#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*/ tmp;
typedef int /*<<< orphan*/ line;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
scalar_t__ config_parse_line(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, int);
int open(char const *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int config_parse_file(const char *filename) {
  int fd = open(filename, O_RDONLY);
  if (fd < 0)
    return fd;
  char tmp[1025];
  char line[1024];
  int nr;
  int lineno = 0;
  while ((nr = read(fd, tmp, sizeof(tmp) - 1)) > 0) {
    tmp[nr] = 0;
    if (nr < sizeof(tmp))
      tmp[nr] = 0;
    char *where = tmp;
    char *where_next = NULL;
    *line = 0;
    while ((where_next = strchr(where, '\n'))) {
      lineno++;
      *where_next = '\0';
      strncat(line, where, sizeof(line) - 1);
      if (config_parse_line(line) != 0)
        goto error;
      *line = 0;
      where = where_next + 1;
    }
    strncpy(line, where, tmp + sizeof(tmp) - where);
    if (nr < sizeof(tmp)) {
      if (config_parse_line(line) != 0)
        goto error;
    }
  }
  close(fd);
  return 0;
error:
  fprintf(stderr, "Error parsing config file %s:%d", filename, lineno);
  close(fd);
  return 1;
}


x86 assembly (clang, -O0):
<config_parse_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11b9 <config_parse_file+0x39>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1369 <config_parse_file+0x1e9>
movl   $0x0,-0x828(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1070 <read@plt>
mov    %eax,-0x824(%rbp)
cmp    $0x0,%eax
jle    1327 <config_parse_file+0x1a7>
movslq -0x824(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
movslq -0x824(%rbp),%rax
cmp    $0x401,%rax
jae    1217 <config_parse_file+0x97>
movslq -0x824(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
lea    -0x420(%rbp),%rax
mov    %rax,-0x830(%rbp)
movq   $0x0,-0x838(%rbp)
movb   $0x0,-0x820(%rbp)
mov    -0x830(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x838(%rbp)
cmp    $0x0,%rax
je     12c3 <config_parse_file+0x143>
mov    -0x828(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x828(%rbp)
mov    -0x838(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x820(%rbp),%rdi
mov    -0x830(%rbp),%rsi
mov    $0x3ff,%edx
call   1050 <strncat@plt>
lea    -0x820(%rbp),%rdi
call   1090 <config_parse_line@plt>
cmp    $0x0,%rax
je     12a5 <config_parse_file+0x125>
jmp    133b <config_parse_file+0x1bb>
movb   $0x0,-0x820(%rbp)
mov    -0x838(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x830(%rbp)
jmp    1237 <config_parse_file+0xb7>
lea    -0x820(%rbp),%rdi
mov    -0x830(%rbp),%rsi
lea    -0x420(%rbp),%rax
add    $0x401,%rax
mov    -0x830(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
movslq -0x824(%rbp),%rax
cmp    $0x401,%rax
jae    1322 <config_parse_file+0x1a2>
lea    -0x820(%rbp),%rdi
call   1090 <config_parse_line@plt>
cmp    $0x0,%rax
je     131d <config_parse_file+0x19d>
jmp    133b <config_parse_file+0x1bb>
jmp    1322 <config_parse_file+0x1a2>
jmp    11c3 <config_parse_file+0x43>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    1369 <config_parse_file+0x1e9>
mov    0x2c96(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x828(%rbp),%ecx
lea    0xcab(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<config_parse_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x828,%rsp
mov    %rdi,%rbx
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,%r12d
test   %eax,%eax
js     12e3 <config_parse_file+0x163>
lea    0x10(%rsp),%r14
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    12d6 <config_parse_file+0x156>
mov    %eax,%r13d
mov    %rbx,0x8(%rsp)
xor    %ebp,%ebp
lea    0x420(%rsp),%rbx
jmp    1200 <config_parse_file+0x80>
xchg   %ax,%ax
mov    %r12d,%edi
lea    0x10(%rsp),%r14
mov    %r14,%rsi
mov    $0x400,%edx
call   1070 <read@plt>
mov    %eax,%r13d
test   %eax,%eax
jle    12d6 <config_parse_file+0x156>
mov    %r13d,%eax
movb   $0x0,0x10(%rsp,%rax,1)
movb   $0x0,0x420(%rsp)
mov    %r14,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1278 <config_parse_file+0xf8>
mov    %rax,%r15
cs nopw 0x0(%rax,%rax,1)
nop
movb   $0x0,(%r15)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3ff,%edx
call   1050 <strncat@plt>
mov    %rbx,%rdi
call   1090 <config_parse_line@plt>
test   %rax,%rax
jne    12b0 <config_parse_file+0x130>
movb   $0x0,0x420(%rsp)
mov    %r15,%r14
add    $0x1,%r14
mov    %r14,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,%r15
add    $0x1,%ebp
test   %rax,%rax
jne    1230 <config_parse_file+0xb0>
lea    0x411(%rsp),%rax
mov    %eax,%edx
sub    %r14d,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strncpy@plt>
cmp    $0x400,%r13d
ja     11e0 <config_parse_file+0x60>
mov    %rbx,%rdi
call   1090 <config_parse_line@plt>
test   %rax,%rax
je     11e0 <config_parse_file+0x60>
jmp    12b3 <config_parse_file+0x133>
add    $0x1,%ebp
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
lea    0xd3d(%rip),%rsi
mov    0x8(%rsp),%rdx
mov    %ebp,%ecx
call   1080 <fprintf@plt>
mov    $0x1,%ebx
jmp    12d8 <config_parse_file+0x158>
xor    %ebx,%ebx
mov    %r12d,%edi
call   1060 <close@plt>
mov    %ebx,%r12d
mov    %r12d,%eax
add    $0x828,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [32 x i8] c"Error parsing config file %s:%d\00"
define i32 @config_parse_file(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [1025 x i8]
%6 = alloca [1024 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %3
%11 = load i8*, i8** %3
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @open(i8* %11, i32 %12)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %1
%17 = load i32, i32* %4
store i32 %17, i32* %2
br label %88
18: ; preds = %1
store i32 0, i32* %8
br label %19
19: ; preds = %77, %18
%20 = load i32, i32* %4
%21 = getelementptr inbounds [1025 x i8], [1025 x i8]* %5, i64 0, i64 0
%22 = call i32 @read(i32 %20, i8* %21, i32 1024)
store i32 %22, i32* %7
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %78
24: ; preds = %19
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [1025 x i8], [1025 x i8]* %5, i64 0, i64 %26
store i8 0, i8* %27
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = icmp ult i64 %29, 1025
br i1 %30, label %31, label %35
31: ; preds = %24
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [1025 x i8], [1025 x i8]* %5, i64 0, i64 %33
store i8 0, i8* %34
br label %35
35: ; preds = %31, %24
%36 = getelementptr inbounds [1025 x i8], [1025 x i8]* %5, i64 0, i64 0
store i8* %36, i8** %9
store i8* null, i8** %10
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
store i8 0, i8* %37
br label %38
38: ; preds = %53, %35
%39 = load i8*, i8** %9
%40 = call i8* @strchr(i8* %39, i8 signext 10)
store i8* %40, i8** %10
%41 = icmp ne i8* %40, null
br i1 %41, label %42, label %57
42: ; preds = %38
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
%45 = load i8*, i8** %10
store i8 0, i8* %45
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%47 = load i8*, i8** %9
%48 = call i32 @strncat(i8* %46, i8* %47, i32 1023)
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%50 = call i64 @config_parse_line(i8* %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %42
br label %81
53: ; preds = %42
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
store i8 0, i8* %54
%55 = load i8*, i8** %10
%56 = getelementptr inbounds i8, i8* %55, i64 1
store i8* %56, i8** %9
br label %38
57: ; preds = %38
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%59 = load i8*, i8** %9
%60 = getelementptr inbounds [1025 x i8], [1025 x i8]* %5, i64 0, i64 0
%61 = getelementptr inbounds i8, i8* %60, i64 1025
%62 = load i8*, i8** %9
%63 = ptrtoint i8* %61 to i64
%64 = ptrtoint i8* %62 to i64
%65 = sub i64 %63, %64
%66 = trunc i64 %65 to i32
%67 = call i32 @strncpy(i8* %58, i8* %59, i32 %66)
%68 = load i32, i32* %7
%69 = sext i32 %68 to i64
%70 = icmp ult i64 %69, 1025
br i1 %70, label %71, label %77
71: ; preds = %57
%72 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%73 = call i64 @config_parse_line(i8* %72)
%74 = icmp ne i64 %73, 0
br i1 %74, label %75, label %76
75: ; preds = %71
br label %81
76: ; preds = %71
br label %77
77: ; preds = %76, %57
br label %19
78: ; preds = %19
%79 = load i32, i32* %4
%80 = call i32 @close(i32 %79)
store i32 0, i32* %2
br label %88
81: ; preds = %75, %52
%82 = load i32, i32* @stderr
%83 = load i8*, i8** %3
%84 = load i32, i32* %8
%85 = call i32 @fprintf(i32 %82, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %83, i32 %84)
%86 = load i32, i32* %4
%87 = call i32 @close(i32 %86)
store i32 1, i32* %2
br label %88
88: ; preds = %81, %78, %16
%89 = load i32, i32* %2
ret i32 %89
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [32 x i8] c"Error parsing config file %s:%d\00"
define i32 @config_parse_file(i8* %0) {
%2 = alloca [1025 x i8]
%3 = alloca [1024 x i8]
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %55, label %7
7: ; preds = %1
%8 = getelementptr inbounds [1025 x i8], [1025 x i8]* %2, i64 0, i64 0
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%10 = call i32 @read(i32 %5, i8* %8, i32 1024)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %52
12: ; preds = %7
%13 = getelementptr inbounds [1025 x i8], [1025 x i8]* %2, i64 0, i64 1025
%14 = ptrtoint i8* %13 to i64
br label %15
15: ; preds = %12, %45
%16 = phi i32 [ %10, %12 ], [ %46, %45 ]
%17 = phi i32 [ 0, %12 ], [ %36, %45 ]
%18 = zext i32 %16 to i64
%19 = getelementptr inbounds [1025 x i8], [1025 x i8]* %2, i64 0, i64 %18
%20 = icmp ult i32 %16, 1025
store i8 0, i8* %19
store i8 0, i8* %9
%21 = call i8* @strchr(i8* dereferenceable(1) %8, i8 signext 10)
%22 = icmp eq i8* %21, null
br i1 %22, label %35, label %23
23: ; preds = %15, %31
%24 = phi i8* [ %33, %31 ], [ %21, %15 ]
%25 = phi i8* [ %32, %31 ], [ %8, %15 ]
%26 = phi i32 [ %27, %31 ], [ %17, %15 ]
%27 = add nsw i32 %26, 1
store i8 0, i8* %24
%28 = call i32 @strncat(i8* %9, i8* %25, i32 1023)
%29 = call i64 @config_parse_line(i8* %9)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %48
31: ; preds = %23
store i8 0, i8* %9
%32 = getelementptr inbounds i8, i8* %24, i64 1
%33 = call i8* @strchr(i8* dereferenceable(1) %32, i8 signext 10)
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %23
35: ; preds = %31, %15
%36 = phi i32 [ %17, %15 ], [ %27, %31 ]
%37 = phi i8* [ %8, %15 ], [ %32, %31 ]
%38 = ptrtoint i8* %37 to i64
%39 = sub i64 %14, %38
%40 = trunc i64 %39 to i32
%41 = call i32 @strncpy(i8* %9, i8* %37, i32 %40)
br i1 %20, label %42, label %45
42: ; preds = %35
%43 = call i64 @config_parse_line(i8* %9)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %35, %42
%46 = call i32 @read(i32 %5, i8* %8, i32 1024)
%47 = icmp sgt i32 %46, 0
br i1 %47, label %15, label %52
48: ; preds = %42, %23
%49 = phi i32 [ %27, %23 ], [ %36, %42 ]
%50 = load i32, i32* @stderr
%51 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %49)
br label %52
52: ; preds = %45, %7, %48
%53 = phi i32 [ 1, %48 ], [ 0, %7 ], [ 0, %45 ]
%54 = call i32 @close(i32 %5)
br label %55
55: ; preds = %1, %52
%56 = phi i32 [ %53, %52 ], [ %5, %1 ]
ret i32 %56
}