#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int strlen(char *);
int get_longest_line_len(FILE *fr) {
  int buff_size = 100;
  char buff[buff_size];
  int max = 0, tmp;
  while (fgets(buff, buff_size, fr) != NULL) {
    if ((tmp = strlen(buff)) > max) {
      max = tmp;
    }
  }
  rewind(fr);
  return max;
}


x86 assembly (clang, -O0):
<get_longest_line_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x64,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%rdx
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11aa <get_longest_line_len+0x7a>
mov    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
cmp    -0x24(%rbp),%eax
jle    11a5 <get_longest_line_len+0x75>
mov    -0x28(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1170 <get_longest_line_len+0x40>
mov    -0x8(%rbp),%rdi
call   1040 <rewind@plt>
mov    -0x24(%rbp),%eax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_longest_line_len>:
push   %rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1182 <get_longest_line_len+0x52>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    %ebp,%eax
cmovg  %eax,%ebp
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    1160 <get_longest_line_len+0x30>
mov    %r14,%rdi
call   1040 <rewind@plt>
mov    %ebp,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_longest_line_len(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %2
store i32 100, i32* %3
%8 = load i32, i32* %3
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %4
%11 = alloca i8, i64 %9
store i64 %9, i64* %5
store i32 0, i32* %6
br label %12
12: ; preds = %23, %1
%13 = load i32, i32* %3
%14 = load i32*, i32** %2
%15 = call i32* @fgets(i8* %11, i32 %13, i32* %14)
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %24
17: ; preds = %12
%18 = call i32 @strlen(i8* %11)
store i32 %18, i32* %7
%19 = load i32, i32* %6
%20 = icmp sgt i32 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = load i32, i32* %7
store i32 %22, i32* %6
br label %23
23: ; preds = %21, %17
br label %12
24: ; preds = %12
%25 = load i32*, i32** %2
%26 = call i32 @rewind(i32* %25)
%27 = load i32, i32* %6
%28 = load i8*, i8** %4
ret i32 %27
}

LLVM IR (-O2):
define i32 @get_longest_line_len(i32* nocapture %0) {
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%4 = call i32* @fgets(i8* %3, i32 100, i32* %0)
%5 = icmp eq i32* %4, null
br i1 %5, label %13, label %6
6: ; preds = %1, %6
%7 = phi i32 [ %10, %6 ], [ 0, %1 ]
%8 = call i32 @strlen(i8* %3)
%9 = icmp sgt i32 %8, %7
%10 = select i1 %9, i32 %8, i32 %7
%11 = call i32* @fgets(i8* %3, i32 100, i32* %0)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %6
13: ; preds = %6, %1
%14 = phi i32 [ 0, %1 ], [ %10, %6 ]
%15 = call i32 @rewind(i32* %0)
ret i32 %14
}