#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int open_file(FILE **fp, char *filename) {
  *fp = fopen(filename, "r");
  if (!*fp) {
    fprintf(stderr, "i2c: cannot open '%s' file\n", filename);
    perror("i2c: open_file");
    return -3;
  }
  return 0;
}


x86 assembly (clang, -O0):
<open_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1199 <open_file+0x69>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe86(%rip),%rsi
call   1030 <fprintf@plt>
lea    0xe96(%rip),%rdi
call   1050 <perror@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    11a0 <open_file+0x70>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_file>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xebf(%rip),%rsi
mov    %r14,%rdi
call   1040 <fopen@plt>
mov    %rax,%rcx
mov    %rax,(%rbx)
xor    %eax,%eax
test   %rcx,%rcx
je     115e <open_file+0x2e>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
lea    0xe94(%rip),%rsi
mov    %r14,%rdx
call   1030 <fprintf@plt>
lea    0xea1(%rip),%rdi
call   1050 <perror@plt>
mov    $0xfffffffd,%eax
jmp    1156 <open_file+0x26>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"i2c: cannot open '%s' file\0A\00"
@.str.2 = [15 x i8] c"i2c: open_file\00"
define i32 @open_file(i32** %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32**
%5 = alloca i8*
store i32** %0, i32*** %4
store i8* %1, i8** %5
%6 = load i8*, i8** %5
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = load i32**, i32*** %4
store i32* %7, i32** %8
%9 = load i32**, i32*** %4
%10 = load i32*, i32** %9
%11 = icmp ne i32* %10, null
br i1 %11, label %17, label %12
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %5
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 -3, i32* %3
br label %18
17: ; preds = %2
store i32 0, i32* %3
br label %18
18: ; preds = %17, %12
%19 = load i32, i32* %3
ret i32 %19
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"i2c: cannot open '%s' file\0A\00"
@.str.2 = [15 x i8] c"i2c: open_file\00"
define i32 @open_file(i32** nocapture writeonly %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %3, i32** %0
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%8 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %9
9: ; preds = %2, %5
%10 = phi i32 [ -3, %5 ], [ 0, %2 ]
ret i32 %10
}