#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 getLine(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ reverseline(int, char *, char *);
int main() {
  int len;
  int max;
  char line[1000];
  char longuest[1000];
  char reversed[1000];
  max = 0;
  while ((len = getLine(line, 1000)) > 0) {
    printf("line is: %s", line);
    reverseline(len, reversed, line);
    printf("reversed line is: %s", reversed);
    if (len > max) {
      max = len;
      copy(longuest, line);
    }
  }
  if (max > 0) {
    printf("longest line is: %s", longuest);
    printf("length of longuest line is: %d\n", max);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xbe0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x400(%rbp),%rdi
mov    $0x3e8,%esi
call   1060 <getLine@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    11e0 <main+0xa0>
lea    -0x400(%rbp),%rsi
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0xbe0(%rbp),%rsi
lea    -0x400(%rbp),%rdx
call   1050 <reverseline@plt>
lea    -0xbe0(%rbp),%rsi
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    11db <main+0x9b>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
lea    -0x7f0(%rbp),%rdi
lea    -0x400(%rbp),%rsi
call   1040 <copy@plt>
jmp    1159 <main+0x19>
cmpl   $0x0,-0xc(%rbp)
jle    1210 <main+0xd0>
lea    -0x7f0(%rbp),%rsi
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xbe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xbc8,%rsp
lea    0x3f0(%rsp),%rdi
mov    $0x3e8,%esi
call   1060 <getLine@plt>
test   %eax,%eax
jle    1206 <main+0xc6>
mov    %eax,%ebp
lea    0xe95(%rip),%r14
lea    0x3f0(%rsp),%rbx
lea    0x7e0(%rsp),%r12
lea    0xe75(%rip),%r13
xor    %r15d,%r15d
jmp    11a3 <main+0x63>
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1060 <getLine@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    11df <main+0x9f>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebp,%edi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <reverseline@plt>
mov    %r13,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
cmp    %r15d,%ebp
jle    1190 <main+0x50>
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1040 <copy@plt>
mov    %ebp,%r15d
jmp    1190 <main+0x50>
test   %r15d,%r15d
jle    1206 <main+0xc6>
lea    0xe2a(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe2d(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xbc8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"line is: %s\00"
@.str.1 = [21 x i8] c"reversed line is: %s\00"
@.str.2 = [20 x i8] c"longest line is: %s\00"
@.str.3 = [32 x i8] c"length of longuest line is: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1000 x i8]
%5 = alloca [1000 x i8]
%6 = alloca [1000 x i8]
store i32 0, i32* %1
store i32 0, i32* %3
br label %7
7: ; preds = %28, %0
%8 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%9 = call i32 @getLine(i8* %8, i32 1000)
store i32 %9, i32* %2
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %29
11: ; preds = %7
%12 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i32, i32* %2
%15 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%16 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%17 = call i32 @reverseline(i32 %14, i8* %15, i8* %16)
%18 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = load i32, i32* %2
%21 = load i32, i32* %3
%22 = icmp sgt i32 %20, %21
br i1 %22, label %23, label %28
23: ; preds = %11
%24 = load i32, i32* %2
store i32 %24, i32* %3
%25 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%26 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%27 = call i32 @copy(i8* %25, i8* %26)
br label %28
28: ; preds = %23, %11
br label %7
29: ; preds = %7
%30 = load i32, i32* %3
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %29
%33 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = load i32, i32* %3
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %32, %29
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"line is: %s\00"
@.str.1 = [21 x i8] c"reversed line is: %s\00"
@.str.2 = [20 x i8] c"longest line is: %s\00"
@.str.3 = [32 x i8] c"length of longuest line is: %d\0A\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = alloca [1000 x i8]
%3 = alloca [1000 x i8]
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%7 = call i32 @getLine(i8* %4, i32 1000)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %27
9: ; preds = %0, %18
%10 = phi i32 [ %20, %18 ], [ %7, %0 ]
%11 = phi i32 [ %19, %18 ], [ 0, %0 ]
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %4)
%13 = call i32 @reverseline(i32 %10, i8* %6, i8* %4)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%15 = icmp sgt i32 %10, %11
br i1 %15, label %16, label %18
16: ; preds = %9
%17 = call i32 @copy(i8* %5, i8* %4)
br label %18
18: ; preds = %16, %9
%19 = phi i32 [ %10, %16 ], [ %11, %9 ]
%20 = call i32 @getLine(i8* %4, i32 1000)
%21 = icmp sgt i32 %20, 0
br i1 %21, label %9, label %22
22: ; preds = %18
%23 = icmp sgt i32 %19, 0
br i1 %23, label %24, label %27
24: ; preds = %22
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %19)
br label %27
27: ; preds = %0, %24, %22
ret i32 0
}