#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*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int strlen(char *);
size_t find_max_line_len(char *file_path) {
  FILE *fp = NULL;
  char buffer[256];
  size_t curr_len;
  size_t max_len;
  fp = fopen(file_path, "r");
  if (fp == NULL) {
    return -1;
  }
  max_len = curr_len = 0;
  while (feof(fp) == 0) {
    memset(buffer, 0, 256);
    fgets(buffer, 256, fp);
    curr_len += strlen(buffer);
    if (*(buffer + strlen(buffer) - 1) == '\n') {
      if (curr_len > max_len) {
        max_len = curr_len - 1;
      }
      curr_len = 0;
    }
  }
  if (*(buffer + strlen(buffer) - 1) == '\n') {
    if (curr_len > max_len) {
      max_len = curr_len - 1;
    }
    curr_len = 0;
  } else {
    if (curr_len > max_len) {
      max_len = curr_len;
    }
  }
  fclose(fp);
  return max_len;
}


x86 assembly (clang, -O0):
<find_max_line_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a3 <find_max_line_len+0x43>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    12f5 <find_max_line_len+0x195>
movq   $0x0,-0x128(%rbp)
movq   $0x0,-0x130(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
jne    1265 <find_max_line_len+0x105>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x100,%esi
call   1060 <fgets@plt>
lea    -0x120(%rbp),%rdi
call   1040 <strlen@plt>
cltq
add    -0x128(%rbp),%rax
mov    %rax,-0x128(%rbp)
lea    -0x120(%rbp),%rdi
call   1040 <strlen@plt>
cltq
movsbl -0x121(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    1260 <find_max_line_len+0x100>
mov    -0x128(%rbp),%rax
cmp    -0x130(%rbp),%rax
jbe    1255 <find_max_line_len+0xf5>
mov    -0x128(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x130(%rbp)
movq   $0x0,-0x128(%rbp)
jmp    11b9 <find_max_line_len+0x59>
lea    -0x120(%rbp),%rdi
call   1040 <strlen@plt>
cltq
movsbl -0x121(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    12ba <find_max_line_len+0x15a>
mov    -0x128(%rbp),%rax
cmp    -0x130(%rbp),%rax
jbe    12aa <find_max_line_len+0x14a>
mov    -0x128(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x130(%rbp)
movq   $0x0,-0x128(%rbp)
jmp    12e1 <find_max_line_len+0x181>
mov    -0x128(%rbp),%rax
cmp    -0x130(%rbp),%rax
jbe    12dc <find_max_line_len+0x17c>
mov    -0x128(%rbp),%rax
mov    %rax,-0x130(%rbp)
jmp    12e1 <find_max_line_len+0x181>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x130(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_max_line_len>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
lea    0xe88(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1199 <find_max_line_len+0x39>
mov    %rax,%r14
mov    %rax,%rdi
call   1070 <feof@plt>
test   %rax,%rax
je     11a5 <find_max_line_len+0x45>
xor    %ebx,%ebx
xor    %r12d,%r12d
jmp    1213 <find_max_line_len+0xb3>
mov    $0xffffffffffffffff,%r15
jmp    123c <find_max_line_len+0xdc>
xor    %r12d,%r12d
mov    %rsp,%r15
xor    %ebx,%ebx
nopl   (%rax)
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
mov    %r15,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
movslq %eax,%r13
lea    (%rbx,%r13,1),%rbp
mov    %r15,%rdi
call   1040 <strlen@plt>
cmp    %r12,%rbp
lea    -0x1(%rbx,%r13,1),%rcx
cmovbe %r12,%rcx
cltq
cmpb   $0xa,-0x1(%rsp,%rax,1)
mov    $0x0,%ebx
cmovne %rbp,%rbx
cmove  %rcx,%r12
mov    %r14,%rdi
call   1070 <feof@plt>
test   %rax,%rax
je     11b0 <find_max_line_len+0x50>
mov    %rsp,%rdi
call   1040 <strlen@plt>
cltq
xor    %ecx,%ecx
cmpb   $0xa,-0x1(%rsp,%rax,1)
sete   %cl
mov    %rbx,%r15
sub    %rcx,%r15
cmp    %r12,%rbx
cmovbe %r12,%r15
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r15,%rax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i64 @find_max_line_len(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [256 x i8]
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %3
store i32* null, i32** %4
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %4
%10 = load i32*, i32** %4
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %13
12: ; preds = %1
store i64 -1, i64* %2
br label %76
13: ; preds = %1
store i64 0, i64* %6
store i64 0, i64* %7
br label %14
14: ; preds = %46, %13
%15 = load i32*, i32** %4
%16 = call i64 @feof(i32* %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %47
18: ; preds = %14
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%20 = call i32 @memset(i8* %19, i32 0, i32 256)
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%22 = load i32*, i32** %4
%23 = call i32 @fgets(i8* %21, i32 256, i32* %22)
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%25 = call i32 @strlen(i8* %24)
%26 = sext i32 %25 to i64
%27 = load i64, i64* %6
%28 = add i64 %27, %26
store i64 %28, i64* %6
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%31 = call i32 @strlen(i8* %30)
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
%34 = getelementptr inbounds i8, i8* %33, i64 -1
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 10
br i1 %37, label %38, label %46
38: ; preds = %18
%39 = load i64, i64* %6
%40 = load i64, i64* %7
%41 = icmp ugt i64 %39, %40
br i1 %41, label %42, label %45
42: ; preds = %38
%43 = load i64, i64* %6
%44 = sub i64 %43, 1
store i64 %44, i64* %7
br label %45
45: ; preds = %42, %38
store i64 0, i64* %6
br label %46
46: ; preds = %45, %18
br label %14
47: ; preds = %14
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%49 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%50 = call i32 @strlen(i8* %49)
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %48, i64 %51
%53 = getelementptr inbounds i8, i8* %52, i64 -1
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 10
br i1 %56, label %57, label %65
57: ; preds = %47
%58 = load i64, i64* %6
%59 = load i64, i64* %7
%60 = icmp ugt i64 %58, %59
br i1 %60, label %61, label %64
61: ; preds = %57
%62 = load i64, i64* %6
%63 = sub i64 %62, 1
store i64 %63, i64* %7
br label %64
64: ; preds = %61, %57
store i64 0, i64* %6
br label %72
65: ; preds = %47
%66 = load i64, i64* %6
%67 = load i64, i64* %7
%68 = icmp ugt i64 %66, %67
br i1 %68, label %69, label %71
69: ; preds = %65
%70 = load i64, i64* %6
store i64 %70, i64* %7
br label %71
71: ; preds = %69, %65
br label %72
72: ; preds = %71, %64
%73 = load i32*, i32** %4
%74 = call i32 @fclose(i32* %73)
%75 = load i64, i64* %7
store i64 %75, i64* %2
br label %76
76: ; preds = %72, %12
%77 = load i64, i64* %2
ret i64 %77
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i64 @find_max_line_len(i8* nocapture %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %44, label %6
6: ; preds = %1
%7 = call i64 @feof(i32* %4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %30
9: ; preds = %6, %9
%10 = phi i64 [ %27, %9 ], [ 0, %6 ]
%11 = phi i64 [ %25, %9 ], [ 0, %6 ]
%12 = call i32 @memset(i8* %3, i32 0, i32 256)
%13 = call i32 @fgets(i8* %3, i32 256, i32* %4)
%14 = call i32 @strlen(i8* %3)
%15 = sext i32 %14 to i64
%16 = add i64 %11, %15
%17 = call i32 @strlen(i8* %3)
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %18
%20 = getelementptr inbounds i8, i8* %19, i64 -1
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 10
%23 = icmp ugt i64 %16, %10
%24 = add i64 %16, -1
%25 = select i1 %22, i64 0, i64 %16
%26 = select i1 %22, i1 %23, i1 false
%27 = select i1 %26, i64 %24, i64 %10
%28 = call i64 @feof(i32* %4)
%29 = icmp eq i64 %28, 0
br i1 %29, label %9, label %30
30: ; preds = %9, %6
%31 = phi i64 [ 0, %6 ], [ %25, %9 ]
%32 = phi i64 [ 0, %6 ], [ %27, %9 ]
%33 = call i32 @strlen(i8* %3)
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %34
%36 = getelementptr inbounds i8, i8* %35, i64 -1
%37 = load i8, i8* %36
%38 = icmp eq i8 %37, 10
%39 = icmp ugt i64 %31, %32
%40 = sext i1 %38 to i64
%41 = add i64 %31, %40
%42 = select i1 %39, i64 %41, i64 %32
%43 = call i32 @fclose(i32* %4)
br label %44
44: ; preds = %1, %30
%45 = phi i64 [ %42, %30 ], [ -1, %1 ]
ret i64 %45
}