#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 int /*<<< orphan*/ uid_t;
struct passwd {
  int /*<<< orphan*/ pw_name;
};

/* Variables and functions */
struct passwd *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ getuid();
int /*<<< orphan*/ snprintf(char *, int, char *, char *, int /*<<< orphan*/);
int yank_filename(char filename[8192]) {
  struct passwd *pwd;
  uid_t u;
  u = getuid();
  if (!(pwd = getpwuid(u)))
    return -1;
  snprintf(filename, 8192, "%s%s", "/tmp/lwe_yank_", pwd->pw_name);
  return 0;
}


x86 assembly (clang, -O0):
<yank_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getuid@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <getpwuid@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1168 <yank_filename+0x38>
movl   $0xffffffff,-0x4(%rbp)
jmp    1192 <yank_filename+0x62>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%r8d
mov    $0x2000,%esi
lea    0xe81(%rip),%rdx
lea    0xe7f(%rip),%rcx
call   1050 <snprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<yank_filename>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <getuid@plt>
mov    %eax,%edi
call   1030 <getpwuid@plt>
test   %rax,%rax
je     116c <yank_filename+0x3c>
mov    (%rax),%r8d
lea    0xeaa(%rip),%rdx
lea    0xea8(%rip),%rcx
mov    %r14,%rdi
mov    $0x2000,%esi
call   1050 <snprintf@plt>
jmp    1171 <yank_filename+0x41>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
%struct.passwd = type { i32 }
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [15 x i8] c"/tmp/lwe_yank_\00"
define i32 @yank_filename(i8* %0) {
%2 = tail call i32 (...) @getuid()
%3 = tail call %struct.passwd* @getpwuid(i32 %2)
%4 = icmp eq %struct.passwd* %3, null
br i1 %4, label %9, label %5
5: ; preds = %1
%6 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 0
%7 = load i32, i32* %6
%8 = tail call i32 @snprintf(i8* %0, i32 8192, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %7)
br label %9
9: ; preds = %1, %5
%10 = phi i32 [ 0, %5 ], [ -1, %1 ]
ret i32 %10
}