#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 */
struct passwd {
  char *pw_name;
};
struct Settings {
  int dummy;
};

/* Variables and functions */
char *calloc(int, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ geteuid();
struct passwd *getpwuid(int /*<<< orphan*/);
char *load_config(char *);
int /*<<< orphan*/ parse_config(struct Settings *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ write_default_config(char *);
int load_init_config(struct Settings *settings) {
  struct passwd *pws = getpwuid(geteuid());
  int pathlen = 8 + strlen(".yaw") + strlen(pws->pw_name);
  char *path = calloc(pathlen, sizeof(char));
  strcpy(path, "/home/");
  strcat(path, pws->pw_name);
  strcat(path, "/");
  strcat(path, ".yaw");
  char *cfg;
  int i;
  for (i = 0; (cfg = load_config(path)) == NULL; i++) {
    write_default_config(path);
    if (i >= 3) {
      parse_config(settings, "usetabs 1\ntabsize 8\nlinnums 1\nbufexpg 0\n");
      return -1;
    }
  }
  parse_config(settings, cfg);
  free(cfg);
  free(path);
  return 0;
}


x86 assembly (clang, -O0):
<load_init_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <geteuid@plt>
mov    %eax,%edi
call   1050 <getpwuid@plt>
mov    %rax,-0x18(%rbp)
lea    0xe3b(%rip),%rdi
call   1060 <strlen@plt>
add    $0x8,%eax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x1,%esi
call   1090 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe03(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
call   10b0 <strcat@plt>
mov    -0x28(%rbp),%rdi
lea    0xde8(%rip),%rsi
call   10b0 <strcat@plt>
mov    -0x28(%rbp),%rdi
lea    0xdce(%rip),%rsi
call   10b0 <strcat@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x28(%rbp),%rdi
call   10c0 <load_config@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1297 <load_init_config+0xf7>
mov    -0x28(%rbp),%rdi
call   1080 <write_default_config@plt>
cmpl   $0x3,-0x34(%rbp)
jl     1284 <load_init_config+0xe4>
mov    -0x10(%rbp),%rdi
lea    0xd99(%rip),%rsi
call   10a0 <parse_config@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12bd <load_init_config+0x11d>
jmp    1289 <load_init_config+0xe9>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    123e <load_init_config+0x9e>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   10a0 <parse_config@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_init_config>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r15
xor    %r14d,%r14d
xor    %eax,%eax
call   1070 <geteuid@plt>
mov    %eax,%edi
call   1050 <getpwuid@plt>
mov    %rax,%rbx
lea    0xe3a(%rip),%r12
mov    %r12,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    (%rbx),%rdi
call   1060 <strlen@plt>
lea    (%rax,%rbp,1),%edi
add    $0x8,%edi
mov    $0x1,%esi
call   1090 <calloc@plt>
mov    %rax,%rbp
lea    0xe13(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
mov    (%rbx),%rsi
mov    %rbp,%rdi
call   10b0 <strcat@plt>
lea    0xdfe(%rip),%rsi
mov    %rbp,%rdi
call   10b0 <strcat@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
call   10b0 <strcat@plt>
mov    %rbp,%rdi
call   10c0 <load_config@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1277 <load_init_config+0xd7>
mov    %rbp,%rdi
call   1080 <write_default_config@plt>
mov    %rbp,%rdi
call   10c0 <load_config@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1277 <load_init_config+0xd7>
mov    %rbp,%rdi
call   1080 <write_default_config@plt>
mov    %rbp,%rdi
call   10c0 <load_config@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1277 <load_init_config+0xd7>
mov    %rbp,%rdi
call   1080 <write_default_config@plt>
mov    %rbp,%rdi
call   10c0 <load_config@plt>
mov    %rax,%rbx
test   %rax,%rax
je     129e <load_init_config+0xfe>
mov    %r15,%rdi
mov    %rbx,%rsi
call   10a0 <parse_config@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbp,%rdi
call   1080 <write_default_config@plt>
lea    0xd5f(%rip),%rsi
mov    %r15,%rdi
call   10a0 <parse_config@plt>
mov    $0xffffffff,%r14d
jmp    1292 <load_init_config+0xf2>

LLVM IR (-O0):
%struct.Settings = type { i32 }
%struct.passwd = type { i8* }
@.str = [5 x i8] c".yaw\00"
@.str.1 = [7 x i8] c"/home/\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [41 x i8] c"usetabs 1\0Atabsize 8\0Alinnums 1\0Abufexpg 0\0A\00"
define i32 @load_init_config(%struct.Settings* %0) {
%2 = alloca i32
%3 = alloca %struct.Settings*
%4 = alloca %struct.passwd*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store %struct.Settings* %0, %struct.Settings** %3
%9 = call i32 (...) @geteuid()
%10 = call %struct.passwd* @getpwuid(i32 %9)
store %struct.passwd* %10, %struct.passwd** %4
%11 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%12 = add nsw i32 8, %11
%13 = load %struct.passwd*, %struct.passwd** %4
%14 = getelementptr inbounds %struct.passwd, %struct.passwd* %13, i32 0, i32 0
%15 = load i8*, i8** %14
%16 = call i32 @strlen(i8* %15)
%17 = add nsw i32 %12, %16
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = call i8* @calloc(i32 %18, i32 1)
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%22 = load i8*, i8** %6
%23 = load %struct.passwd*, %struct.passwd** %4
%24 = getelementptr inbounds %struct.passwd, %struct.passwd* %23, i32 0, i32 0
%25 = load i8*, i8** %24
%26 = call i32 @strcat(i8* %22, i8* %25)
%27 = load i8*, i8** %6
%28 = call i32 @strcat(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%29 = load i8*, i8** %6
%30 = call i32 @strcat(i8* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %8
br label %31
31: ; preds = %44, %1
%32 = load i8*, i8** %6
%33 = call i8* @load_config(i8* %32)
store i8* %33, i8** %7
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %47
35: ; preds = %31
%36 = load i8*, i8** %6
%37 = call i32 @write_default_config(i8* %36)
%38 = load i32, i32* %8
%39 = icmp sge i32 %38, 3
br i1 %39, label %40, label %43
40: ; preds = %35
%41 = load %struct.Settings*, %struct.Settings** %3
%42 = call i32 @parse_config(%struct.Settings* %41, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %2
br label %55
43: ; preds = %35
br label %44
44: ; preds = %43
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 1
store i32 %46, i32* %8
br label %31
47: ; preds = %31
%48 = load %struct.Settings*, %struct.Settings** %3
%49 = load i8*, i8** %7
%50 = call i32 @parse_config(%struct.Settings* %48, i8* %49)
%51 = load i8*, i8** %7
%52 = call i32 @free(i8* %51)
%53 = load i8*, i8** %6
%54 = call i32 @free(i8* %53)
store i32 0, i32* %2
br label %55
55: ; preds = %47, %40
%56 = load i32, i32* %2
ret i32 %56
}

LLVM IR (-O2):
%struct.Settings = type { i32 }
%struct.passwd = type { i8* }
@.str = [5 x i8] c".yaw\00"
@.str.1 = [7 x i8] c"/home/\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [41 x i8] c"usetabs 1\0Atabsize 8\0Alinnums 1\0Abufexpg 0\0A\00"
define i32 @load_init_config(%struct.Settings* %0) {
%2 = tail call i32 (...) @geteuid()
%3 = tail call %struct.passwd* @getpwuid(i32 %2)
%4 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%5 = add nsw i32 %4, 8
%6 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 0
%7 = load i8*, i8** %6
%8 = tail call i32 @strlen(i8* %7)
%9 = add nsw i32 %5, %8
%10 = tail call i8* @calloc(i32 %9, i32 1)
%11 = tail call i32 @strcpy(i8* %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%12 = load i8*, i8** %6
%13 = tail call i32 @strcat(i8* %10, i8* %12)
%14 = tail call i32 @strcat(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i32 @strcat(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%16 = tail call i8* @load_config(i8* %10)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %33
18: ; preds = %1
%19 = tail call i32 @write_default_config(i8* %10)
%20 = tail call i8* @load_config(i8* %10)
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %33
22: ; preds = %18
%23 = tail call i32 @write_default_config(i8* %10)
%24 = tail call i8* @load_config(i8* %10)
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %33
26: ; preds = %22
%27 = tail call i32 @write_default_config(i8* %10)
%28 = tail call i8* @load_config(i8* %10)
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = tail call i32 @write_default_config(i8* %10)
%32 = tail call i32 @parse_config(%struct.Settings* %0, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
br label %38
33: ; preds = %18, %22, %26, %1
%34 = phi i8* [ %16, %1 ], [ %20, %18 ], [ %24, %22 ], [ %28, %26 ]
%35 = tail call i32 @parse_config(%struct.Settings* %0, i8* %34)
%36 = tail call i32 @free(i8* %34)
%37 = tail call i32 @free(i8* %10)
br label %38
38: ; preds = %33, %30
%39 = phi i32 [ -1, %30 ], [ 0, %33 ]
ret i32 %39
}