#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ copy(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getline(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int len;
  char longest[128];
  char line[128];
  int max = 0;
  FILE *in;
  in = fopen("input.dat", "r");
  if (in == NULL) {
    perror("input.dat");
    return 1;
  }
  while ((len = getline(in, line, 128)) > 0) {
    printf("%d:%s\n", len, line);
    if (max < len) {
      max = len;
      copy(longest, line);
    }
  }
  if (max > 0) {
    printf("max line is:\n%s\n", longest);
  }
  fclose(in);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x124(%rbp)
lea    0xe76(%rip),%rdi
lea    0xe79(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x130(%rbp)
cmpq   $0x0,-0x130(%rbp)
jne    11c3 <main+0x63>
lea    0xe4e(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1269 <main+0x109>
jmp    11c8 <main+0x68>
mov    -0x130(%rbp),%rdi
lea    -0x120(%rbp),%rsi
mov    $0x80,%edx
call   1080 <getline@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    1234 <main+0xd4>
mov    -0x14(%rbp),%esi
lea    -0x120(%rbp),%rdx
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x124(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    122f <main+0xcf>
mov    -0x14(%rbp),%eax
mov    %eax,-0x124(%rbp)
lea    -0xa0(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   1050 <copy@plt>
jmp    11c8 <main+0x68>
cmpl   $0x0,-0x124(%rbp)
jle    1256 <main+0xf6>
lea    -0xa0(%rbp),%rsi
lea    0xdc4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x130(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
lea    0xe88(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     122e <main+0xce>
mov    %rax,%r15
mov    %rsp,%rsi
mov    %rax,%rdi
mov    $0x80,%edx
call   1080 <getline@plt>
test   %eax,%eax
jle    1212 <main+0xb2>
mov    %eax,%ebp
lea    0xe5f(%rip),%r14
mov    %rsp,%r13
lea    0x80(%rsp),%r12
xor    %ebx,%ebx
jmp    11d6 <main+0x76>
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r13,%rsi
mov    $0x80,%edx
call   1080 <getline@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    11f8 <main+0x98>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r13,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
cmp    %ebp,%ebx
jge    11c0 <main+0x60>
mov    %r12,%rdi
mov    %r13,%rsi
call   1050 <copy@plt>
mov    %ebp,%ebx
jmp    11c0 <main+0x60>
test   %ebx,%ebx
jle    1212 <main+0xb2>
lea    0xe10(%rip),%rdi
lea    0x80(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdcb(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%eax
jmp    121c <main+0xbc>

LLVM IR (-O0):
@.str = [10 x i8] c"input.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [7 x i8] c"%d:%s\0A\00"
@.str.3 = [17 x i8] c"max line is:\0A%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [128 x i8]
%8 = alloca [128 x i8]
%9 = alloca i32
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
%11 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %10
%12 = load i32*, i32** %10
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %44
16: ; preds = %2
br label %17
17: ; preds = %34, %16
%18 = load i32*, i32** %10
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%20 = call i32 @getline(i32* %18, i8* %19, i32 128)
store i32 %20, i32* %6
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %35
22: ; preds = %17
%23 = load i32, i32* %6
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %23, i8* %24)
%26 = load i32, i32* %9
%27 = load i32, i32* %6
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %34
29: ; preds = %22
%30 = load i32, i32* %6
store i32 %30, i32* %9
%31 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%33 = call i32 @copy(i8* %31, i8* %32)
br label %34
34: ; preds = %29, %22
br label %17
35: ; preds = %17
%36 = load i32, i32* %9
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %39)
br label %41
41: ; preds = %38, %35
%42 = load i32*, i32** %10
%43 = call i32 @fclose(i32* %42)
store i32 0, i32* %3
br label %44
44: ; preds = %41, %14
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@.str = [10 x i8] c"input.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [7 x i8] c"%d:%s\0A\00"
@.str.3 = [17 x i8] c"max line is:\0A%s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [128 x i8]
%4 = alloca [128 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = call i32 @getline(i32* %7, i8* %6, i32 128)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %14, label %29
12: ; preds = %2
%13 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %31
14: ; preds = %9, %21
%15 = phi i32 [ %23, %21 ], [ %10, %9 ]
%16 = phi i32 [ %22, %21 ], [ 0, %9 ]
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %15, i8* %6)
%18 = icmp slt i32 %16, %15
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = call i32 @copy(i8* %5, i8* %6)
br label %21
21: ; preds = %19, %14
%22 = phi i32 [ %15, %19 ], [ %16, %14 ]
%23 = call i32 @getline(i32* %7, i8* %6, i32 128)
%24 = icmp sgt i32 %23, 0
br i1 %24, label %14, label %25
25: ; preds = %21
%26 = icmp sgt i32 %22, 0
br i1 %26, label %27, label %29
27: ; preds = %25
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %5)
br label %29
29: ; preds = %9, %27, %25
%30 = call i32 @fclose(i32* %7)
br label %31
31: ; preds = %29, %12
%32 = phi i32 [ 1, %12 ], [ 0, %29 ]
ret i32 %32
}