#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 */
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int __uio_line_from_file(char *filename, char *linebuf) {
  char *s;
  int i;
  memset(linebuf, 0, 64);
  FILE *file = fopen(filename, "r");
  if (!file)
    return -1;
  s = fgets(linebuf, 64, file);
  if (!s)
    return -2;
  for (i = 0; (*s) && (i < 64); i++) {
    if (*s == '\n')
      *s = 0;
    s++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<__uio_line_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    117b <__uio_line_from_file+0x4b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1216 <__uio_line_from_file+0xe6>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    $0x40,%esi
call   1040 <fgets@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a8 <__uio_line_from_file+0x78>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1216 <__uio_line_from_file+0xe6>
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x31(%rbp)
je     11ce <__uio_line_from_file+0x9e>
cmpl   $0x40,-0x24(%rbp)
setl   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11de <__uio_line_from_file+0xae>
jmp    120f <__uio_line_from_file+0xdf>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    11f5 <__uio_line_from_file+0xc5>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11af <__uio_line_from_file+0x7f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__uio_line_from_file>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1030 <memset@plt>
lea    0xeb0(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     11a0 <__uio_line_from_file+0x70>
mov    %r14,%rdi
mov    $0x40,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11a7 <__uio_line_from_file+0x77>
mov    (%rax),%bl
test   %bl,%bl
je     11ae <__uio_line_from_file+0x7e>
xor    %edx,%edx
xor    %ecx,%ecx
nopl   0x0(%rax)
cmp    $0xa,%bl
jne    1189 <__uio_line_from_file+0x59>
movb   $0x0,(%rax,%rdx,1)
movzbl 0x1(%rax,%rdx,1),%ebx
test   %bl,%bl
je     11b0 <__uio_line_from_file+0x80>
lea    0x1(%rdx),%rsi
cmp    $0x3f,%edx
mov    %rsi,%rdx
jb     1180 <__uio_line_from_file+0x50>
jmp    11b0 <__uio_line_from_file+0x80>
mov    $0xffffffff,%ecx
jmp    11b0 <__uio_line_from_file+0x80>
mov    $0xfffffffe,%ecx
jmp    11b0 <__uio_line_from_file+0x80>
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @__uio_line_from_file(i8* nocapture %0, i8* %1) {
%3 = tail call i32 @memset(i8* %1, i32 0, i32 64)
%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 %25, label %6
6: ; preds = %2
%7 = tail call i8* @fgets(i8* %1, i32 64, i32* %4)
%8 = icmp eq i8* %7, null
br i1 %8, label %25, label %9
9: ; preds = %6
%10 = load i8, i8* %7
%11 = icmp eq i8 %10, 0
br i1 %11, label %25, label %12
12: ; preds = %9, %18
%13 = phi i8 [ %21, %18 ], [ %10, %9 ]
%14 = phi i32 [ %20, %18 ], [ 0, %9 ]
%15 = phi i8* [ %19, %18 ], [ %7, %9 ]
%16 = icmp eq i8 %13, 10
br i1 %16, label %17, label %18
17: ; preds = %12
store i8 0, i8* %15
br label %18
18: ; preds = %17, %12
%19 = getelementptr inbounds i8, i8* %15, i64 1
%20 = add nuw nsw i32 %14, 1
%21 = load i8, i8* %19
%22 = icmp ne i8 %21, 0
%23 = icmp ult i32 %14, 63
%24 = select i1 %22, i1 %23, i1 false
br i1 %24, label %12, label %25
25: ; preds = %18, %9, %6, %2
%26 = phi i32 [ -1, %2 ], [ -2, %6 ], [ 0, %9 ], [ 0, %18 ]
ret i32 %26
}