#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 */

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int R_OK;
int W_OK;
int /*<<< orphan*/ change_dir(char *);
int /*<<< orphan*/ check_file_dir(char *, int);
char *easy_printf(char *, scalar_t__, char *, char *, ...);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char *getenv(char *);
int /*<<< orphan*/ make_dir(char *, int);
scalar_t__ strlen(char *);
int /*<<< orphan*/ write_error(char *);
char *change_config_dir() {
  char *dir_name;
  char *conf_xdg_conf = getenv("XDG_CONFIG_HOME");
  if (conf_xdg_conf) {
    dir_name = easy_printf("%s/%s",
                           strlen("%s/%s") + strlen(conf_xdg_conf) +
                               strlen("showiumize/") + 1,
                           conf_xdg_conf, "showiumize/");
  } else {
    write_error("No $XDG_CONFIG_HOME variable, using $HOME/.config instead.");
    char *conf_home = getenv("HOME");
    if (!conf_home) {
      write_error("No home variable set. Exiting.");
      exit(EXIT_FAILURE);
    }
    dir_name = easy_printf("%s/%s%s",
                           strlen("%s/%s%s") + strlen(conf_home) +
                               strlen(".config/") + strlen("showiumize/") + 1,
                           conf_home, ".config/", "showiumize/");
  }
  if (!check_file_dir(dir_name, W_OK | R_OK)) {
    make_dir(dir_name, 0755);
  }
  change_dir(dir_name);
  return dir_name;
}


x86 assembly (clang, -O0):
<change_config_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    0xe71(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1203 <change_config_dir+0x83>
lea    0xe66(%rip),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
lea    0xe45(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rsi
add    %rax,%rsi
add    $0x1,%rsi
mov    -0x10(%rbp),%rdx
lea    0xe24(%rip),%rdi
lea    0xe23(%rip),%rcx
mov    $0x0,%al
call   1050 <easy_printf@plt>
mov    %rax,-0x8(%rbp)
jmp    12c0 <change_config_dir+0x140>
lea    0xe18(%rip),%rdi
call   1070 <write_error@plt>
lea    0xdf5(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1244 <change_config_dir+0xc4>
lea    0xe2c(%rip),%rdi
call   1070 <write_error@plt>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    0xe31(%rip),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
lea    0xe12(%rip),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
lea    0xd8a(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rsi
add    %rax,%rsi
add    $0x1,%rsi
mov    -0x18(%rbp),%rdx
lea    0xdd5(%rip),%rdi
lea    0xdd6(%rip),%rcx
lea    0xd61(%rip),%r8
mov    $0x0,%al
call   1050 <easy_printf@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2d1d(%rip),%rax
mov    (%rax),%esi
mov    0x2cfc(%rip),%rax
or     (%rax),%esi
call   1060 <check_file_dir@plt>
cmp    $0x0,%eax
jne    12f2 <change_config_dir+0x172>
mov    -0x8(%rbp),%rdi
mov    $0x1ed,%esi
call   1080 <make_dir@plt>
mov    -0x8(%rbp),%rdi
call   1090 <change_dir@plt>
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<change_config_dir>:
push   %rbx
lea    0xe78(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11bb <change_config_dir+0x3b>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
lea    0x11(%rax),%rsi
lea    0xe68(%rip),%rdi
lea    0xe67(%rip),%rcx
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <easy_printf@plt>
jmp    1206 <change_config_dir+0x86>
lea    0xe60(%rip),%rdi
call   1070 <write_error@plt>
lea    0xe3d(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1241 <change_config_dir+0xc1>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
lea    0x1b(%rax),%rsi
lea    0xe8e(%rip),%rdi
lea    0xe8f(%rip),%rcx
lea    0xe1a(%rip),%r8
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <easy_printf@plt>
mov    %rax,%rbx
mov    0x2dd8(%rip),%rax
mov    0x2db9(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
call   1060 <check_file_dir@plt>
test   %eax,%eax
jne    1234 <change_config_dir+0xb4>
mov    %rbx,%rdi
mov    $0x1ed,%esi
call   1080 <make_dir@plt>
mov    %rbx,%rdi
call   1090 <change_dir@plt>
mov    %rbx,%rax
pop    %rbx
ret
lea    0xe15(%rip),%rdi
call   1070 <write_error@plt>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"XDG_CONFIG_HOME\00"
@.str.1 = [6 x i8] c"%s/%s\00"
@.str.2 = [12 x i8] c"showiumize/\00"
@.str.3 = [59 x i8] c"No $XDG_CONFIG_HOME variable, using $HOME/.config instead.\00"
@.str.4 = [5 x i8] c"HOME\00"
@.str.5 = [31 x i8] c"No home variable set. Exiting.\00"
@EXIT_FAILURE = global i32 0
@.str.6 = [8 x i8] c"%s/%s%s\00"
@.str.7 = [9 x i8] c".config/\00"
@W_OK = global i32 0
@R_OK = global i32 0
define i8* @change_config_dir() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** %2
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %17
7: ; preds = %0
%8 = call i64 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%9 = load i8*, i8** %2
%10 = call i64 @strlen(i8* %9)
%11 = add nsw i64 %8, %10
%12 = call i64 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%13 = add nsw i64 %11, %12
%14 = add nsw i64 %13, 1
%15 = load i8*, i8** %2
%16 = call i8* (i8*, i64, i8*, i8*, ...) @easy_printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %14, i8* %15, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
store i8* %16, i8** %1
br label %38
17: ; preds = %0
%18 = call i32 @write_error(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0))
%19 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
store i8* %19, i8** %3
%20 = load i8*, i8** %3
%21 = icmp ne i8* %20, null
br i1 %21, label %26, label %22
22: ; preds = %17
%23 = call i32 @write_error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %17
%27 = call i64 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%28 = load i8*, i8** %3
%29 = call i64 @strlen(i8* %28)
%30 = add nsw i64 %27, %29
%31 = call i64 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%32 = add nsw i64 %30, %31
%33 = call i64 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%34 = add nsw i64 %32, %33
%35 = add nsw i64 %34, 1
%36 = load i8*, i8** %3
%37 = call i8* (i8*, i64, i8*, i8*, ...) @easy_printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i64 %35, i8* %36, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
store i8* %37, i8** %1
br label %38
38: ; preds = %26, %7
%39 = load i8*, i8** %1
%40 = load i32, i32* @W_OK
%41 = load i32, i32* @R_OK
%42 = or i32 %40, %41
%43 = call i32 @check_file_dir(i8* %39, i32 %42)
%44 = icmp ne i32 %43, 0
br i1 %44, label %48, label %45
45: ; preds = %38
%46 = load i8*, i8** %1
%47 = call i32 @make_dir(i8* %46, i32 493)
br label %48
48: ; preds = %45, %38
%49 = load i8*, i8** %1
%50 = call i32 @change_dir(i8* %49)
%51 = load i8*, i8** %1
ret i8* %51
}

LLVM IR (-O2):
@.str = [16 x i8] c"XDG_CONFIG_HOME\00"
@.str.1 = [6 x i8] c"%s/%s\00"
@.str.2 = [12 x i8] c"showiumize/\00"
@.str.3 = [59 x i8] c"No $XDG_CONFIG_HOME variable, using $HOME/.config instead.\00"
@.str.4 = [5 x i8] c"HOME\00"
@.str.5 = [31 x i8] c"No home variable set. Exiting.\00"
@EXIT_FAILURE = global i32 0
@.str.6 = [8 x i8] c"%s/%s%s\00"
@.str.7 = [9 x i8] c".config/\00"
@W_OK = global i32 0
@R_OK = global i32 0
define i8* @change_config_dir() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %7, label %3
3: ; preds = %0
%4 = tail call i64 @strlen(i8* %1)
%5 = add nsw i64 %4, 17
%6 = tail call i8* (i8*, i64, i8*, i8*, ...) @easy_printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %5, i8* %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %19
7: ; preds = %0
%8 = tail call i32 @write_error(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0))
%9 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = tail call i32 @write_error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %7
%16 = tail call i64 @strlen(i8* %9)
%17 = add nsw i64 %16, 27
%18 = tail call i8* (i8*, i64, i8*, i8*, ...) @easy_printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i64 %17, i8* %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %15, %3
%20 = phi i8* [ %6, %3 ], [ %18, %15 ]
%21 = load i32, i32* @W_OK
%22 = load i32, i32* @R_OK
%23 = or i32 %22, %21
%24 = tail call i32 @check_file_dir(i8* %20, i32 %23)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %19
%27 = tail call i32 @make_dir(i8* %20, i32 493)
br label %28
28: ; preds = %26, %19
%29 = tail call i32 @change_dir(i8* %20)
ret i8* %20
}