#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 *, char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ load_plugin(char *);
int /*<<< orphan*/ perror(char *);
char *strtok(char *, char *);
int load_plugins() {
  char *line = NULL;
  size_t len = 0;
  FILE *config = fopen("plugins.conf", "r");
  if (config == NULL) {
    perror("fopen");
    return 2;
  }
  while (getline(&line, &len, config) != -1) {
    if ((line[0] == '\n') || (line[0] == '#')) {
      continue;
    }
    line = strtok(line, "\n");
    load_plugin(line);
  }
  fclose(config);
  return 0;
}


x86 assembly (clang, -O0):
<load_plugins>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xe81(%rip),%rdi
lea    0xe87(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b2 <load_plugins+0x52>
lea    0xe6e(%rip),%rdi
call   1060 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1228 <load_plugins+0xc8>
jmp    11b7 <load_plugins+0x57>
mov    -0x20(%rbp),%rdx
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <getline@plt>
cmp    $0xffffffff,%eax
je     1218 <load_plugins+0xb8>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     11f1 <load_plugins+0x91>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    11f6 <load_plugins+0x96>
jmp    11b7 <load_plugins+0x57>
mov    -0x10(%rbp),%rdi
lea    0xe14(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <load_plugin@plt>
jmp    11b7 <load_plugins+0x57>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_plugins>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe7c(%rip),%rdi
lea    0xe82(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1220 <load_plugins+0xc0>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rax,%rdx
call   1080 <getline@plt>
cmp    $0xffffffff,%eax
je     120a <load_plugins+0xaa>
lea    0x8(%rsp),%r14
lea    0x10(%rsp),%r15
lea    0xe51(%rip),%r12
jmp    11e3 <load_plugins+0x83>
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1080 <getline@plt>
cmp    $0xffffffff,%eax
je     120a <load_plugins+0xaa>
mov    0x8(%rsp),%rdi
movzbl (%rdi),%eax
cmp    $0x23,%al
je     11d0 <load_plugins+0x70>
cmp    $0xa,%al
je     11d0 <load_plugins+0x70>
mov    %r12,%rsi
call   1070 <strtok@plt>
mov    %rax,0x8(%rsp)
mov    %rax,%rdi
call   1030 <load_plugin@plt>
jmp    11d0 <load_plugins+0x70>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xde8(%rip),%rdi
call   1060 <perror@plt>
mov    $0x2,%eax
jmp    1214 <load_plugins+0xb4>

LLVM IR (-O0):
@.str = [13 x i8] c"plugins.conf\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"fopen\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @load_plugins() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32*
store i8* null, i8** %2
store i64 0, i64* %3
%5 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %4
%6 = load i32*, i32** %4
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %1
br label %36
10: ; preds = %0
br label %11
11: ; preds = %28, %27, %10
%12 = load i32*, i32** %4
%13 = call i32 @getline(i8** %2, i64* %3, i32* %12)
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %33
15: ; preds = %11
%16 = load i8*, i8** %2
%17 = getelementptr inbounds i8, i8* %16, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 10
br i1 %20, label %27, label %21
21: ; preds = %15
%22 = load i8*, i8** %2
%23 = getelementptr inbounds i8, i8* %22, 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 = %21, %15
br label %11
28: ; preds = %21
%29 = load i8*, i8** %2
%30 = call i8* @strtok(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %30, i8** %2
%31 = load i8*, i8** %2
%32 = call i32 @load_plugin(i8* %31)
br label %11
33: ; preds = %11
%34 = load i32*, i32** %4
%35 = call i32 @fclose(i32* %34)
store i32 0, i32* %1
br label %36
36: ; preds = %33, %8
%37 = load i32, i32* %1
ret i32 %37
}

LLVM IR (-O2):
@.str = [13 x i8] c"plugins.conf\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"fopen\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @load_plugins() {
%1 = alloca i8*
%2 = alloca i64
%3 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%4 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %0
%8 = call i32 @getline(i8** %1, i64* %2, i32* %5)
%9 = icmp eq i32 %8, -1
br i1 %9, label %21, label %12
10: ; preds = %0
%11 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %23
12: ; preds = %7, %15
%13 = load i8*, i8** %1
%14 = load i8, i8* %13
switch i8 %14, label %18 [
i8 10, label %15
i8 35, label %15
]
15: ; preds = %12, %12, %18
%16 = call i32 @getline(i8** %1, i64* %2, i32* %5)
%17 = icmp eq i32 %16, -1
br i1 %17, label %21, label %12
18: ; preds = %12
%19 = call i8* @strtok(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %19, i8** %1
%20 = call i32 @load_plugin(i8* %19)
br label %15
21: ; preds = %15, %7
%22 = call i32 @fclose(i32* %5)
br label %23
23: ; preds = %21, %10
%24 = phi i32 [ 2, %10 ], [ 0, %21 ]
ret i32 %24
}