#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 config_read(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int config_read_file(const char *file) {
  int ret = 0;
  if (file) {
    FILE *fd = fopen(file, "r");
    if (fd) {
      ret = config_read(fd);
      fclose(fd);
    } else {
      ret = -1;
    }
  } else {
    ret = -1;
  }
  return ret;
}


x86 assembly (clang, -O0):
<config_read_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1193 <config_read_file+0x63>
mov    -0x8(%rbp),%rdi
lea    0xea7(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1187 <config_read_file+0x57>
mov    -0x18(%rbp),%rdi
call   1040 <config_read@plt>
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    118e <config_read_file+0x5e>
movl   $0xffffffff,-0xc(%rbp)
jmp    119a <config_read_file+0x6a>
movl   $0xffffffff,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<config_read_file>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     1162 <config_read_file+0x32>
lea    0xec1(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1162 <config_read_file+0x32>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <config_read@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
jmp    1167 <config_read_file+0x37>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @config_read_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
store i8* %0, i8** %2
store i32 0, i32* %3
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %19
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %4
%10 = load i32*, i32** %4
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %17
12: ; preds = %7
%13 = load i32*, i32** %4
%14 = call i32 @config_read(i32* %13)
store i32 %14, i32* %3
%15 = load i32*, i32** %4
%16 = call i32 @fclose(i32* %15)
br label %18
17: ; preds = %7
store i32 -1, i32* %3
br label %18
18: ; preds = %17, %12
br label %20
19: ; preds = %1
store i32 -1, i32* %3
br label %20
20: ; preds = %19, %18
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @config_read_file(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %9, label %3
3: ; preds = %1
%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 %9, label %6
6: ; preds = %3
%7 = tail call i32 @config_read(i32* %4)
%8 = tail call i32 @fclose(i32* %4)
br label %9
9: ; preds = %1, %6, %3
%10 = phi i32 [ %7, %6 ], [ -1, %3 ], [ -1, %1 ]
ret i32 %10
}