#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 */
int /*<<< orphan*/ geteuid();
struct passwd *getpwuid(int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
int strlen(int /*<<< orphan*/);
void set_username(char **user) {
  struct passwd *pw;
  uid_t uid;
  uid = geteuid();
  pw = getpwuid(uid);
  *user = malloc(sizeof(char) * strlen(pw->pw_name));
  strcpy(*user, pw->pw_name);
}


x86 assembly (clang, -O0):
<set_username>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1060 <geteuid@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <getpwuid@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1050 <strlen@plt>
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
call   1030 <strcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_username>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1060 <geteuid@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
mov    %rax,%rbx
mov    (%rax),%edi
call   1050 <strlen@plt>
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,(%r14)
mov    (%rbx),%esi
mov    %rax,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
%struct.passwd = type { i32 }
define void @set_username(i8** %0) {
%2 = alloca i8**
%3 = alloca %struct.passwd*
%4 = alloca i32
store i8** %0, i8*** %2
%5 = call i32 (...) @geteuid()
store i32 %5, i32* %4
%6 = load i32, i32* %4
%7 = call %struct.passwd* @getpwuid(i32 %6)
store %struct.passwd* %7, %struct.passwd** %3
%8 = load %struct.passwd*, %struct.passwd** %3
%9 = getelementptr inbounds %struct.passwd, %struct.passwd* %8, i32 0, i32 0
%10 = load i32, i32* %9
%11 = call i32 @strlen(i32 %10)
%12 = sext i32 %11 to i64
%13 = mul i64 1, %12
%14 = trunc i64 %13 to i32
%15 = call i8* @malloc(i32 %14)
%16 = load i8**, i8*** %2
store i8* %15, i8** %16
%17 = load i8**, i8*** %2
%18 = load i8*, i8** %17
%19 = load %struct.passwd*, %struct.passwd** %3
%20 = getelementptr inbounds %struct.passwd, %struct.passwd* %19, i32 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @strcpy(i8* %18, i32 %21)
ret void
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
define void @set_username(i8** nocapture writeonly %0) {
%2 = tail call i32 (...) @geteuid()
%3 = tail call %struct.passwd* @getpwuid(i32 %2)
%4 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 0
%5 = load i32, i32* %4
%6 = tail call i32 @strlen(i32 %5)
%7 = tail call i8* @malloc(i32 %6)
store i8* %7, i8** %0
%8 = load i32, i32* %4
%9 = tail call i32 @strcpy(i8* %7, i32 %8)
ret void
}