#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*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char *find_theme_file(char const *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ interface_fatal(char *, int /*<<< orphan*/);
int parse_theme_line(int, char *, int const);
char *read_line(int /*<<< orphan*/ *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int load_color_theme(const char *name, const int errors_are_fatal) {
  FILE *file;
  char *line;
  int line_num = 0;
  char *theme_file = find_theme_file(name);
  if (!(file = fopen(theme_file, "r"))) {
    if (errors_are_fatal)
      interface_fatal("Can't open theme file: %s", strerror(errno));
    return 0;
  }
  while ((line = read_line(file))) {
    int res;
    line_num++;
    res = parse_theme_line(line_num, line, errors_are_fatal);
    free(line);
    if (!res)
      return 0;
  }
  fclose(file);
  return 1;
}


x86 assembly (clang, -O0):
<load_color_theme>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <find_theme_file@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11f3 <load_color_theme+0x73>
cmpl   $0x0,-0x14(%rbp)
je     11e7 <load_color_theme+0x67>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %eax,%esi
lea    0xe20(%rip),%rdi
call   1050 <interface_fatal@plt>
movl   $0x0,-0x4(%rbp)
jmp    125e <load_color_theme+0xde>
jmp    11f8 <load_color_theme+0x78>
mov    -0x20(%rbp),%rdi
call   1070 <read_line@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     124e <load_color_theme+0xce>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1090 <parse_theme_line@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x3c(%rbp)
jne    1249 <load_color_theme+0xc9>
movl   $0x0,-0x4(%rbp)
jmp    125e <load_color_theme+0xde>
jmp    11f8 <load_color_theme+0x78>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_color_theme>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
call   1060 <find_theme_file@plt>
lea    0xe69(%rip),%rsi
mov    %rax,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11e4 <load_color_theme+0x64>
mov    %rax,%r15
mov    $0x1,%ebp
nopl   0x0(%rax)
mov    %r15,%rdi
call   1070 <read_line@plt>
test   %rax,%rax
je     1209 <load_color_theme+0x89>
mov    %rax,%rbx
mov    %ebp,%edi
mov    %rax,%rsi
mov    %r14d,%edx
call   1090 <parse_theme_line@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x1,%ebp
test   %r12d,%r12d
jne    11b0 <load_color_theme+0x30>
xor    %ebx,%ebx
jmp    1216 <load_color_theme+0x96>
xor    %ebx,%ebx
test   %r14d,%r14d
je     1216 <load_color_theme+0x96>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xe02(%rip),%rdi
mov    %eax,%esi
call   1050 <interface_fatal@plt>
jmp    1216 <load_color_theme+0x96>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [26 x i8] c"Can't open theme file: %s\00"
@errno = global i32 0
define i32 @load_color_theme(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 0, i32* %8
%11 = load i8*, i8** %4
%12 = call i8* @find_theme_file(i8* %11)
store i8* %12, i8** %9
%13 = load i8*, i8** %9
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %6
%15 = icmp ne i32* %14, null
br i1 %15, label %24, label %16
16: ; preds = %2
%17 = load i32, i32* %5
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load i32, i32* @errno
%21 = call i32 @strerror(i32 %20)
%22 = call i32 @interface_fatal(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %19, %16
store i32 0, i32* %3
br label %45
24: ; preds = %2
br label %25
25: ; preds = %41, %24
%26 = load i32*, i32** %6
%27 = call i8* @read_line(i32* %26)
store i8* %27, i8** %7
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %42
29: ; preds = %25
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 1
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = load i8*, i8** %7
%34 = load i32, i32* %5
%35 = call i32 @parse_theme_line(i32 %32, i8* %33, i32 %34)
store i32 %35, i32* %10
%36 = load i8*, i8** %7
%37 = call i32 @free(i8* %36)
%38 = load i32, i32* %10
%39 = icmp ne i32 %38, 0
br i1 %39, label %41, label %40
40: ; preds = %29
store i32 0, i32* %3
br label %45
41: ; preds = %29
br label %25
42: ; preds = %25
%43 = load i32*, i32** %6
%44 = call i32 @fclose(i32* %43)
store i32 1, i32* %3
br label %45
45: ; preds = %42, %40, %23
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [26 x i8] c"Can't open theme file: %s\00"
@errno = global i32 0
define i32 @load_color_theme(i8* %0, i32 %1) {
%3 = tail call i8* @find_theme_file(i8* %0)
%4 = tail call i32* @fopen(i8* %3, 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 %12
6: ; preds = %2
%7 = icmp eq i32 %1, 0
br i1 %7, label %23, label %8
8: ; preds = %6
%9 = load i32, i32* @errno
%10 = tail call i32 @strerror(i32 %9)
%11 = tail call i32 @interface_fatal(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %10)
br label %23
12: ; preds = %2, %16
%13 = phi i32 [ %17, %16 ], [ 0, %2 ]
%14 = tail call i8* @read_line(i32* %4)
%15 = icmp eq i8* %14, null
br i1 %15, label %21, label %16
16: ; preds = %12
%17 = add nuw nsw i32 %13, 1
%18 = tail call i32 @parse_theme_line(i32 %17, i8* %14, i32 %1)
%19 = tail call i32 @free(i8* %14)
%20 = icmp eq i32 %18, 0
br i1 %20, label %23, label %12
21: ; preds = %12
%22 = tail call i32 @fclose(i32* %4)
br label %23
23: ; preds = %16, %6, %8, %21
%24 = phi i32 [ 1, %21 ], [ 0, %8 ], [ 0, %6 ], [ 0, %16 ]
ret i32 %24
}