#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 *);
scalar_t__ get_line(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stdin;
char *trim(char *);
int main(int argc, char **argv) {
  char buffer[65536];
  char *ptr;
  int how_many = 0;
  if (argc == 2) {
    how_many = atoi(argv[1]);
  }
  while (get_line(buffer, stdin)) {
    ptr = trim(buffer);
    if (how_many) {
      *(ptr + how_many) = '\0';
    }
    printf("%s\n", buffer);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1001c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1180 <main+0x40>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x1001c(%rbp)
jmp    1185 <main+0x45>
lea    -0x10010(%rbp),%rdi
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
call   1030 <get_line@plt>
cmp    $0x0,%rax
je     11ee <main+0xae>
lea    -0x10010(%rbp),%rdi
call   1050 <trim@plt>
mov    %rax,-0x10018(%rbp)
cmpl   $0x0,-0x1001c(%rbp)
je     11d6 <main+0x96>
mov    -0x10018(%rbp),%rax
movslq -0x1001c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
lea    -0x10010(%rbp),%rsi
lea    0xe1c(%rip),%rdi
call   1040 <printf@plt>
jmp    1185 <main+0x45>
xor    %eax,%eax
add    $0x10020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10000,%rsp
xor    %ebp,%ebp
cmp    $0x2,%edi
jne    1161 <main+0x21>
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
mov    0x2e80(%rip),%r15
mov    (%r15),%esi
mov    %rsp,%rdi
call   1030 <get_line@plt>
test   %rax,%rax
je     11be <main+0x7e>
movslq %ebp,%r12
mov    %rsp,%rbx
lea    0xe7b(%rip),%r14
jmp    11ab <main+0x6b>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    (%r15),%esi
mov    %rbx,%rdi
call   1030 <get_line@plt>
test   %rax,%rax
je     11be <main+0x7e>
mov    %rbx,%rdi
call   1050 <trim@plt>
test   %ebp,%ebp
je     1190 <main+0x50>
movb   $0x0,(%rax,%r12,1)
jmp    1190 <main+0x50>
xor    %eax,%eax
add    $0x10000,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [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 [65536 x i8]
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 2
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @atoi(i8* %14)
store i32 %15, i32* %8
br label %16
16: ; preds = %11, %2
br label %17
17: ; preds = %32, %16
%18 = getelementptr inbounds [65536 x i8], [65536 x i8]* %6, i64 0, i64 0
%19 = load i32, i32* @stdin
%20 = call i64 @get_line(i8* %18, i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %35
22: ; preds = %17
%23 = getelementptr inbounds [65536 x i8], [65536 x i8]* %6, i64 0, i64 0
%24 = call i8* @trim(i8* %23)
store i8* %24, i8** %7
%25 = load i32, i32* %8
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = load i8*, i8** %7
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
store i8 0, i8* %31
br label %32
32: ; preds = %27, %22
%33 = getelementptr inbounds [65536 x i8], [65536 x i8]* %6, i64 0, i64 0
%34 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %33)
br label %17
35: ; preds = %17
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [65536 x i8]
%4 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
br label %10
10: ; preds = %6, %2
%11 = phi i32 [ %9, %6 ], [ 0, %2 ]
%12 = load i32, i32* @stdin
%13 = call i64 @get_line(i8* %4, i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %27, label %15
15: ; preds = %10
%16 = icmp eq i32 %11, 0
%17 = sext i32 %11 to i64
br label %18
18: ; preds = %15, %22
%19 = call i8* @trim(i8* %4)
br i1 %16, label %22, label %20
20: ; preds = %18
%21 = getelementptr inbounds i8, i8* %19, i64 %17
store i8 0, i8* %21
br label %22
22: ; preds = %20, %18
%23 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %4)
%24 = load i32, i32* @stdin
%25 = call i64 @get_line(i8* %4, i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %18
27: ; preds = %22, %10
ret i32 0
}