#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 /*<<< orphan*/ free(char *);
scalar_t__ get_line(char **);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
void get_max_line() {
  char *buf;
  int max;
  char static_buf[128];
  char *max_len_buf, *dynamic_buf;
  max = 0;
  while (get_line(&buf) > 0) {
    int len;
    len = strlen(buf);
    if (len > max) {
      if (max >= 128)
        free(max_len_buf);
      max = len;
      if (len < 128)
        max_len_buf = static_buf;
      else {
        dynamic_buf = (char *)malloc(len + 1);
        if (!dynamic_buf) {
          printf("fatal error!\n");
          return;
        }
        max_len_buf = dynamic_buf;
      }
      copy(max_len_buf, buf);
      free(buf);
    }
  }
  printf("max len line:%s\n", max_len_buf);
}


x86 assembly (clang, -O0):
<get_max_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0xc(%rbp)
lea    -0x8(%rbp),%rdi
call   1040 <get_line@plt>
cmp    $0x0,%rax
jle    124a <get_max_line+0xea>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0xa4(%rbp)
mov    -0xa4(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    1245 <get_max_line+0xe5>
cmpl   $0x80,-0xc(%rbp)
jl     11bc <get_max_line+0x5c>
mov    -0x98(%rbp),%rdi
call   1030 <free@plt>
mov    -0xa4(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x80,-0xa4(%rbp)
jge    11e8 <get_max_line+0x88>
lea    -0x90(%rbp),%rax
mov    %rax,-0x98(%rbp)
jmp    122c <get_max_line+0xcc>
mov    -0xa4(%rbp),%edi
add    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,-0xa0(%rbp)
cmpq   $0x0,-0xa0(%rbp)
jne    121e <get_max_line+0xbe>
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    125f <get_max_line+0xff>
mov    -0xa0(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <copy@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
jmp    1172 <get_max_line+0x12>
mov    -0x98(%rbp),%rsi
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_max_line>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x90,%rsp
lea    0x8(%rsp),%r14
mov    %r14,%rdi
call   1050 <get_line@plt>
xor    %ebp,%ebp
lea    0x10(%rsp),%r12
jmp    11c6 <get_max_line+0x56>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x8(%rsp),%rsi
mov    %r15,%rdi
call   1080 <copy@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %ebx,%ebp
mov    %r14,%rdi
call   1050 <get_line@plt>
test   %rax,%rax
jle    1203 <get_max_line+0x93>
mov    0x8(%rsp),%rdi
call   1060 <strlen@plt>
cmp    %ebp,%eax
jle    11b9 <get_max_line+0x49>
mov    %eax,%ebx
cmp    $0x80,%ebp
jl     11e6 <get_max_line+0x76>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%r15
cmp    $0x80,%ebx
jl     11a0 <get_max_line+0x30>
lea    0x1(%rbx),%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     1216 <get_max_line+0xa6>
mov    %rax,%r15
jmp    11a0 <get_max_line+0x30>
lea    0xdf6(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1222 <get_max_line+0xb2>
lea    0xdf4(%rip),%rdi
call   1040 <puts@plt>
add    $0x90,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"fatal error!\0A\00"
@.str.1 = [17 x i8] c"max len line:%s\0A\00"
define void @get_max_line() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca [128 x i8]
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i32 0, i32* %2
br label %7
7: ; preds = %45, %0
%8 = call i64 @get_line(i8** %1)
%9 = icmp sgt i64 %8, 0
br i1 %9, label %10, label %46
10: ; preds = %7
%11 = load i8*, i8** %1
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = load i32, i32* %2
%15 = icmp sgt i32 %13, %14
br i1 %15, label %16, label %45
16: ; preds = %10
%17 = load i32, i32* %2
%18 = icmp sge i32 %17, 128
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i8*, i8** %4
%21 = call i32 @free(i8* %20)
br label %22
22: ; preds = %19, %16
%23 = load i32, i32* %6
store i32 %23, i32* %2
%24 = load i32, i32* %6
%25 = icmp slt i32 %24, 128
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
store i8* %27, i8** %4
br label %39
28: ; preds = %22
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
%31 = call i64 @malloc(i32 %30)
%32 = inttoptr i64 %31 to i8*
store i8* %32, i8** %5
%33 = load i8*, i8** %5
%34 = icmp ne i8* %33, null
br i1 %34, label %37, label %35
35: ; preds = %28
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %49
37: ; preds = %28
%38 = load i8*, i8** %5
store i8* %38, i8** %4
br label %39
39: ; preds = %37, %26
%40 = load i8*, i8** %4
%41 = load i8*, i8** %1
%42 = call i32 @copy(i8* %40, i8* %41)
%43 = load i8*, i8** %1
%44 = call i32 @free(i8* %43)
br label %45
45: ; preds = %39, %10
br label %7
46: ; preds = %7
%47 = load i8*, i8** %4
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %47)
br label %49
49: ; preds = %46, %35
ret void
}

LLVM IR (-O2):
@.str.1 = [17 x i8] c"max len line:%s\0A\00"
@str = [13 x i8] c"fatal error!\00"
define void @get_max_line() {
%1 = alloca i8*
%2 = alloca [128 x i8]
%3 = bitcast i8** %1 to i8*
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%5 = call i64 @get_line(i8** %1)
%6 = icmp sgt i64 %5, 0
br label %7
7: ; preds = %0, %33
%8 = phi i32 [ %35, %33 ], [ 0, %0 ]
%9 = phi i8* [ %34, %33 ], [ undef, %0 ]
%10 = load i8*, i8** %1
%11 = call i32 @strlen(i8* %10)
%12 = icmp sgt i32 %11, %8
br i1 %12, label %13, label %33
13: ; preds = %7
%14 = icmp sgt i32 %8, 127
br i1 %14, label %15, label %17
15: ; preds = %13
%16 = call i32 @free(i8* %9)
br label %17
17: ; preds = %15, %13
%18 = icmp slt i32 %11, 128
br i1 %18, label %27, label %19
19: ; preds = %17
%20 = add nuw nsw i32 %11, 1
%21 = call i64 @malloc(i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
br label %40
25: ; preds = %19
%26 = inttoptr i64 %21 to i8*
br label %27
27: ; preds = %17, %25
%28 = phi i8* [ %26, %25 ], [ %4, %17 ]
%29 = load i8*, i8** %1
%30 = call i32 @copy(i8* %28, i8* %29)
%31 = load i8*, i8** %1
%32 = call i32 @free(i8* %31)
br label %33
33: ; preds = %7, %27
%34 = phi i8* [ %28, %27 ], [ %9, %7 ]
%35 = phi i32 [ %11, %27 ], [ %8, %7 ]
%36 = call i64 @get_line(i8** %1)
%37 = icmp sgt i64 %36, 0
br i1 %37, label %7, label %38
38: ; preds = %33
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %34)
br label %40
40: ; preds = %23, %38
ret void
}