#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 struct Option Option;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ ferror(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct Option *parse_opt_line(char *);
int /*<<< orphan*/ stderr;
void stub1(struct Option *);
void stub2(struct Option *);
void read_config(FILE *fp, void (**handle_opt)(struct Option *)) {
  char line[1024];
  struct Option *opt;
  void (**tmp)(struct Option *) = handle_opt;
  while (fgets(line, 1024, fp)) {
    opt = parse_opt_line(line);
    for (tmp = handle_opt; *tmp; *tmp++)
      (*tmp)(opt);
  }
  for (; *handle_opt; *handle_opt++)
    (*handle_opt)(NULL);
  if (ferror(fp))
    fprintf(stderr, "An error occurred while reading the config file.\n");
}


x86 assembly (clang, -O0):
<read_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x420(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11db <read_config+0x9b>
lea    -0x410(%rbp),%rdi
call   1060 <parse_opt_line@plt>
mov    %rax,-0x418(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x420(%rbp)
mov    -0x420(%rbp),%rax
cmpq   $0x0,(%rax)
je     11d6 <read_config+0x96>
mov    -0x420(%rbp),%rax
mov    (%rax),%rax
mov    -0x418(%rbp),%rdi
call   *%rax
mov    -0x420(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x420(%rbp)
jmp    119b <read_config+0x5b>
jmp    115e <read_config+0x1e>
jmp    11e0 <read_config+0xa0>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1209 <read_config+0xc9>
mov    -0x10(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edi
call   *(%rax)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    11e0 <read_config+0xa0>
mov    -0x8(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1231 <read_config+0xf1>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
lea    0xdd4(%rip),%rsi
call   1050 <fprintf@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_config>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r12
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11c4 <read_config+0x84>
lea    0x8(%r12),%r13
mov    %rsp,%r15
jmp    1195 <read_config+0x55>
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11c4 <read_config+0x84>
mov    %r15,%rdi
call   1060 <parse_opt_line@plt>
mov    %rax,%rbx
mov    (%r12),%rax
test   %rax,%rax
je     1180 <read_config+0x40>
mov    %r13,%rbp
nopl   0x0(%rax)
mov    %rbx,%rdi
call   *%rax
mov    0x0(%rbp),%rax
add    $0x8,%rbp
test   %rax,%rax
jne    11b0 <read_config+0x70>
jmp    1180 <read_config+0x40>
mov    (%r12),%rax
test   %rax,%rax
je     11f1 <read_config+0xb1>
add    $0x8,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
call   *%rax
mov    (%r12),%rax
add    $0x8,%r12
test   %rax,%rax
jne    11e0 <read_config+0xa0>
mov    %r14,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     1213 <read_config+0xd3>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
lea    0xdf2(%rip),%rsi
call   1050 <fprintf@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.Option = type opaque
@stderr = global i32 0
@.str = [50 x i8] c"An error occurred while reading the config file.\0A\00"
define void @read_config(i32* %0, void (%struct.Option*)** %1) {
%3 = alloca i32*
%4 = alloca void (%struct.Option*)**
%5 = alloca [1024 x i8]
%6 = alloca %struct.Option*
%7 = alloca void (%struct.Option*)**
store i32* %0, i32** %3
store void (%struct.Option*)** %1, void (%struct.Option*)*** %4
%8 = load void (%struct.Option*)**, void (%struct.Option*)*** %4
store void (%struct.Option*)** %8, void (%struct.Option*)*** %7
br label %9
9: ; preds = %30, %2
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%11 = load i32*, i32** %3
%12 = call i64 @fgets(i8* %10, i32 1024, i32* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %31
14: ; preds = %9
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%16 = call %struct.Option* @parse_opt_line(i8* %15)
store %struct.Option* %16, %struct.Option** %6
%17 = load void (%struct.Option*)**, void (%struct.Option*)*** %4
store void (%struct.Option*)** %17, void (%struct.Option*)*** %7
br label %18
18: ; preds = %26, %14
%19 = load void (%struct.Option*)**, void (%struct.Option*)*** %7
%20 = load void (%struct.Option*)*, void (%struct.Option*)** %19
%21 = icmp ne void (%struct.Option*)* %20, null
br i1 %21, label %22, label %30
22: ; preds = %18
%23 = load void (%struct.Option*)**, void (%struct.Option*)*** %7
%24 = load void (%struct.Option*)*, void (%struct.Option*)** %23
%25 = load %struct.Option*, %struct.Option** %6
br label %26
26: ; preds = %22
%27 = load void (%struct.Option*)**, void (%struct.Option*)*** %7
%28 = getelementptr inbounds void (%struct.Option*)*, void (%struct.Option*)** %27, i32 1
store void (%struct.Option*)** %28, void (%struct.Option*)*** %7
%29 = load void (%struct.Option*)*, void (%struct.Option*)** %27
br label %18
30: ; preds = %18
br label %9
31: ; preds = %9
br label %32
32: ; preds = %39, %31
%33 = load void (%struct.Option*)**, void (%struct.Option*)*** %4
%34 = load void (%struct.Option*)*, void (%struct.Option*)** %33
%35 = icmp ne void (%struct.Option*)* %34, null
br i1 %35, label %36, label %43
36: ; preds = %32
%37 = load void (%struct.Option*)**, void (%struct.Option*)*** %4
%38 = load void (%struct.Option*)*, void (%struct.Option*)** %37
br label %39
39: ; preds = %36
%40 = load void (%struct.Option*)**, void (%struct.Option*)*** %4
%41 = getelementptr inbounds void (%struct.Option*)*, void (%struct.Option*)** %40, i32 1
store void (%struct.Option*)** %41, void (%struct.Option*)*** %4
%42 = load void (%struct.Option*)*, void (%struct.Option*)** %40
br label %32
43: ; preds = %32
%44 = load i32*, i32** %3
%45 = call i64 @ferror(i32* %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %43
%48 = load i32, i32* @stderr
%49 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
br label %50
50: ; preds = %47, %43
ret void
}

LLVM IR (-O2):
%struct.Option = type opaque
@stderr = global i32 0
@.str = [50 x i8] c"An error occurred while reading the config file.\0A\00"
define void @read_config(i32* nocapture %0, void (%struct.Option*)** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i64 @fgets(i8* %4, i32 1024, i32* %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %10, label %13
7: ; preds = %17, %13
%8 = call i64 @fgets(i8* %4, i32 1024, i32* %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %7, %2
%11 = load void (%struct.Option*)*, void (%struct.Option*)** %1
%12 = icmp eq void (%struct.Option*)* %11, null
br i1 %12, label %29, label %23
13: ; preds = %2, %7
%14 = call %struct.Option* @parse_opt_line(i8* %4)
%15 = load void (%struct.Option*)*, void (%struct.Option*)** %1
%16 = icmp eq void (%struct.Option*)* %15, null
br i1 %16, label %7, label %17
17: ; preds = %13, %17
%18 = phi void (%struct.Option*)* [ %21, %17 ], [ %15, %13 ]
%19 = phi void (%struct.Option*)** [ %20, %17 ], [ %1, %13 ]
%20 = getelementptr inbounds void (%struct.Option*)*, void (%struct.Option*)** %19, i64 1
%21 = load void (%struct.Option*)*, void (%struct.Option*)** %20
%22 = icmp eq void (%struct.Option*)* %21, null
br i1 %22, label %7, label %17
23: ; preds = %10, %23
%24 = phi void (%struct.Option*)* [ %27, %23 ], [ %11, %10 ]
%25 = phi void (%struct.Option*)** [ %26, %23 ], [ %1, %10 ]
%26 = getelementptr inbounds void (%struct.Option*)*, void (%struct.Option*)** %25, i64 1
%27 = load void (%struct.Option*)*, void (%struct.Option*)** %26
%28 = icmp eq void (%struct.Option*)* %27, null
br i1 %28, label %29, label %23
29: ; preds = %23, %10
%30 = call i64 @ferror(i32* %0)
%31 = icmp eq i64 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %29
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
br label %35
35: ; preds = %32, %29
ret void
}