#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*/ linebuf;
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 *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int process_line(char *);
int /*<<< orphan*/ stderr;
int process_file(const char *fname) {
  FILE *fp;
  int linenum = 0, err = 0;
  char linebuf[256];
  fp = fopen(fname, "r");
  if (!fp) {
    err = 1;
    goto ret;
  }
  while (fgets(linebuf, sizeof(linebuf), fp)) {
    ++linenum;
    err = process_line(linebuf);
    if (err) {
      fprintf(stderr, "error at line %d: ", linenum);
      break;
    }
  }
ret:
  if (fp)
    fclose(fp);
  return err;
}


x86 assembly (clang, -O0):
<process_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe88(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1198 <process_file+0x48>
movl   $0x1,-0x18(%rbp)
jmp    1205 <process_file+0xb5>
jmp    119d <process_file+0x4d>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x100,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1200 <process_file+0xb0>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
lea    -0x120(%rbp),%rdi
call   1070 <process_line@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11fb <process_file+0xab>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe11(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1200 <process_file+0xb0>
jmp    119d <process_file+0x4d>
jmp    1205 <process_file+0xb5>
cmpq   $0x0,-0x10(%rbp)
je     1219 <process_file+0xc9>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
lea    0xe9a(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11ca <process_file+0x7a>
mov    %rax,%r15
xor    %r14d,%r14d
mov    %rsp,%r12
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11c0 <process_file+0x70>
add    $0x1,%ebp
mov    %r12,%rdi
call   1070 <process_line@plt>
test   %eax,%eax
je     1180 <process_file+0x30>
mov    %eax,%ebx
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
mov    %ebp,%edx
call   1050 <fprintf@plt>
mov    %ebx,%r14d
mov    %r15,%rdi
call   1030 <fclose@plt>
jmp    11d0 <process_file+0x80>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"error at line %d: \00"
define i32 @process_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [256 x i8]
store i8* %0, i8** %2
store i32 0, i32* %4
store i32 0, i32* %5
%7 = load i8*, i8** %2
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %3
%9 = load i32*, i32** %3
%10 = icmp ne i32* %9, null
br i1 %10, label %12, label %11
11: ; preds = %1
store i32 1, i32* %5
br label %31
12: ; preds = %1
br label %13
13: ; preds = %29, %12
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%15 = load i32*, i32** %3
%16 = call i64 @fgets(i8* %14, i32 256, i32* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %30
18: ; preds = %13
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%22 = call i32 @process_line(i8* %21)
store i32 %22, i32* %5
%23 = load i32, i32* %5
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %18
%26 = load i32, i32* @stderr
%27 = load i32, i32* %4
%28 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %27)
br label %30
29: ; preds = %18
br label %13
30: ; preds = %25, %13
br label %31
31: ; preds = %30, %11
%32 = load i32*, i32** %3
%33 = icmp ne i32* %32, null
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i32*, i32** %3
%36 = call i32 @fclose(i32* %35)
br label %37
37: ; preds = %34, %31
%38 = load i32, i32* %5
ret i32 %38
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"error at line %d: \00"
define i32 @process_file(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 %20, label %6
6: ; preds = %1, %10
%7 = phi i32 [ %11, %10 ], [ 0, %1 ]
%8 = call i64 @fgets(i8* %3, i32 256, i32* %4)
%9 = icmp eq i64 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %6
%11 = add nuw nsw i32 %7, 1
%12 = call i32 @process_line(i8* %3)
%13 = icmp eq i32 %12, 0
br i1 %13, label %6, label %14
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %11)
br label %17
17: ; preds = %6, %14
%18 = phi i32 [ %12, %14 ], [ 0, %6 ]
%19 = call i32 @fclose(i32* %4)
br label %20
20: ; preds = %1, %17
%21 = phi i32 [ %18, %17 ], [ 1, %1 ]
ret i32 %21
}