#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 */
scalar_t__ ParseOption(char *, int);
int /*<<< orphan*/ debug_error(char *, ...);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *strchr(char *, char);
int ParseConfigFile(char *file_path) {
  FILE *config_file;
  char *temp;
  char line[4096 + 1];
  int nline;
  if ((config_file = fopen(file_path, "r")) == NULL) {
    debug_error("Cannot open config file");
    return (-1);
  }
  nline = 0;
  while ((fgets(line, 4096, config_file)) != NULL) {
    if ((temp = strchr(line, '\n')) != NULL)
      *temp = '\0';
    nline++;
    if (ParseOption(line, nline)) {
      debug_error("Error Parsing Config File, at line: %d", nline);
      return (-1);
    }
  }
  fclose(config_file);
  return 0;
}


x86 assembly (clang, -O0):
<ParseConfigFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe86(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11a7 <ParseConfigFile+0x47>
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1080 <debug_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1256 <ParseConfigFile+0xf6>
movl   $0x0,-0x1034(%rbp)
lea    -0x1030(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x1000,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1246 <ParseConfigFile+0xe6>
lea    -0x1030(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11f6 <ParseConfigFile+0x96>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x1034(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1034(%rbp)
lea    -0x1030(%rbp),%rdi
mov    -0x1034(%rbp),%esi
call   1060 <ParseOption@plt>
cmp    $0x0,%rax
je     1241 <ParseConfigFile+0xe1>
mov    -0x1034(%rbp),%esi
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1080 <debug_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1256 <ParseConfigFile+0xf6>
jmp    11b1 <ParseConfigFile+0x51>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ParseConfigFile>:
push   %rbp
push   %r14
push   %rbx
sub    $0x1010,%rsp
lea    0xe8e(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ce <ParseConfigFile+0x6e>
mov    %rax,%r14
xor    %ebp,%ebp
mov    %rsp,%rbx
jmp    11a2 <ParseConfigFile+0x42>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <ParseOption@plt>
test   %rax,%rax
jne    11e3 <ParseConfigFile+0x83>
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11fa <ParseConfigFile+0x9a>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1190 <ParseConfigFile+0x30>
movb   $0x0,(%rax)
jmp    1190 <ParseConfigFile+0x30>
lea    0xe2d(%rip),%rdi
xor    %eax,%eax
call   1080 <debug_error@plt>
mov    $0xffffffff,%eax
jmp    1204 <ParseConfigFile+0xa4>
lea    0xe30(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1080 <debug_error@plt>
mov    $0xffffffff,%eax
jmp    1204 <ParseConfigFile+0xa4>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x1010,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [24 x i8] c"Cannot open config file\00"
@.str.2 = [39 x i8] c"Error Parsing Config File, at line: %d\00"
define i32 @ParseConfigFile(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca [4097 x i8]
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%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 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 (i8*, ...) @debug_error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %39
13: ; preds = %1
store i32 0, i32* %7
br label %14
14: ; preds = %35, %13
%15 = getelementptr inbounds [4097 x i8], [4097 x i8]* %6, i64 0, i64 0
%16 = load i32*, i32** %4
%17 = call i32* @fgets(i8* %15, i32 4096, i32* %16)
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %36
19: ; preds = %14
%20 = getelementptr inbounds [4097 x i8], [4097 x i8]* %6, i64 0, i64 0
%21 = call i8* @strchr(i8* %20, i8 signext 10)
store i8* %21, i8** %5
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = load i8*, i8** %5
store i8 0, i8* %24
br label %25
25: ; preds = %23, %19
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
store i32 %27, i32* %7
%28 = getelementptr inbounds [4097 x i8], [4097 x i8]* %6, i64 0, i64 0
%29 = load i32, i32* %7
%30 = call i64 @ParseOption(i8* %28, i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %25
%33 = load i32, i32* %7
%34 = call i32 (i8*, ...) @debug_error(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %33)
store i32 -1, i32* %2
br label %39
35: ; preds = %25
br label %14
36: ; preds = %14
%37 = load i32*, i32** %4
%38 = call i32 @fclose(i32* %37)
store i32 0, i32* %2
br label %39
39: ; preds = %36, %32, %11
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [24 x i8] c"Cannot open config file\00"
@.str.2 = [39 x i8] c"Error Parsing Config File, at line: %d\00"
define i32 @ParseConfigFile(i8* nocapture %0) {
%2 = alloca [4097 x i8]
%3 = getelementptr inbounds [4097 x i8], [4097 x i8]* %2, i64 0, i64 0
%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 %8
6: ; preds = %1
%7 = tail call i32 (i8*, ...) @debug_error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %24
8: ; preds = %1, %16
%9 = phi i32 [ %17, %16 ], [ 0, %1 ]
%10 = call i32* @fgets(i8* %3, i32 4096, i32* %4)
%11 = icmp eq i32* %10, null
br i1 %11, label %22, label %12
12: ; preds = %8
%13 = call i8* @strchr(i8* %3, i8 signext 10)
%14 = icmp eq i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %12
store i8 0, i8* %13
br label %16
16: ; preds = %15, %12
%17 = add nuw nsw i32 %9, 1
%18 = call i64 @ParseOption(i8* %3, i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %8, label %20
20: ; preds = %16
%21 = call i32 (i8*, ...) @debug_error(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %17)
br label %24
22: ; preds = %8
%23 = call i32 @fclose(i32* %4)
br label %24
24: ; preds = %22, %20, %6
%25 = phi i32 [ -1, %6 ], [ -1, %20 ], [ 0, %22 ]
ret i32 %25
}