#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 /*<<< orphan*/ copy(char *, char *);
int mygetline(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int len;
  int max;
  char line[1000];
  char longest[1000];
  max = 0;
  printf("\nType in some lines, I will show you the longest. Enter a '$' "
         "character to end.\n\n");
  while ((len = mygetline(line, 1000)) > 0)
    if (len > max) {
      max = len;
      if (len < 1000 - 1)
        copy(longest, line);
      else
        printf("\nthe line is too long, but its length is: %d\n\n", len);
    }
  if (max > 0)
    printf("%s", longest);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7f0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x400(%rbp),%rdi
mov    $0x3e8,%esi
call   1050 <mygetline@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    11c6 <main+0x96>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    11c1 <main+0x91>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x3e7,-0x8(%rbp)
jge    11ab <main+0x7b>
lea    -0x7f0(%rbp),%rdi
lea    -0x400(%rbp),%rsi
call   1040 <copy@plt>
jmp    11bc <main+0x8c>
mov    -0x8(%rbp),%esi
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c1 <main+0x91>
jmp    1157 <main+0x27>
cmpl   $0x0,-0xc(%rbp)
jle    11e5 <main+0xb5>
lea    -0x7f0(%rbp),%rsi
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x7f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x7e0,%rsp
lea    0xedc(%rip),%rdi
call   1030 <puts@plt>
lea    0x3f0(%rsp),%rdi
mov    $0x3e8,%esi
call   1060 <mygetline@plt>
test   %eax,%eax
jle    11df <main+0x9f>
mov    %eax,%ebp
mov    %rsp,%r14
lea    0x3f0(%rsp),%r12
lea    0xe7b(%rip),%r15
xor    %ebx,%ebx
jmp    11b1 <main+0x71>
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%ebx
mov    %r12,%rdi
mov    $0x3e8,%esi
call   1060 <mygetline@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    11ca <main+0x8a>
cmp    %ebx,%ebp
jle    119e <main+0x5e>
cmp    $0x3e6,%ebp
ja     1190 <main+0x50>
mov    %r14,%rdi
mov    %r12,%rsi
call   1050 <copy@plt>
jmp    119c <main+0x5c>
test   %ebx,%ebx
jle    11df <main+0x9f>
lea    0xe5a(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x7e0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [82 x i8] c"\0AType in some lines, I will show you the longest. Enter a '$' character to end.\0A\0A\00"
@.str.1 = [47 x i8] c"\0Athe line is too long, but its length is: %d\0A\0A\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1000 x i8]
%5 = alloca [1000 x i8]
store i32 0, i32* %1
store i32 0, i32* %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %27, %0
%8 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%9 = call i32 @mygetline(i8* %8, i32 1000)
store i32 %9, i32* %2
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %28
11: ; preds = %7
%12 = load i32, i32* %2
%13 = load i32, i32* %3
%14 = icmp sgt i32 %12, %13
br i1 %14, label %15, label %27
15: ; preds = %11
%16 = load i32, i32* %2
store i32 %16, i32* %3
%17 = load i32, i32* %2
%18 = icmp slt i32 %17, 999
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%21 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%22 = call i32 @copy(i8* %20, i8* %21)
br label %26
23: ; preds = %15
%24 = load i32, i32* %2
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %23, %19
br label %27
27: ; preds = %26, %11
br label %7
28: ; preds = %7
%29 = load i32, i32* %3
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %31, %28
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [47 x i8] c"\0Athe line is too long, but its length is: %d\0A\0A\00"
@.str.2 = [3 x i8] c"%s\00"
@str = [81 x i8] c"\0AType in some lines, I will show you the longest. Enter a '$' character to end.\0A\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = alloca [1000 x i8]
%3 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @str, i64 0, i64 0))
%6 = call i32 @mygetline(i8* %3, i32 1000)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %26
8: ; preds = %0, %18
%9 = phi i32 [ %20, %18 ], [ %6, %0 ]
%10 = phi i32 [ %19, %18 ], [ 0, %0 ]
%11 = icmp sgt i32 %9, %10
br i1 %11, label %12, label %18
12: ; preds = %8
%13 = icmp ult i32 %9, 999
br i1 %13, label %14, label %16
14: ; preds = %12
%15 = call i32 @copy(i8* %4, i8* %3)
br label %18
16: ; preds = %12
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 %9)
br label %18
18: ; preds = %14, %16, %8
%19 = phi i32 [ %9, %14 ], [ %9, %16 ], [ %10, %8 ]
%20 = call i32 @mygetline(i8* %3, i32 1000)
%21 = icmp sgt i32 %20, 0
br i1 %21, label %8, label %22
22: ; preds = %18
%23 = icmp sgt i32 %19, 0
br i1 %23, label %24, label %26
24: ; preds = %22
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %4)
br label %26
26: ; preds = %0, %24, %22
ret i32 0
}