#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__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
char *strchr(char *, char);
int longest_passwd_line(const char *fname) {
  FILE *f = fopen(fname, "r");
  int max = 8;
  char buf[128];
  if (!f)
    return max;
  while (fgets(buf, sizeof buf, f)) {
    char *colon = strchr(buf, ':');
    if (colon) {
      int len = (int)(colon - buf);
      if (len > max)
        max = len;
    }
  }
  fclose(f);
  return max;
}


x86 assembly (clang, -O0):
<longest_passwd_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x8,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1180 <longest_passwd_line+0x40>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1212 <longest_passwd_line+0xd2>
jmp    1185 <longest_passwd_line+0x45>
lea    -0xa0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x80,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1203 <longest_passwd_line+0xc3>
lea    -0xa0(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0xa8(%rbp)
cmpq   $0x0,-0xa8(%rbp)
je     11fe <longest_passwd_line+0xbe>
mov    -0xa8(%rbp),%rax
lea    -0xa0(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0xac(%rbp)
mov    -0xac(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    11f9 <longest_passwd_line+0xb9>
mov    -0xac(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11fe <longest_passwd_line+0xbe>
jmp    1185 <longest_passwd_line+0x45>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<longest_passwd_line>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
lea    0xeae(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11bb <longest_passwd_line+0x7b>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x80,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    $0x8,%ebp
test   %rax,%rax
je     11b1 <longest_passwd_line+0x71>
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %eax,%ecx
sub    %ebx,%ecx
cmp    %ecx,%ebp
cmovge %ebp,%ecx
test   %rax,%rax
cmovne %ecx,%ebp
mov    %rbx,%rdi
mov    $0x80,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    1180 <longest_passwd_line+0x40>
mov    %r14,%rdi
call   1030 <fclose@plt>
jmp    11c0 <longest_passwd_line+0x80>
mov    $0x8,%ebp
mov    %ebp,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @longest_passwd_line(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca [128 x i8]
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %4
store i32 8, i32* %5
%11 = load i32*, i32** %4
%12 = icmp ne i32* %11, null
br i1 %12, label %15, label %13
13: ; preds = %1
%14 = load i32, i32* %5
store i32 %14, i32* %2
br label %44
15: ; preds = %1
br label %16
16: ; preds = %39, %15
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%18 = load i32*, i32** %4
%19 = call i64 @fgets(i8* %17, i32 128, i32* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %40
21: ; preds = %16
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%23 = call i8* @strchr(i8* %22, i8 signext 58)
store i8* %23, i8** %7
%24 = load i8*, i8** %7
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %39
26: ; preds = %21
%27 = load i8*, i8** %7
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%29 = ptrtoint i8* %27 to i64
%30 = ptrtoint i8* %28 to i64
%31 = sub i64 %29, %30
%32 = trunc i64 %31 to i32
store i32 %32, i32* %8
%33 = load i32, i32* %8
%34 = load i32, i32* %5
%35 = icmp sgt i32 %33, %34
br i1 %35, label %36, label %38
36: ; preds = %26
%37 = load i32, i32* %8
store i32 %37, i32* %5
br label %38
38: ; preds = %36, %26
br label %39
39: ; preds = %38, %21
br label %16
40: ; preds = %16
%41 = load i32*, i32** %4
%42 = call i32 @fclose(i32* %41)
%43 = load i32, i32* %5
store i32 %43, i32* %2
br label %44
44: ; preds = %40, %13
%45 = load i32, i32* %2
ret i32 %45
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @longest_passwd_line(i8* nocapture %0) {
%2 = alloca [128 x i8]
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%5 = icmp eq i32* %3, null
br i1 %5, label %26, label %6
6: ; preds = %1
%7 = call i64 @fgets(i8* %4, i32 128, i32* %3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %23, label %9
9: ; preds = %6
%10 = ptrtoint [128 x i8]* %2 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i32 [ 8, %9 ], [ %20, %11 ]
%13 = call i8* @strchr(i8* %4, i8 signext 58)
%14 = icmp eq i8* %13, null
%15 = ptrtoint i8* %13 to i64
%16 = sub i64 %15, %10
%17 = trunc i64 %16 to i32
%18 = icmp slt i32 %12, %17
%19 = select i1 %18, i32 %17, i32 %12
%20 = select i1 %14, i32 %12, i32 %19
%21 = call i64 @fgets(i8* %4, i32 128, i32* %3)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %11
23: ; preds = %11, %6
%24 = phi i32 [ 8, %6 ], [ %20, %11 ]
%25 = call i32 @fclose(i32* %3)
br label %26
26: ; preds = %1, %23
%27 = phi i32 [ %24, %23 ], [ 8, %1 ]
ret i32 %27
}