#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 EOF;
int getchar();
int /*<<< orphan*/ putchar(char);
int trim(int width) {
  int c;
  int i = 0;
  while ((c = getchar()) != EOF) {
    if (i++ < width) {
      putchar(c);
    }
    if (c == '\n') {
      i = 0;
    } else if (i == width) {
      putchar('\n');
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<trim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2ea5(%rip),%rcx
cmp    (%rcx),%eax
je     11a0 <trim+0x80>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xc(%rbp)
cmp    -0x4(%rbp),%eax
jge    116a <trim+0x4a>
mov    -0x8(%rbp),%eax
movsbl %al,%edi
call   1030 <putchar@plt>
cmpl   $0xa,-0x8(%rbp)
jne    1180 <trim+0x60>
movl   $0x0,-0xc(%rbp)
jmp    119b <trim+0x7b>
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    1196 <trim+0x76>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    119b <trim+0x7b>
jmp    1132 <trim+0x12>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r15d
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2eaf(%rip),%r14
cmp    (%r14),%eax
jne    1149 <trim+0x29>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebp
xor    %ebx,%ebx
jmp    1161 <trim+0x41>
nop
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebp
mov    %r12d,%ebx
cmp    (%r14),%eax
je     113e <trim+0x1e>
cmp    %r15d,%ebx
jge    116f <trim+0x4f>
movsbl %bpl,%edi
call   1030 <putchar@plt>
xor    %r12d,%r12d
cmp    $0xa,%ebp
je     1150 <trim+0x30>
add    $0x1,%ebx
mov    %ebx,%r12d
cmp    %r15d,%ebx
jne    1150 <trim+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15d,%r12d
jmp    1150 <trim+0x30>

LLVM IR (-O0):
@EOF = global i32 0
define i32 @trim(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
br label %5
5: ; preds = %29, %1
%6 = call i32 (...) @getchar()
store i32 %6, i32* %3
%7 = load i32, i32* @EOF
%8 = icmp ne i32 %6, %7
br i1 %8, label %9, label %30
9: ; preds = %5
%10 = load i32, i32* %4
%11 = add nsw i32 %10, 1
store i32 %11, i32* %4
%12 = load i32, i32* %2
%13 = icmp slt i32 %10, %12
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i32, i32* %3
%16 = trunc i32 %15 to i8
%17 = call i32 @putchar(i8 signext %16)
br label %18
18: ; preds = %14, %9
%19 = load i32, i32* %3
%20 = icmp eq i32 %19, 10
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 0, i32* %4
br label %29
22: ; preds = %18
%23 = load i32, i32* %4
%24 = load i32, i32* %2
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 @putchar(i8 signext 10)
br label %28
28: ; preds = %26, %22
br label %29
29: ; preds = %28, %21
br label %5
30: ; preds = %5
ret i32 0
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @trim(i32 %0) {
%2 = tail call i32 (...) @getchar()
%3 = load i32, i32* @EOF
%4 = icmp eq i32 %2, %3
br i1 %4, label %24, label %5
5: ; preds = %1, %19
%6 = phi i32 [ %21, %19 ], [ %2, %1 ]
%7 = phi i32 [ %20, %19 ], [ 0, %1 ]
%8 = add nsw i32 %7, 1
%9 = icmp slt i32 %7, %0
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = trunc i32 %6 to i8
%12 = tail call i32 @putchar(i8 signext %11)
br label %13
13: ; preds = %10, %5
%14 = icmp eq i32 %6, 10
br i1 %14, label %19, label %15
15: ; preds = %13
%16 = icmp eq i32 %8, %0
br i1 %16, label %17, label %19
17: ; preds = %15
%18 = tail call i32 @putchar(i8 signext 10)
br label %19
19: ; preds = %13, %15, %17
%20 = phi i32 [ %0, %17 ], [ %8, %15 ], [ 0, %13 ]
%21 = tail call i32 (...) @getchar()
%22 = load i32, i32* @EOF
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %5
24: ; preds = %19, %1
ret i32 0
}