#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_dir;
};
typedef int /*<<< orphan*/ s;
typedef int /*<<< orphan*/ cfg_file;

/* Variables and functions */
char *getenv(char *);
scalar_t__ getpwuid_r(int /*<<< orphan*/, struct passwd *, char *, int,
                      struct passwd **);
int /*<<< orphan*/ getuid();
int /*<<< orphan*/ load_config_file(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
void load_personal_config(void) {
  struct passwd passwd;
  struct passwd *pw;
  const char *p;
  char s[384];
  char cfg_file[384];
  p = getenv("HOME");
  if (p == NULL) {
    if (getpwuid_r(getuid(), &passwd, s, sizeof(s), &pw) != 0)
      return;
    p = pw->pw_dir;
  }
  snprintf(cfg_file, sizeof(cfg_file), "%s/.unfit", p);
  load_config_file(cfg_file);
}


x86 assembly (clang, -O0):
<load_personal_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x320,%rsp
lea    0xe9e(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b2 <load_personal_config+0x62>
mov    $0x0,%al
call   1060 <getuid@plt>
mov    %eax,%edi
lea    -0x1a0(%rbp),%rdx
lea    -0x8(%rbp),%rsi
mov    $0x180,%ecx
lea    -0x10(%rbp),%r8
call   1050 <getpwuid_r@plt>
cmp    $0x0,%rax
je     11a7 <load_personal_config+0x57>
jmp    11da <load_personal_config+0x8a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
lea    -0x320(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x180,%esi
lea    0xe3c(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0x320(%rbp),%rdi
call   1040 <load_config_file@plt>
add    $0x320,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_personal_config>:
push   %rbx
sub    $0x310,%rsp
lea    0xea1(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     118f <load_personal_config+0x3f>
lea    0xe95(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x180,%esi
mov    %rax,%rcx
call   1070 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <load_config_file@plt>
jmp    11b7 <load_personal_config+0x67>
xor    %eax,%eax
call   1060 <getuid@plt>
lea    0x8(%rsp),%rsi
lea    0x190(%rsp),%rdx
mov    %rsp,%r8
mov    %eax,%edi
mov    $0x180,%ecx
call   1050 <getpwuid_r@plt>
test   %rax,%rax
je     11c0 <load_personal_config+0x70>
add    $0x310,%rsp
pop    %rbx
ret
mov    (%rsp),%rax
mov    (%rax),%rax
jmp    1169 <load_personal_config+0x19>

LLVM IR (-O0):
%struct.passwd = type { i8* }
@.str = [5 x i8] c"HOME\00"
@.str.1 = [10 x i8] c"%s/.unfit\00"
define void @load_personal_config() {
%1 = alloca %struct.passwd
%2 = alloca %struct.passwd*
%3 = alloca i8*
%4 = alloca [384 x i8]
%5 = alloca [384 x i8]
%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 %19
9: ; preds = %0
%10 = call i32 (...) @getuid()
%11 = getelementptr inbounds [384 x i8], [384 x i8]* %4, i64 0, i64 0
%12 = call i64 @getpwuid_r(i32 %10, %struct.passwd* %1, i8* %11, i32 384, %struct.passwd** %2)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %9
br label %25
15: ; preds = %9
%16 = load %struct.passwd*, %struct.passwd** %2
%17 = getelementptr inbounds %struct.passwd, %struct.passwd* %16, i32 0, i32 0
%18 = load i8*, i8** %17
store i8* %18, i8** %3
br label %19
19: ; preds = %15, %0
%20 = getelementptr inbounds [384 x i8], [384 x i8]* %5, i64 0, i64 0
%21 = load i8*, i8** %3
%22 = call i32 @snprintf(i8* %20, i32 384, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = getelementptr inbounds [384 x i8], [384 x i8]* %5, i64 0, i64 0
%24 = call i32 @load_config_file(i8* %23)
br label %25
25: ; preds = %19, %14
ret void
}

LLVM IR (-O2):
%struct.passwd = type { i8* }
@.str = [5 x i8] c"HOME\00"
@.str.1 = [10 x i8] c"%s/.unfit\00"
define void @load_personal_config() {
%1 = alloca %struct.passwd
%2 = alloca %struct.passwd*
%3 = alloca [384 x i8]
%4 = alloca [384 x i8]
%5 = bitcast %struct.passwd* %1 to i8*
%6 = bitcast %struct.passwd** %2 to i8*
%7 = getelementptr inbounds [384 x i8], [384 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [384 x i8], [384 x i8]* %4, i64 0, i64 0
%9 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %19
11: ; preds = %0
%12 = tail call i32 (...) @getuid()
%13 = call i64 @getpwuid_r(i32 %12, %struct.passwd* %1, i8* %7, i32 384, %struct.passwd** %2)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %11
%16 = load %struct.passwd*, %struct.passwd** %2
%17 = getelementptr inbounds %struct.passwd, %struct.passwd* %16, i64 0, i32 0
%18 = load i8*, i8** %17
br label %19
19: ; preds = %15, %0
%20 = phi i8* [ %18, %15 ], [ %9, %0 ]
%21 = call i32 @snprintf(i8* %8, i32 384, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = call i32 @load_config_file(i8* %8)
br label %23
23: ; preds = %11, %19
ret void
}