#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ load_config_file(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int read_config(const char *file) {
  FILE *fp = NULL;
  if (file == NULL) {
    return 0;
  }
  if ((fp = fopen(file, "r")) == NULL) {
    fprintf(stderr, "Couldn't open %s. No config found\n", file);
    return 0;
  }
  fprintf(stdout, "Using config file %s.\n", file);
  load_config_file(fp);
  fclose(fp);
  return 1;
}


x86 assembly (clang, -O0):
<read_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116b <read_config+0x2b>
movl   $0x0,-0x4(%rbp)
jmp    11e0 <read_config+0xa0>
mov    -0x10(%rbp),%rdi
lea    0xe8a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11ae <read_config+0x6e>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe65(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e0 <read_config+0xa0>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe63(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <load_config_file@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_config>:
push   %rbp
push   %r14
push   %rbx
xor    %r14d,%r14d
test   %rdi,%rdi
je     11ab <read_config+0x6b>
mov    %rdi,%rbx
lea    0xeaa(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1193 <read_config+0x53>
mov    %rax,%rbp
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
lea    0xeb2(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
mov    %rbp,%rdi
call   1030 <load_config_file@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    $0x1,%r14d
jmp    11ab <read_config+0x6b>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
lea    0xe5f(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"Couldn't open %s. No config found\0A\00"
@stdout = global i32 0
@.str.2 = [23 x i8] c"Using config file %s.\0A\00"
define i32 @read_config(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
store i8* %0, i8** %3
store i32* null, i32** %4
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 0, i32* %2
br label %24
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %4
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %3
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %14)
store i32 0, i32* %2
br label %24
16: ; preds = %8
%17 = load i32, i32* @stdout
%18 = load i8*, i8** %3
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = load i32*, i32** %4
%21 = call i32 @load_config_file(i32* %20)
%22 = load i32*, i32** %4
%23 = call i32 @fclose(i32* %22)
store i32 1, i32* %2
br label %24
24: ; preds = %16, %12, %7
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"Couldn't open %s. No config found\0A\00"
@stdout = global i32 0
@.str.2 = [23 x i8] c"Using config file %s.\0A\00"
define i32 @read_config(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %14, 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 %6, label %9
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %14
9: ; preds = %3
%10 = load i32, i32* @stdout
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%12 = tail call i32 @load_config_file(i32* %4)
%13 = tail call i32 @fclose(i32* %4)
br label %14
14: ; preds = %1, %9, %6
%15 = phi i32 [ 0, %6 ], [ 1, %9 ], [ 0, %1 ]
ret i32 %15
}