#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 getlittleline(char *);
int /*<<< orphan*/ printf(char *, int, int, char *);
int main(int argc, char *argv[]) {
  int len;
  char line[500];
  int linenum = 0;
  while ((len = getlittleline(line)) > 0) {
    ++linenum;
    if (len == 500 - 1) {
      printf("Line %d cut at %d max characters. First 100 chars: %.100s\n",
             linenum, 500, line);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x214(%rbp)
lea    -0x210(%rbp),%rdi
call   1040 <getlittleline@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    119a <main+0x7a>
mov    -0x214(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x214(%rbp)
cmpl   $0x1f3,-0x14(%rbp)
jne    1195 <main+0x75>
mov    -0x214(%rbp),%esi
lea    -0x210(%rbp),%rcx
lea    0xe75(%rip),%rdi
mov    $0x1f4,%edx
call   1030 <printf@plt>
jmp    1143 <main+0x23>
xor    %eax,%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %rsp,%rdi
call   1040 <getlittleline@plt>
test   %eax,%eax
jle    117a <main+0x5a>
mov    $0x1,%ebx
lea    0xebc(%rip),%r14
mov    %rsp,%r15
jmp    115f <main+0x3f>
nopl   0x0(%rax)
mov    %r15,%rdi
call   1040 <getlittleline@plt>
add    $0x1,%ebx
test   %eax,%eax
jle    117a <main+0x5a>
cmp    $0x1f3,%eax
jne    1150 <main+0x30>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x1f4,%edx
mov    %r15,%rcx
call   1030 <printf@plt>
jmp    1150 <main+0x30>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [59 x i8] c"Line %d cut at %d max characters. First 100 chars: %.100s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [500 x i8]
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
br label %9
9: ; preds = %22, %2
%10 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%11 = call i32 @getlittleline(i8* %10)
store i32 %11, i32* %6
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %9
%14 = load i32, i32* %8
%15 = add nsw i32 %14, 1
store i32 %15, i32* %8
%16 = load i32, i32* %6
%17 = icmp eq i32 %16, 499
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = load i32, i32* %8
%20 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%21 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i32 %19, i32 500, i8* %20)
br label %22
22: ; preds = %18, %13
br label %9
23: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str = [59 x i8] c"Line %d cut at %d max characters. First 100 chars: %.100s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [500 x i8]
%4 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%5 = call i32 @getlittleline(i8* %4)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %17
7: ; preds = %2, %14
%8 = phi i32 [ %15, %14 ], [ %5, %2 ]
%9 = phi i32 [ %10, %14 ], [ 0, %2 ]
%10 = add nuw nsw i32 %9, 1
%11 = icmp eq i32 %8, 499
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i32 %10, i32 500, i8* %4)
br label %14
14: ; preds = %12, %7
%15 = call i32 @getlittleline(i8* %4)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %7, label %17
17: ; preds = %14, %2
ret i32 0
}