#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  char *pw_dir;
};

/* Variables and functions */
scalar_t__ EEXIST;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ free(void *);
char *getenv(char *);
TYPE_1__ *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ getuid();
scalar_t__ mkdir(char const *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
void *strdup_printf(char *, char const *);
void config_file_init(char **configfile) {
  const char *homedir;
  const char *configdir;
  int fd;
  homedir = getenv("HOME");
  if (homedir == NULL) {
    homedir = getpwuid(getuid())->pw_dir;
  }
  configdir = getenv("XDG_CONFIG_HOME");
  if (configdir == NULL) {
    configdir = strdup_printf("%s/.config", homedir);
    if (mkdir(configdir, 0755) != 0 && errno != EEXIST) {
      perror("mkdir");
      fprintf(stderr, "cannot create %s\n", configdir);
      exit(1);
    }
    free((void *)configdir);
    configdir = strdup_printf("%s/.config/mediafire-tools", homedir);
  } else {
    if (mkdir(configdir, 0755) != 0 && errno != EEXIST) {
      perror("mkdir");
      fprintf(stderr, "cannot create %s\n", configdir);
      exit(1);
    }
    configdir = strdup_printf("%s/mediafire-tools", configdir);
  }
  if (mkdir(configdir, 0755) != 0 && errno != EEXIST) {
    perror("mkdir");
    fprintf(stderr, "cannot create %s\n", configdir);
    exit(1);
  }
  *configfile = strdup_printf("%s/config", configdir);
  fd = open(*configfile, O_RDONLY);
  if (fd < 0) {
    free(*configfile);
    *configfile = NULL;
  } else {
    close(fd);
  }
  free((void *)configdir);
}


x86 assembly (clang, -O0):
<config_file_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe48(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ec <config_file_init+0x3c>
mov    $0x0,%al
call   1080 <getuid@plt>
mov    %eax,%edi
call   1070 <getpwuid@plt>
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
lea    0xe0d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    129e <config_file_init+0xee>
mov    -0x10(%rbp),%rsi
lea    0xdfe(%rip),%rdi
call   1060 <strdup_printf@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x1ed,%esi
call   1050 <mkdir@plt>
cmp    $0x0,%rax
je     127c <config_file_init+0xcc>
mov    0x2d8e(%rip),%rax
mov    (%rax),%rax
mov    0x2d94(%rip),%rcx
cmp    (%rcx),%rax
je     127c <config_file_init+0xcc>
lea    0xdc7(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdb4(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
mov    -0x10(%rbp),%rsi
lea    0xda3(%rip),%rdi
call   1060 <strdup_printf@plt>
mov    %rax,-0x18(%rbp)
jmp    1313 <config_file_init+0x163>
mov    -0x18(%rbp),%rdi
mov    $0x1ed,%esi
call   1050 <mkdir@plt>
cmp    $0x0,%rax
je     12ff <config_file_init+0x14f>
mov    0x2d0b(%rip),%rax
mov    (%rax),%rax
mov    0x2d11(%rip),%rcx
cmp    (%rcx),%rax
je     12ff <config_file_init+0x14f>
lea    0xd44(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xd31(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x18(%rbp),%rsi
lea    0xd44(%rip),%rdi
call   1060 <strdup_printf@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x1ed,%esi
call   1050 <mkdir@plt>
cmp    $0x0,%rax
je     1374 <config_file_init+0x1c4>
mov    0x2c96(%rip),%rax
mov    (%rax),%rax
mov    0x2c9c(%rip),%rcx
cmp    (%rcx),%rax
je     1374 <config_file_init+0x1c4>
lea    0xccf(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2c78(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xcbc(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x18(%rbp),%rsi
lea    0xce2(%rip),%rdi
call   1060 <strdup_printf@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    0x2c4c(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    13cc <config_file_init+0x21c>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1040 <free@plt>
mov    -0x8(%rbp),%rax
movq   $0x0,(%rax)
jmp    13d4 <config_file_init+0x224>
mov    -0x1c(%rbp),%edi
call   1090 <close@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<config_file_init>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xe4c(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r15
test   %rax,%rax
jne    11dd <config_file_init+0x2d>
xor    %eax,%eax
call   1080 <getuid@plt>
mov    %eax,%edi
call   1070 <getpwuid@plt>
mov    (%rax),%r15
lea    0xe1c(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1229 <config_file_init+0x79>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1ed,%esi
call   1050 <mkdir@plt>
test   %rax,%rax
je     121d <config_file_init+0x6d>
mov    0x2dbe(%rip),%rax
mov    (%rax),%rax
mov    0x2dc4(%rip),%rcx
cmp    (%rcx),%rax
jne    12f5 <config_file_init+0x145>
lea    0xe2a(%rip),%rdi
mov    %rbx,%rsi
jmp    1279 <config_file_init+0xc9>
lea    0xde0(%rip),%rdi
mov    %r15,%rsi
call   1060 <strdup_printf@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1ed,%esi
call   1050 <mkdir@plt>
test   %rax,%rax
je     1267 <config_file_init+0xb7>
mov    0x2d74(%rip),%rax
mov    (%rax),%rax
mov    0x2d7a(%rip),%rcx
cmp    (%rcx),%rax
jne    12f5 <config_file_init+0x145>
mov    %rbx,%rdi
call   1040 <free@plt>
lea    0xdbd(%rip),%rdi
mov    %r15,%rsi
call   1060 <strdup_printf@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1ed,%esi
call   1050 <mkdir@plt>
test   %rax,%rax
je     12a9 <config_file_init+0xf9>
mov    0x2d2e(%rip),%rax
mov    (%rax),%rax
mov    0x2d34(%rip),%rcx
cmp    (%rcx),%rax
jne    12f5 <config_file_init+0x145>
lea    0xdb1(%rip),%rdi
mov    %rbx,%rsi
call   1060 <strdup_printf@plt>
mov    %rax,(%r14)
mov    0x2d26(%rip),%rcx
mov    (%rcx),%esi
mov    %rax,%rdi
call   10b0 <open@plt>
test   %eax,%eax
js     12d9 <config_file_init+0x129>
mov    %eax,%edi
call   1090 <close@plt>
jmp    12e8 <config_file_init+0x138>
mov    (%r14),%rdi
call   1040 <free@plt>
movq   $0x0,(%r14)
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <free@plt>
lea    0xd1f(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2cc8(%rip),%rax
mov    (%rax),%edi
lea    0xd10(%rip),%rsi
mov    %rbx,%rdx
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_2__ = type { i8* }
@.str = [5 x i8] c"HOME\00"
@.str.1 = [16 x i8] c"XDG_CONFIG_HOME\00"
@.str.2 = [11 x i8] c"%s/.config\00"
@errno = global i64 0
@EEXIST = global i64 0
@.str.3 = [6 x i8] c"mkdir\00"
@stderr = global i32 0
@.str.4 = [18 x i8] c"cannot create %s\0A\00"
@.str.5 = [27 x i8] c"%s/.config/mediafire-tools\00"
@.str.6 = [19 x i8] c"%s/mediafire-tools\00"
@.str.7 = [10 x i8] c"%s/config\00"
@O_RDONLY = global i32 0
define void @config_file_init(i8** %0) {
%2 = alloca i8**
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8** %0, i8*** %2
%6 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %14
9: ; preds = %1
%10 = call i32 (...) @getuid()
%11 = call %struct.TYPE_2__* @getpwuid(i32 %10)
%12 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %11, i32 0, i32 0
%13 = load i8*, i8** %12
store i8* %13, i8** %3
br label %14
14: ; preds = %9, %1
%15 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %39
18: ; preds = %14
%19 = load i8*, i8** %3
%20 = call i8* @strdup_printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %19)
store i8* %20, i8** %4
%21 = load i8*, i8** %4
%22 = call i64 @mkdir(i8* %21, i32 493)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %34
24: ; preds = %18
%25 = load i64, i64* @errno
%26 = load i64, i64* @EEXIST
%27 = icmp ne i64 %25, %26
br i1 %27, label %28, label %34
28: ; preds = %24
%29 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %4
%32 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %31)
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %24, %18
%35 = load i8*, i8** %4
%36 = call i32 @free(i8* %35)
%37 = load i8*, i8** %3
%38 = call i8* @strdup_printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %37)
store i8* %38, i8** %4
br label %56
39: ; preds = %14
%40 = load i8*, i8** %4
%41 = call i64 @mkdir(i8* %40, i32 493)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %53
43: ; preds = %39
%44 = load i64, i64* @errno
%45 = load i64, i64* @EEXIST
%46 = icmp ne i64 %44, %45
br i1 %46, label %47, label %53
47: ; preds = %43
%48 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%49 = load i32, i32* @stderr
%50 = load i8*, i8** %4
%51 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %50)
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %43, %39
%54 = load i8*, i8** %4
%55 = call i8* @strdup_printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %54)
store i8* %55, i8** %4
br label %56
56: ; preds = %53, %34
%57 = load i8*, i8** %4
%58 = call i64 @mkdir(i8* %57, i32 493)
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %70
60: ; preds = %56
%61 = load i64, i64* @errno
%62 = load i64, i64* @EEXIST
%63 = icmp ne i64 %61, %62
br i1 %63, label %64, label %70
64: ; preds = %60
%65 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%66 = load i32, i32* @stderr
%67 = load i8*, i8** %4
%68 = call i32 @fprintf(i32 %66, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %67)
%69 = call i32 @exit(i32 1)
unreachable
70: ; preds = %60, %56
%71 = load i8*, i8** %4
%72 = call i8* @strdup_printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* %71)
%73 = load i8**, i8*** %2
store i8* %72, i8** %73
%74 = load i8**, i8*** %2
%75 = load i8*, i8** %74
%76 = load i32, i32* @O_RDONLY
%77 = call i32 @open(i8* %75, i32 %76)
store i32 %77, i32* %5
%78 = load i32, i32* %5
%79 = icmp slt i32 %78, 0
br i1 %79, label %80, label %85
80: ; preds = %70
%81 = load i8**, i8*** %2
%82 = load i8*, i8** %81
%83 = call i32 @free(i8* %82)
%84 = load i8**, i8*** %2
store i8* null, i8** %84
br label %88
85: ; preds = %70
%86 = load i32, i32* %5
%87 = call i32 @close(i32 %86)
br label %88
88: ; preds = %85, %80
%89 = load i8*, i8** %4
%90 = call i32 @free(i8* %89)
ret void
}

LLVM IR (-O2):
%struct.TYPE_2__ = type { i8* }
@.str = [5 x i8] c"HOME\00"
@.str.1 = [16 x i8] c"XDG_CONFIG_HOME\00"
@.str.2 = [11 x i8] c"%s/.config\00"
@errno = global i64 0
@EEXIST = global i64 0
@.str.3 = [6 x i8] c"mkdir\00"
@stderr = global i32 0
@.str.4 = [18 x i8] c"cannot create %s\0A\00"
@.str.5 = [27 x i8] c"%s/.config/mediafire-tools\00"
@.str.6 = [19 x i8] c"%s/mediafire-tools\00"
@.str.7 = [10 x i8] c"%s/config\00"
@O_RDONLY = global i32 0
define void @config_file_init(i8** nocapture %0) {
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %9
4: ; preds = %1
%5 = tail call i32 (...) @getuid()
%6 = tail call %struct.TYPE_2__* @getpwuid(i32 %5)
%7 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %6, i64 0, i32 0
%8 = load i8*, i8** %7
br label %9
9: ; preds = %4, %1
%10 = phi i8* [ %8, %4 ], [ %2, %1 ]
%11 = tail call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %29
13: ; preds = %9
%14 = tail call i8* @strdup_printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%15 = tail call i64 @mkdir(i8* %14, i32 493)
%16 = icmp eq i64 %15, 0
br i1 %16, label %26, label %17
17: ; preds = %13
%18 = load i64, i64* @errno
%19 = load i64, i64* @EEXIST
%20 = icmp eq i64 %18, %19
br i1 %20, label %26, label %21
21: ; preds = %17
%22 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%23 = load i32, i32* @stderr
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %14)
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %17, %13
%27 = tail call i32 @free(i8* %14)
%28 = tail call i8* @strdup_printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %10)
br label %43
29: ; preds = %9
%30 = tail call i64 @mkdir(i8* %11, i32 493)
%31 = icmp eq i64 %30, 0
br i1 %31, label %41, label %32
32: ; preds = %29
%33 = load i64, i64* @errno
%34 = load i64, i64* @EEXIST
%35 = icmp eq i64 %33, %34
br i1 %35, label %41, label %36
36: ; preds = %32
%37 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%38 = load i32, i32* @stderr
%39 = tail call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %11)
%40 = tail call i32 @exit(i32 1)
unreachable
41: ; preds = %32, %29
%42 = tail call i8* @strdup_printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %11)
br label %43
43: ; preds = %41, %26
%44 = phi i8* [ %28, %26 ], [ %42, %41 ]
%45 = tail call i64 @mkdir(i8* %44, i32 493)
%46 = icmp eq i64 %45, 0
br i1 %46, label %56, label %47
47: ; preds = %43
%48 = load i64, i64* @errno
%49 = load i64, i64* @EEXIST
%50 = icmp eq i64 %48, %49
br i1 %50, label %56, label %51
51: ; preds = %47
%52 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%53 = load i32, i32* @stderr
%54 = tail call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %44)
%55 = tail call i32 @exit(i32 1)
unreachable
56: ; preds = %47, %43
%57 = tail call i8* @strdup_printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* %44)
store i8* %57, i8** %0
%58 = load i32, i32* @O_RDONLY
%59 = tail call i32 @open(i8* %57, i32 %58)
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %56
%62 = load i8*, i8** %0
%63 = tail call i32 @free(i8* %62)
store i8* null, i8** %0
br label %66
64: ; preds = %56
%65 = tail call i32 @close(i32 %59)
br label %66
66: ; preds = %64, %61
%67 = tail call i32 @free(i8* %44)
ret void
}