#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 */
char *getenv(char *);
char *malloc(int);
int /*<<< orphan*/ mkdir(char *, int);
int /*<<< orphan*/ print_error(char *);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char const *);
char *get_config_file_name(const char *subdir, const char *base,
                           const char *suffix) {
  char *home = getenv("HOME");
  char *s;
  int n;
  if (!home) {
    print_error("$HOME not defined");
    return NULL;
  }
  n = strlen(home) + strlen("/.clamz/") + strlen(base) + 1;
  if (subdir)
    n += strlen(subdir) + 1;
  if (suffix)
    n += strlen(suffix);
  s = malloc(n * sizeof(char));
  if (!s) {
    print_error("Out of memory");
    return NULL;
  }
  strcpy(s, home);
  strcat(s, "/.clamz");
  mkdir(s, 0775);
  if (subdir) {
    strcat(s, "/");
    strcat(s, subdir);
    mkdir(s, 0775);
  }
  strcat(s, "/");
  strcat(s, base);
  if (suffix)
    strcat(s, suffix);
  return s;
}


x86 assembly (clang, -O0):
<get_config_file_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    0xe75(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b8 <get_config_file_name+0x48>
lea    0xe5f(%rip),%rdi
call   1060 <print_error@plt>
movq   $0x0,-0x8(%rbp)
jmp    12fc <get_config_file_name+0x18c>
mov    -0x28(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x3c(%rbp)
lea    0xe4c(%rip),%rdi
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     120d <get_config_file_name+0x9d>
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
add    $0x1,%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1227 <get_config_file_name+0xb7>
mov    -0x20(%rbp),%rdi
call   1070 <strlen@plt>
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
movslq -0x34(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    125e <get_config_file_name+0xee>
lea    0xdd4(%rip),%rdi
call   1060 <print_error@plt>
movq   $0x0,-0x8(%rbp)
jmp    12fc <get_config_file_name+0x18c>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x30(%rbp),%rdi
lea    0xdb8(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x30(%rbp),%rdi
mov    $0x1fd,%esi
call   1050 <mkdir@plt>
cmpq   $0x0,-0x10(%rbp)
je     12bf <get_config_file_name+0x14f>
mov    -0x30(%rbp),%rdi
lea    0xd7f(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x30(%rbp),%rdi
mov    $0x1fd,%esi
call   1050 <mkdir@plt>
mov    -0x30(%rbp),%rdi
lea    0xd54(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <strcat@plt>
cmpq   $0x0,-0x20(%rbp)
je     12f4 <get_config_file_name+0x184>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_config_file_name>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
lea    0xe75(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1279 <get_config_file_name+0x109>
mov    %rax,%r13
mov    %rax,%rdi
call   1070 <strlen@plt>
mov    %eax,%ebx
lea    0xe6a(%rip),%rdi
call   1070 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1070 <strlen@plt>
add    %ebx,%ebp
lea    (%rax,%rbp,1),%ebx
add    $0x1,%ebx
test   %r12,%r12
je     11d6 <get_config_file_name+0x66>
mov    %r12,%rdi
call   1070 <strlen@plt>
add    %eax,%ebx
add    $0x1,%ebx
test   %r15,%r15
je     11e7 <get_config_file_name+0x77>
mov    %r15,%rdi
call   1070 <strlen@plt>
add    %ebx,%eax
mov    %eax,%ebx
mov    %ebx,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1282 <get_config_file_name+0x112>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
lea    0xe22(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
mov    %rbx,%rdi
mov    $0x1fd,%esi
call   1050 <mkdir@plt>
test   %r12,%r12
je     124d <get_config_file_name+0xdd>
lea    0xdf1(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1090 <strcat@plt>
mov    %rbx,%rdi
mov    $0x1fd,%esi
call   1050 <mkdir@plt>
lea    0xdca(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <strcat@plt>
test   %r15,%r15
je     1290 <get_config_file_name+0x120>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1090 <strcat@plt>
jmp    1290 <get_config_file_name+0x120>
lea    0xd85(%rip),%rdi
jmp    1289 <get_config_file_name+0x119>
lea    0xd97(%rip),%rdi
call   1060 <print_error@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [18 x i8] c"$HOME not defined\00"
@.str.2 = [9 x i8] c"/.clamz/\00"
@.str.3 = [14 x i8] c"Out of memory\00"
@.str.4 = [8 x i8] c"/.clamz\00"
@.str.5 = [2 x i8] c"/\00"
define i8* @get_config_file_name(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%11 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %8
%12 = load i8*, i8** %8
%13 = icmp ne i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %3
%15 = call i32 @print_error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %4
br label %83
16: ; preds = %3
%17 = load i8*, i8** %8
%18 = call i32 @strlen(i8* %17)
%19 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%20 = add nsw i32 %18, %19
%21 = load i8*, i8** %6
%22 = call i32 @strlen(i8* %21)
%23 = add nsw i32 %20, %22
%24 = add nsw i32 %23, 1
store i32 %24, i32* %10
%25 = load i8*, i8** %5
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %33
27: ; preds = %16
%28 = load i8*, i8** %5
%29 = call i32 @strlen(i8* %28)
%30 = add nsw i32 %29, 1
%31 = load i32, i32* %10
%32 = add nsw i32 %31, %30
store i32 %32, i32* %10
br label %33
33: ; preds = %27, %16
%34 = load i8*, i8** %7
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %41
36: ; preds = %33
%37 = load i8*, i8** %7
%38 = call i32 @strlen(i8* %37)
%39 = load i32, i32* %10
%40 = add nsw i32 %39, %38
store i32 %40, i32* %10
br label %41
41: ; preds = %36, %33
%42 = load i32, i32* %10
%43 = sext i32 %42 to i64
%44 = mul i64 %43, 1
%45 = trunc i64 %44 to i32
%46 = call i8* @malloc(i32 %45)
store i8* %46, i8** %9
%47 = load i8*, i8** %9
%48 = icmp ne i8* %47, null
br i1 %48, label %51, label %49
49: ; preds = %41
%50 = call i32 @print_error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
store i8* null, i8** %4
br label %83
51: ; preds = %41
%52 = load i8*, i8** %9
%53 = load i8*, i8** %8
%54 = call i32 @strcpy(i8* %52, i8* %53)
%55 = load i8*, i8** %9
%56 = call i32 @strcat(i8* %55, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%57 = load i8*, i8** %9
%58 = call i32 @mkdir(i8* %57, i32 509)
%59 = load i8*, i8** %5
%60 = icmp ne i8* %59, null
br i1 %60, label %61, label %69
61: ; preds = %51
%62 = load i8*, i8** %9
%63 = call i32 @strcat(i8* %62, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%64 = load i8*, i8** %9
%65 = load i8*, i8** %5
%66 = call i32 @strcat(i8* %64, i8* %65)
%67 = load i8*, i8** %9
%68 = call i32 @mkdir(i8* %67, i32 509)
br label %69
69: ; preds = %61, %51
%70 = load i8*, i8** %9
%71 = call i32 @strcat(i8* %70, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%72 = load i8*, i8** %9
%73 = load i8*, i8** %6
%74 = call i32 @strcat(i8* %72, i8* %73)
%75 = load i8*, i8** %7
%76 = icmp ne i8* %75, null
br i1 %76, label %77, label %81
77: ; preds = %69
%78 = load i8*, i8** %9
%79 = load i8*, i8** %7
%80 = call i32 @strcat(i8* %78, i8* %79)
br label %81
81: ; preds = %77, %69
%82 = load i8*, i8** %9
store i8* %82, i8** %4
br label %83
83: ; preds = %81, %49, %14
%84 = load i8*, i8** %4
ret i8* %84
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [18 x i8] c"$HOME not defined\00"
@.str.2 = [9 x i8] c"/.clamz/\00"
@.str.3 = [14 x i8] c"Out of memory\00"
@.str.4 = [8 x i8] c"/.clamz\00"
@.str.5 = [2 x i8] c"/\00"
define i8* @get_config_file_name(i8* %0, i8* %1, i8* %2) {
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @print_error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %45
8: ; preds = %3
%9 = tail call i32 @strlen(i8* %4)
%10 = tail call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%11 = tail call i32 @strlen(i8* %1)
%12 = add i32 %9, 1
%13 = add i32 %12, %10
%14 = add i32 %13, %11
%15 = icmp eq i8* %0, null
br i1 %15, label %20, label %16
16: ; preds = %8
%17 = tail call i32 @strlen(i8* %0)
%18 = add i32 %14, 1
%19 = add i32 %18, %17
br label %20
20: ; preds = %16, %8
%21 = phi i32 [ %19, %16 ], [ %14, %8 ]
%22 = icmp eq i8* %2, null
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = tail call i32 @strlen(i8* %2)
%25 = add nsw i32 %24, %21
br label %26
26: ; preds = %23, %20
%27 = phi i32 [ %25, %23 ], [ %21, %20 ]
%28 = tail call i8* @malloc(i32 %27)
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = tail call i32 @print_error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %45
32: ; preds = %26
%33 = tail call i32 @strcpy(i8* %28, i8* %4)
%34 = tail call i32 @strcat(i8* %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%35 = tail call i32 @mkdir(i8* %28, i32 509)
br i1 %15, label %40, label %36
36: ; preds = %32
%37 = tail call i32 @strcat(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%38 = tail call i32 @strcat(i8* %28, i8* %0)
%39 = tail call i32 @mkdir(i8* %28, i32 509)
br label %40
40: ; preds = %36, %32
%41 = tail call i32 @strcat(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%42 = tail call i32 @strcat(i8* %28, i8* %1)
br i1 %22, label %45, label %43
43: ; preds = %40
%44 = tail call i32 @strcat(i8* %28, i8* %2)
br label %45
45: ; preds = %40, %43, %30, %6
%46 = phi i8* [ null, %30 ], [ null, %6 ], [ %28, %43 ], [ %28, %40 ]
ret i8* %46
}