#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 trim_trailing_whitespace(char *);
int main() {
  int len, max, num_lines;
  char line[1000];
  char longest[1000];
  max = len = num_lines = 0;
  printf("\nType in some lines. I will tell you the longest and some data.\n");
  printf("Enter a '$' character to end. Tabs and blanks at the end don't "
         "count!\n\n");
  while ((len = mygetline(line, 1000)) > 0) {
    if (len != 1)
      num_lines++;
    len = trim_trailing_whitespace(line);
    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("Total lines: %d\n", num_lines);
    printf(
        "Number of chars, including the carriage return, in longest line: %d\n",
        max);
    printf("Longest line is: %s", longest);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7f0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x400(%rbp),%rdi
mov    $0x3e8,%esi
call   1060 <mygetline@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    1214 <main+0xd4>
cmpl   $0x1,-0x8(%rbp)
je     11b3 <main+0x73>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
lea    -0x400(%rbp),%rdi
call   1050 <trim_trailing_whitespace@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    120f <main+0xcf>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x3e7,-0x8(%rbp)
jge    11f9 <main+0xb9>
lea    -0x7f0(%rbp),%rdi
lea    -0x400(%rbp),%rsi
call   1040 <copy@plt>
jmp    120a <main+0xca>
mov    -0x8(%rbp),%esi
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    120f <main+0xcf>
jmp    1183 <main+0x43>
cmpl   $0x0,-0xc(%rbp)
jle    1255 <main+0x115>
mov    -0x10(%rbp),%esi
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x7f0(%rbp),%rsi
lea    0xec0(%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   %r13
push   %r12
push   %rbx
sub    $0x7d8,%rsp
lea    0xf31(%rip),%rdi
call   1030 <puts@plt>
lea    0xf65(%rip),%rdi
call   1030 <puts@plt>
lea    0x3f0(%rsp),%rdi
mov    $0x3e8,%esi
call   1070 <mygetline@plt>
test   %eax,%eax
jle    123e <main+0xee>
lea    0x3f0(%rsp),%r14
xor    %ebx,%ebx
xor    %r13d,%r13d
jmp    11da <main+0x8a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xe49(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%r13d
mov    %r12b,%r15b
add    %r15d,%ebx
mov    %r14,%rdi
mov    $0x3e8,%esi
call   1070 <mygetline@plt>
test   %eax,%eax
jle    1207 <main+0xb7>
xor    %r15d,%r15d
cmp    $0x1,%eax
setne  %r12b
mov    %r14,%rdi
call   1060 <trim_trailing_whitespace@plt>
cmp    %r13d,%eax
jle    11c3 <main+0x73>
mov    %eax,%ebp
cmp    $0x3e6,%eax
jg     11b0 <main+0x60>
mov    %rsp,%rdi
mov    %r14,%rsi
call   1050 <copy@plt>
jmp    11c0 <main+0x70>
test   %r13d,%r13d
jle    123e <main+0xee>
lea    0xe1c(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe1d(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe51(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x7d8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [65 x i8] c"\0AType in some lines. I will tell you the longest and some data.\0A\00"
@.str.1 = [72 x i8] c"Enter a '$' character to end. Tabs and blanks at the end don't count!\0A\0A\00"
@.str.2 = [47 x i8] c"\0Athe line is too long, but its length is: %d\0A\0A\00"
@.str.3 = [17 x i8] c"Total lines: %d\0A\00"
@.str.4 = [69 x i8] c"Number of chars, including the carriage return, in longest line: %d\0A\00"
@.str.5 = [20 x i8] c"Longest line is: %s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1000 x i8]
%6 = alloca [1000 x i8]
store i32 0, i32* %1
store i32 0, i32* %4
store i32 0, i32* %2
store i32 0, i32* %3
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %37, %0
%10 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%11 = call i32 @mygetline(i8* %10, i32 1000)
store i32 %11, i32* %2
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %38
13: ; preds = %9
%14 = load i32, i32* %2
%15 = icmp ne i32 %14, 1
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
br label %19
19: ; preds = %16, %13
%20 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%21 = call i32 @trim_trailing_whitespace(i8* %20)
store i32 %21, i32* %2
%22 = load i32, i32* %2
%23 = load i32, i32* %3
%24 = icmp sgt i32 %22, %23
br i1 %24, label %25, label %37
25: ; preds = %19
%26 = load i32, i32* %2
store i32 %26, i32* %3
%27 = load i32, i32* %2
%28 = icmp slt i32 %27, 999
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%31 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%32 = call i32 @copy(i8* %30, i8* %31)
br label %36
33: ; preds = %25
%34 = load i32, i32* %2
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %33, %29
br label %37
37: ; preds = %36, %19
br label %9
38: ; preds = %9
%39 = load i32, i32* %3
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %48
41: ; preds = %38
%42 = load i32, i32* %4
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %42)
%44 = load i32, i32* %3
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.4, i64 0, i64 0), i32 %44)
%46 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %46)
br label %48
48: ; preds = %41, %38
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [47 x i8] c"\0Athe line is too long, but its length is: %d\0A\0A\00"
@.str.3 = [17 x i8] c"Total lines: %d\0A\00"
@.str.4 = [69 x i8] c"Number of chars, including the carriage return, in longest line: %d\0A\00"
@.str.5 = [20 x i8] c"Longest line is: %s\00"
@str = [64 x i8] c"\0AType in some lines. I will tell you the longest and some data.\00"
@str.6 = [71 x i8] c"Enter a '$' character to end. Tabs and blanks at the end don't count!\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 ([64 x i8], [64 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @str.6, i64 0, i64 0))
%7 = call i32 @mygetline(i8* %3, i32 1000)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %34
9: ; preds = %0, %24
%10 = phi i32 [ %26, %24 ], [ %7, %0 ]
%11 = phi i32 [ %15, %24 ], [ 0, %0 ]
%12 = phi i32 [ %25, %24 ], [ 0, %0 ]
%13 = icmp ne i32 %10, 1
%14 = zext i1 %13 to i32
%15 = add nuw nsw i32 %11, %14
%16 = call i32 @trim_trailing_whitespace(i8* %3)
%17 = icmp sgt i32 %16, %12
br i1 %17, label %18, label %24
18: ; preds = %9
%19 = icmp slt i32 %16, 999
br i1 %19, label %20, label %22
20: ; preds = %18
%21 = call i32 @copy(i8* %4, i8* %3)
br label %24
22: ; preds = %18
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i32 %16)
br label %24
24: ; preds = %20, %22, %9
%25 = phi i32 [ %16, %20 ], [ %16, %22 ], [ %12, %9 ]
%26 = call i32 @mygetline(i8* %3, i32 1000)
%27 = icmp sgt i32 %26, 0
br i1 %27, label %9, label %28
28: ; preds = %24
%29 = icmp sgt i32 %25, 0
br i1 %29, label %30, label %34
30: ; preds = %28
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([69 x i8], [69 x i8]* @.str.4, i64 0, i64 0), i32 %25)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %4)
br label %34
34: ; preds = %0, %30, %28
ret i32 0
}