#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*/ decode_line(char *, scalar_t__);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ strlen(char *);
int open_cfg_file() {
  FILE *cfg_file;
  char buf[1000];
  cfg_file = fopen("cfg/config.txt", "r");
  if (!cfg_file)
    return 1;
  while (fgets(buf, 1000, cfg_file) != NULL) {
    decode_line(buf, strlen(buf) + 1);
  }
  fclose(cfg_file);
  return 0;
}


x86 assembly (clang, -O0):
<open_cfg_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
lea    0xe9e(%rip),%rdi
lea    0xea6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1189 <open_cfg_file+0x39>
movl   $0x1,-0x4(%rbp)
jmp    11ef <open_cfg_file+0x9f>
jmp    118e <open_cfg_file+0x3e>
lea    -0x400(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x3e8,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11df <open_cfg_file+0x8f>
lea    -0x400(%rbp),%rax
mov    %rax,-0x408(%rbp)
lea    -0x400(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x408(%rbp),%rdi
mov    %rax,%rsi
add    $0x1,%rsi
call   1070 <decode_line@plt>
jmp    118e <open_cfg_file+0x3e>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_cfg_file>:
push   %r14
push   %rbx
sub    $0x3e8,%rsp
lea    0xe9f(%rip),%rdi
lea    0xea7(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11c5 <open_cfg_file+0x75>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x3e8,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11b9 <open_cfg_file+0x69>
mov    %rsp,%rbx
nopl   (%rax)
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rsi
mov    %rbx,%rdi
call   1070 <decode_line@plt>
mov    %rbx,%rdi
mov    $0x3e8,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    1190 <open_cfg_file+0x40>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    11ca <open_cfg_file+0x7a>
mov    $0x1,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [15 x i8] c"cfg/config.txt\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @open_cfg_file() {
%1 = alloca [1000 x i8]
%2 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %16, label %5
5: ; preds = %0
%6 = call i32* @fgets(i8* %2, i32 1000, i32* %3)
%7 = icmp eq i32* %6, null
br i1 %7, label %14, label %8
8: ; preds = %5, %8
%9 = call i64 @strlen(i8* %2)
%10 = add nsw i64 %9, 1
%11 = call i32 @decode_line(i8* %2, i64 %10)
%12 = call i32* @fgets(i8* %2, i32 1000, i32* %3)
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %8
14: ; preds = %8, %5
%15 = call i32 @fclose(i32* %3)
br label %16
16: ; preds = %0, %14
%17 = phi i32 [ 0, %14 ], [ 1, %0 ]
ret i32 %17
}