#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ get_line(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
char *trim_until_character(char *, char, char *, int);
int main(int argc, char **argv) {
  char in_buffer[1024];
  char out_buffer[1024];
  char character;
  int num2trim;
  if (argc < 2) {
    fprintf(stderr, "Usage: %s character [num2trim]\n", argv[0]);
    exit(1);
  }
  character = *argv[1];
  if (argc == 3)
    num2trim = atoi(argv[2]);
  else
    num2trim = 1;
  while (get_line(in_buffer, stdin)) {
    printf("%s\n",
           trim_until_character(out_buffer, character, in_buffer, num2trim));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11a9 <main+0x49>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe66(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%al
mov    %al,-0x811(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    11db <main+0x7b>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x818(%rbp)
jmp    11e5 <main+0x85>
movl   $0x1,-0x818(%rbp)
jmp    11ea <main+0x8a>
lea    -0x410(%rbp),%rdi
mov    0x2df0(%rip),%rax
mov    (%rax),%esi
call   1030 <get_line@plt>
cmp    $0x0,%rax
je     123f <main+0xdf>
lea    -0x810(%rbp),%rdi
mov    -0x811(%rbp),%al
lea    -0x410(%rbp),%rdx
mov    -0x818(%rbp),%ecx
movsbl %al,%esi
call   1050 <trim_until_character@plt>
mov    %rax,%rsi
lea    0xdeb(%rip),%rdi
call   1040 <printf@plt>
jmp    11ea <main+0x8a>
xor    %eax,%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
cmp    $0x1,%edi
jle    1210 <main+0xb0>
mov    0x8(%rsi),%rax
mov    (%rax),%bl
mov    $0x1,%r15d
cmp    $0x3,%edi
jne    1197 <main+0x37>
mov    0x10(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%r15d
mov    0x2e4a(%rip),%r13
mov    0x0(%r13),%esi
mov    %rsp,%rdi
call   1030 <get_line@plt>
test   %rax,%rax
je     11fc <main+0x9c>
movsbl %bl,%ebp
lea    0x400(%rsp),%r14
mov    %rsp,%rbx
lea    0xe5c(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
mov    %r15d,%ecx
call   1050 <trim_until_character@plt>
mov    %r12,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1030 <get_line@plt>
test   %rax,%rax
jne    11d0 <main+0x70>
xor    %eax,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xddd(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"Usage: %s character [num2trim]\0A\00"
@stdin = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = alloca i8
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i8, i8* %22
store i8 %23, i8* %8
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, 3
br i1 %25, label %26, label %31
26: ; preds = %19
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %9
br label %32
31: ; preds = %19
store i32 1, i32* %9
br label %32
32: ; preds = %31, %26
br label %33
33: ; preds = %38, %32
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%35 = load i32, i32* @stdin
%36 = call i64 @get_line(i8* %34, i32 %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %45
38: ; preds = %33
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%40 = load i8, i8* %8
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%42 = load i32, i32* %9
%43 = call i8* @trim_until_character(i8* %39, i8 signext %40, i8* %41, i32 %42)
%44 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %43)
br label %33
45: ; preds = %33
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"Usage: %s character [num2trim]\0A\00"
@stdin = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = load i8, i8* %15
%17 = icmp eq i32 %0, 3
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i32 @atoi(i8* %20)
br label %22
22: ; preds = %13, %18
%23 = phi i32 [ %21, %18 ], [ 1, %13 ]
%24 = load i32, i32* @stdin
%25 = call i64 @get_line(i8* %5, i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %33, label %27
27: ; preds = %22, %27
%28 = call i8* @trim_until_character(i8* %6, i8 signext %16, i8* %5, i32 %23)
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = load i32, i32* @stdin
%31 = call i64 @get_line(i8* %5, i32 %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %27
33: ; preds = %27, %22
ret i32 0
}