#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*/ errno;
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
FILE *open_file(const char *file, int *reported) {
  FILE *fp = fopen(file, "r");
  if (!fp) {
    if (!reported || *reported == 0) {
      fprintf(stderr,
              "torsmo: "
              "can't open %s: %s"
              "\n",
              file, strerror(errno));
      if (reported)
        *reported = 1;
    }
    return 0;
  }
  return fp;
}


x86 assembly (clang, -O0):
<open_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d6 <open_file+0xa6>
cmpq   $0x0,-0x18(%rbp)
je     1177 <open_file+0x47>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jne    11c9 <open_file+0x99>
mov    0x2e62(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xe58(%rip),%rsi
call   1030 <fprintf@plt>
cmpq   $0x0,-0x18(%rbp)
je     11c4 <open_file+0x94>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
jmp    11c9 <open_file+0x99>
movq   $0x0,-0x8(%rbp)
jmp    11de <open_file+0xae>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xebc(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     115f <open_file+0x2f>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
test   %r15,%r15
je     119e <open_file+0x6e>
cmpl   $0x0,(%r15)
jne    1151 <open_file+0x21>
mov    0x2e6f(%rip),%rax
mov    (%rax),%ebp
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe7a(%rip),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    %rax,%rcx
call   1030 <fprintf@plt>
movl   $0x1,(%r15)
jmp    1151 <open_file+0x21>
mov    0x2e3b(%rip),%rax
mov    (%rax),%ebp
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe46(%rip),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    %rax,%rcx
call   1030 <fprintf@plt>
jmp    1151 <open_file+0x21>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"torsmo: can't open %s: %s\0A\00"
@errno = global i32 0
define i32* @open_file(i8* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
store i8* %0, i8** %4
store i32* %1, i32** %5
%7 = load i8*, i8** %4
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp ne i32* %9, null
br i1 %10, label %30, label %11
11: ; preds = %2
%12 = load i32*, i32** %5
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i32*, i32** %5
%16 = load i32, i32* %15
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %29
18: ; preds = %14, %11
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %4
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %20, i8* %22)
%24 = load i32*, i32** %5
%25 = icmp ne i32* %24, null
br i1 %25, label %26, label %28
26: ; preds = %18
%27 = load i32*, i32** %5
store i32 1, i32* %27
br label %28
28: ; preds = %26, %18
br label %29
29: ; preds = %28, %14
store i32* null, i32** %3
br label %32
30: ; preds = %2
%31 = load i32*, i32** %6
store i32* %31, i32** %3
br label %32
32: ; preds = %30, %29
%33 = load i32*, i32** %3
ret i32* %33
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"torsmo: can't open %s: %s\0A\00"
@errno = global i32 0
define noalias i32* @open_file(i8* %0, i32* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %20
5: ; preds = %2
%6 = icmp eq i32* %1, null
br i1 %6, label %15, label %7
7: ; preds = %5
%8 = load i32, i32* %1
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %20
10: ; preds = %7
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = tail call i8* @strerror(i32 %12)
%14 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %13)
store i32 1, i32* %1
br label %20
15: ; preds = %5
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = tail call i8* @strerror(i32 %17)
%19 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %18)
br label %20
20: ; preds = %2, %7, %10, %15
ret i32* %3
}