#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 scalar_t__ uid_t;
struct passwd {
  char *pw_dir;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
struct passwd *getpwuid(scalar_t__);
scalar_t__ getuid();
char *malloc_wrap(size_t);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, size_t, char *, char *, char *);
int strlen(char *);
int /*<<< orphan*/ vfprintf_diag(char *, unsigned long);
void conf_file_path(char **conf_file) {
  char *path;
  uid_t uid;
  struct passwd *passwd;
  size_t size;
  uid = getuid();
  errno = 0;
  if ((passwd = getpwuid(uid)) == NULL) {
    if (errno == 0)
      vfprintf_diag("password file entry for uid %lu not found",
                    (unsigned long)uid);
    else
      perror("getpwuid");
    exit(EXIT_FAILURE);
  }
  size = strlen(passwd->pw_dir) + 1 + strlen(".colorize.conf") + 1;
  path = malloc_wrap(size);
  snprintf(path, size, "%s/%s", passwd->pw_dir, ".colorize.conf");
  *conf_file = path;
}


x86 assembly (clang, -O0):
<conf_file_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <getuid@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e42(%rip),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
call   1030 <getpwuid@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11fc <conf_file_path+0x7c>
mov    0x2e1d(%rip),%rax
cmpq   $0x0,(%rax)
jne    11e2 <conf_file_path+0x62>
mov    -0x18(%rbp),%rsi
lea    0xe28(%rip),%rdi
call   1080 <vfprintf_diag@plt>
jmp    11ee <conf_file_path+0x6e>
lea    0xe41(%rip),%rdi
call   1090 <perror@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
lea    0xe1e(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <malloc_wrap@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
lea    0xdf5(%rip),%rdx
lea    0xddf(%rip),%r8
call   1060 <snprintf@plt>
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<conf_file_path>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <getuid@plt>
mov    %rax,%r15
mov    0x2e43(%rip),%rbx
movq   $0x0,(%rbx)
mov    %rax,%rdi
call   1030 <getpwuid@plt>
test   %rax,%rax
je     1208 <conf_file_path+0x88>
mov    %rax,%r13
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
lea    0xe6d(%rip),%r12
mov    %r12,%rdi
call   1040 <strlen@plt>
add    %r15d,%eax
add    $0x2,%eax
movslq %eax,%rbx
mov    %rbx,%rdi
call   1070 <malloc_wrap@plt>
mov    %rax,%r15
mov    0x0(%r13),%rcx
lea    0xe55(%rip),%rdx
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r12,%r8
call   1060 <snprintf@plt>
mov    %r15,(%r14)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
cmpq   $0x0,(%rbx)
je     1228 <conf_file_path+0xa8>
lea    0xe15(%rip),%rdi
call   1090 <perror@plt>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    0xdd1(%rip),%rdi
mov    %r15,%rsi
call   1080 <vfprintf_diag@plt>
jmp    121a <conf_file_path+0x9a>

LLVM IR (-O0):
%struct.passwd = type { i8* }
@errno = global i64 0
@.str = [42 x i8] c"password file entry for uid %lu not found\00"
@.str.1 = [9 x i8] c"getpwuid\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [15 x i8] c".colorize.conf\00"
@.str.3 = [6 x i8] c"%s/%s\00"
define void @conf_file_path(i8** %0) {
%2 = alloca i8**
%3 = alloca i8*
%4 = alloca i64
%5 = alloca %struct.passwd*
%6 = alloca i64
store i8** %0, i8*** %2
%7 = call i64 (...) @getuid()
store i64 %7, i64* %4
store i64 0, i64* @errno
%8 = load i64, i64* %4
%9 = call %struct.passwd* @getpwuid(i64 %8)
store %struct.passwd* %9, %struct.passwd** %5
%10 = icmp eq %struct.passwd* %9, null
br i1 %10, label %11, label %22
11: ; preds = %1
%12 = load i64, i64* @errno
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i64, i64* %4
%16 = call i32 @vfprintf_diag(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i64 %15)
br label %19
17: ; preds = %11
%18 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %14
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %1
%23 = load %struct.passwd*, %struct.passwd** %5
%24 = getelementptr inbounds %struct.passwd, %struct.passwd* %23, i32 0, i32 0
%25 = load i8*, i8** %24
%26 = call i32 @strlen(i8* %25)
%27 = add nsw i32 %26, 1
%28 = call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%29 = add nsw i32 %27, %28
%30 = add nsw i32 %29, 1
%31 = sext i32 %30 to i64
store i64 %31, i64* %6
%32 = load i64, i64* %6
%33 = call i8* @malloc_wrap(i64 %32)
store i8* %33, i8** %3
%34 = load i8*, i8** %3
%35 = load i64, i64* %6
%36 = load %struct.passwd*, %struct.passwd** %5
%37 = getelementptr inbounds %struct.passwd, %struct.passwd* %36, i32 0, i32 0
%38 = load i8*, i8** %37
%39 = call i32 @snprintf(i8* %34, i64 %35, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %38, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%40 = load i8*, i8** %3
%41 = load i8**, i8*** %2
store i8* %40, i8** %41
ret void
}

LLVM IR (-O2):
%struct.passwd = type { i8* }
@errno = global i64 0
@.str = [42 x i8] c"password file entry for uid %lu not found\00"
@.str.1 = [9 x i8] c"getpwuid\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [15 x i8] c".colorize.conf\00"
@.str.3 = [6 x i8] c"%s/%s\00"
define void @conf_file_path(i8** nocapture writeonly %0) {
%2 = tail call i64 (...) @getuid()
store i64 0, i64* @errno
%3 = tail call %struct.passwd* @getpwuid(i64 %2)
%4 = icmp eq %struct.passwd* %3, null
br i1 %4, label %5, label %15
5: ; preds = %1
%6 = load i64, i64* @errno
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @vfprintf_diag(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i64 %2)
br label %12
10: ; preds = %5
%11 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %8
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %1
%16 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 0
%17 = load i8*, i8** %16
%18 = tail call i32 @strlen(i8* %17)
%19 = tail call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%20 = add i32 %18, 2
%21 = add i32 %20, %19
%22 = sext i32 %21 to i64
%23 = tail call i8* @malloc_wrap(i64 %22)
%24 = load i8*, i8** %16
%25 = tail call i32 @snprintf(i8* %23, i64 %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %24, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i8* %23, i8** %0
ret void
}