#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;
  char *pw_dir;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ free(char *);
int get_user_cfgfile_path(char *, char *, struct passwd *, char **);
scalar_t__ strcmp(char *, char *);
void test_get_user_cfgfile_path(void) {
  char *file;
  struct passwd user;
  int ret;
  user.pw_name = "root";
  user.pw_dir = "/root";
  ret = get_user_cfgfile_path("/foo/bar", "test", &user, &file);
  assert(ret == 1);
  assert(strcmp(file, "/foo/bar/test") == 0);
  free(file);
  ret = get_user_cfgfile_path(NULL, "test", &user, &file);
  assert(ret == 1);
  assert(strcmp(file, "/root/.yubico/test") == 0);
  free(file);
}


x86 assembly (clang, -O0):
<test_get_user_cfgfile_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb2(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xea6(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xea1(%rip),%rdi
lea    0xebf(%rip),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x8(%rbp),%rcx
call   1060 <get_user_cfgfile_path@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
lea    0xe77(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe69(%rip),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x8(%rbp),%rcx
call   1060 <get_user_cfgfile_path@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
lea    0xe2f(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_get_user_cfgfile_path>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xeb1(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xea4(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xe9e(%rip),%rdi
lea    0xebc(%rip),%rbx
lea    0x10(%rsp),%r14
lea    0x8(%rsp),%r15
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
call   1060 <get_user_cfgfile_path@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1050 <assert@plt>
mov    0x8(%rsp),%rdi
lea    0xe6e(%rip),%rsi
call   1040 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
call   1060 <get_user_cfgfile_path@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1050 <assert@plt>
mov    0x8(%rsp),%rdi
lea    0xe35(%rip),%rsi
call   1040 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.passwd = type { i8*, i8* }
@.str = [5 x i8] c"root\00"
@.str.1 = [6 x i8] c"/root\00"
@.str.2 = [9 x i8] c"/foo/bar\00"
@.str.3 = [5 x i8] c"test\00"
@.str.4 = [14 x i8] c"/foo/bar/test\00"
@.str.5 = [19 x i8] c"/root/.yubico/test\00"
define void @test_get_user_cfgfile_path() {
%1 = alloca i8*
%2 = alloca %struct.passwd
%3 = alloca i32
%4 = getelementptr inbounds %struct.passwd, %struct.passwd* %2, i32 0, i32 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %4
%5 = getelementptr inbounds %struct.passwd, %struct.passwd* %2, i32 0, i32 1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %5
%6 = call i32 @get_user_cfgfile_path(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %struct.passwd* %2, i8** %1)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, 1
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i8*, i8** %1
%12 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i8*, i8** %1
%17 = call i32 @free(i8* %16)
%18 = call i32 @get_user_cfgfile_path(i8* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %struct.passwd* %2, i8** %1)
store i32 %18, i32* %3
%19 = load i32, i32* %3
%20 = icmp eq i32 %19, 1
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = load i8*, i8** %1
%24 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = load i8*, i8** %1
%29 = call i32 @free(i8* %28)
ret void
}

LLVM IR (-O2):
%struct.passwd = type { i8*, i8* }
@.str = [5 x i8] c"root\00"
@.str.1 = [6 x i8] c"/root\00"
@.str.2 = [9 x i8] c"/foo/bar\00"
@.str.3 = [5 x i8] c"test\00"
@.str.4 = [14 x i8] c"/foo/bar/test\00"
@.str.5 = [19 x i8] c"/root/.yubico/test\00"
define void @test_get_user_cfgfile_path() {
%1 = alloca i8*
%2 = alloca %struct.passwd
%3 = bitcast i8** %1 to i8*
%4 = bitcast %struct.passwd* %2 to i8*
%5 = getelementptr inbounds %struct.passwd, %struct.passwd* %2, i64 0, i32 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %5
%6 = getelementptr inbounds %struct.passwd, %struct.passwd* %2, i64 0, i32 1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %6
%7 = call i32 @get_user_cfgfile_path(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %struct.passwd* %2, i8** %1)
%8 = icmp eq i32 %7, 1
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i8*, i8** %1
%12 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i8*, i8** %1
%17 = call i32 @free(i8* %16)
%18 = call i32 @get_user_cfgfile_path(i8* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %struct.passwd* %2, i8** %1)
%19 = icmp eq i32 %18, 1
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load i8*, i8** %1
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = load i8*, i8** %1
%28 = call i32 @free(i8* %27)
ret void
}