#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_name;
};

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, char *, ...);
const char *home_path(struct passwd *user, const char *path) {
  static char result[512];
  if (path == NULL) {
    snprintf(result, 512, "/home/%s", user->pw_name);
  } else {
    snprintf(result, 512, "/home/%s/%s", user->pw_name, path);
  }
  return result;
}


x86 assembly (clang, -O0):
<home_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1151 <home_path+0x41>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
lea    0x2f07(%rip),%rdi
mov    $0x200,%esi
lea    0xebb(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    1176 <home_path+0x66>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%r8
lea    0x2edd(%rip),%rdi
mov    $0x200,%esi
lea    0xe9a(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
lea    0x2ec3(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<home_path>:
push   %rax
mov    (%rdi),%rcx
test   %rsi,%rsi
je     1138 <home_path+0x28>
mov    %rsi,%r8
lea    0x2f1d(%rip),%rdi
lea    0xedf(%rip),%rdx
mov    $0x200,%esi
xor    %eax,%eax
call   1030 <snprintf@plt>
jmp    1152 <home_path+0x42>
lea    0x2f01(%rip),%rdi
lea    0xeba(%rip),%rdx
mov    $0x200,%esi
xor    %eax,%eax
call   1030 <snprintf@plt>
lea    0x2ee7(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
%struct.passwd = type { i8* }
@home_path.result = internal global [512 x i8] zeroinitializer
@.str = [9 x i8] c"/home/%s\00"
@.str.1 = [12 x i8] c"/home/%s/%s\00"
define i8* @home_path(%struct.passwd* %0, i8* %1) {
%3 = alloca %struct.passwd*
%4 = alloca i8*
store %struct.passwd* %0, %struct.passwd** %3
store i8* %1, i8** %4
%5 = load i8*, i8** %4
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load %struct.passwd*, %struct.passwd** %3
%9 = getelementptr inbounds %struct.passwd, %struct.passwd* %8, i32 0, i32 0
%10 = load i8*, i8** %9
%11 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @home_path.result, i64 0, i64 0), i32 512, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %18
12: ; preds = %2
%13 = load %struct.passwd*, %struct.passwd** %3
%14 = getelementptr inbounds %struct.passwd, %struct.passwd* %13, i32 0, i32 0
%15 = load i8*, i8** %14
%16 = load i8*, i8** %4
%17 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @home_path.result, i64 0, i64 0), i32 512, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %15, i8* %16)
br label %18
18: ; preds = %12, %7
ret i8* getelementptr inbounds ([512 x i8], [512 x i8]* @home_path.result, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.passwd = type { i8* }
@home_path.result = internal global [512 x i8] zeroinitializer
@.str = [9 x i8] c"/home/%s\00"
@.str.1 = [12 x i8] c"/home/%s/%s\00"
define i8* @home_path(%struct.passwd* nocapture %0, i8* %1) {
%3 = icmp eq i8* %1, null
%4 = getelementptr inbounds %struct.passwd, %struct.passwd* %0, i64 0, i32 0
%5 = load i8*, i8** %4
br i1 %3, label %6, label %8
6: ; preds = %2
%7 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @home_path.result, i64 0, i64 0), i32 512, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %10
8: ; preds = %2
%9 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @home_path.result, i64 0, i64 0), i32 512, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %5, i8* %1)
br label %10
10: ; preds = %8, %6
ret i8* getelementptr inbounds ([512 x i8], [512 x i8]* @home_path.result, i64 0, i64 0)
}