#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__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ process_cmd(int, char **);
char *strtok(char *, char *);
int load_conf(char *file) {
  char line[1024];
  FILE *fd;
  char *argv[64], *pch;
  int i = 0;
  fd = fopen(file, "r");
  if (!fd) {
    printf("Couldn't load configuration file: %s\n", file);
    return 0;
  }
  while (fgets(line, 1024, fd)) {
    if (line[0] == '#')
      continue;
    i = 0;
    pch = strtok(line, " \r\n");
    while (pch != NULL) {
      argv[i++] = pch;
      pch = strtok(NULL, " \r\n");
    }
    if (i > 0) {
      process_cmd(i, argv);
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<load_conf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x630,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x62c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe8c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
jne    11aa <load_conf+0x5a>
mov    -0x10(%rbp),%rsi
lea    0xe69(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1281 <load_conf+0x131>
jmp    11af <load_conf+0x5f>
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     127a <load_conf+0x12a>
movsbl -0x410(%rbp),%eax
cmp    $0x23,%eax
jne    11e6 <load_conf+0x96>
jmp    11af <load_conf+0x5f>
movl   $0x0,-0x62c(%rbp)
lea    -0x410(%rbp),%rdi
lea    0xe2a(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x628(%rbp)
cmpq   $0x0,-0x628(%rbp)
je     1256 <load_conf+0x106>
mov    -0x628(%rbp),%rcx
mov    -0x62c(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x62c(%rbp)
cltq
mov    %rcx,-0x620(%rbp,%rax,8)
ff
xor    %eax,%eax
mov    %eax,%edi
lea    0xde3(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x628(%rbp)
jmp    120a <load_conf+0xba>
cmpl   $0x0,-0x62c(%rbp)
jle    1275 <load_conf+0x125>
mov    -0x62c(%rbp),%edi
lea    -0x620(%rbp),%rsi
call   1050 <process_cmd@plt>
jmp    11af <load_conf+0x5f>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x630,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_conf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x608,%rsp
mov    %rdi,%rbx
lea    0xe95(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1227 <load_conf+0xd7>
mov    %rax,%r13
lea    0x200(%rsp),%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
mov    $0x1,%r14d
test   %rax,%rax
je     1239 <load_conf+0xe9>
lea    0x200(%rsp),%r15
lea    0xe79(%rip),%rbp
mov    %rsp,%r12
jmp    11d5 <load_conf+0x85>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    $0x400,%esi
mov    %r13,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1239 <load_conf+0xe9>
cmpb   $0x23,0x200(%rsp)
23
je     11c0 <load_conf+0x70>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1070 <strtok@plt>
test   %rax,%rax
je     11c0 <load_conf+0x70>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rax,(%rsp,%rbx,8)
add    $0x1,%rbx
xor    %edi,%edi
mov    %rbp,%rsi
call   1070 <strtok@plt>
test   %rax,%rax
jne    1200 <load_conf+0xb0>
test   %ebx,%ebx
je     11c0 <load_conf+0x70>
mov    %ebx,%edi
mov    %r12,%rsi
call   1050 <process_cmd@plt>
jmp    11c0 <load_conf+0x70>
lea    0xdd4(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x608,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [38 x i8] c"Couldn't load configuration file: %s\0A\00"
@.str.2 = [4 x i8] c" \0D\0A\00"
define i32 @load_conf(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [1024 x i8]
%5 = alloca i32*
%6 = alloca [64 x i8*]
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %8
%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** %5
%11 = load i32*, i32** %5
%12 = icmp ne i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %14)
store i32 0, i32* %2
br label %50
16: ; preds = %1
br label %17
17: ; preds = %48, %27, %16
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%19 = load i32*, i32** %5
%20 = call i64 @fgets(i8* %18, i32 1024, i32* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %49
22: ; preds = %17
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 35
br i1 %26, label %27, label %28
27: ; preds = %22
br label %17
28: ; preds = %22
store i32 0, i32* %8
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%30 = call i8* @strtok(i8* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store i8* %30, i8** %7
br label %31
31: ; preds = %34, %28
%32 = load i8*, i8** %7
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %41
34: ; preds = %31
%35 = load i8*, i8** %7
%36 = load i32, i32* %8
%37 = add nsw i32 %36, 1
store i32 %37, i32* %8
%38 = sext i32 %36 to i64
%39 = getelementptr inbounds [64 x i8*], [64 x i8*]* %6, i64 0, i64 %38
store i8* %35, i8** %39
%40 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store i8* %40, i8** %7
br label %31
41: ; preds = %31
%42 = load i32, i32* %8
%43 = icmp sgt i32 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %41
%45 = load i32, i32* %8
%46 = getelementptr inbounds [64 x i8*], [64 x i8*]* %6, i64 0, i64 0
%47 = call i32 @process_cmd(i32 %45, i8** %46)
br label %48
48: ; preds = %44, %41
br label %17
49: ; preds = %17
store i32 1, i32* %2
br label %50
50: ; preds = %49, %13
%51 = load i32, i32* %2
ret i32 %51
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [38 x i8] c"Couldn't load configuration file: %s\0A\00"
@.str.2 = [4 x i8] c" \0D\0A\00"
define i32 @load_conf(i8* %0) {
%2 = alloca [1024 x i8]
%3 = alloca [64 x i8*]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = bitcast [64 x i8*]* %3 to i8*
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %13, label %8
8: ; preds = %1
%9 = call i64 @fgets(i8* %4, i32 1024, i32* %6)
%10 = icmp eq i64 %9, 0
br i1 %10, label %36, label %11
11: ; preds = %8
%12 = getelementptr inbounds [64 x i8*], [64 x i8*]* %3, i64 0, i64 0
br label %15
13: ; preds = %1
%14 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %36
15: ; preds = %11, %33
%16 = load i8, i8* %4
%17 = icmp eq i8 %16, 35
br i1 %17, label %33, label %18
18: ; preds = %15
%19 = call i8* @strtok(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i8* %19, null
br i1 %20, label %33, label %21
21: ; preds = %18, %21
%22 = phi i64 [ %24, %21 ], [ 0, %18 ]
%23 = phi i8* [ %26, %21 ], [ %19, %18 ]
%24 = add nuw i64 %22, 1
%25 = getelementptr inbounds [64 x i8*], [64 x i8*]* %3, i64 0, i64 %22
store i8* %23, i8** %25
%26 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %21
28: ; preds = %21
%29 = trunc i64 %24 to i32
%30 = icmp eq i32 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %28
%32 = call i32 @process_cmd(i32 %29, i8** %12)
br label %33
33: ; preds = %18, %28, %31, %15
%34 = call i64 @fgets(i8* %4, i32 1024, i32* %6)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %15
36: ; preds = %33, %8, %13
%37 = phi i32 [ 0, %13 ], [ 1, %8 ], [ 1, %33 ]
ret i32 %37
}