#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 {
  int /*<<< orphan*/ pw_dir;
};

/* Variables and functions */
struct passwd *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ getuid();
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, int /*<<< orphan*/, int);
int strmlen(int /*<<< orphan*/);
void getUserPath(char **path) {
  struct passwd *userInformations;
  int len;
  userInformations = getpwuid(getuid());
  len = strmlen(userInformations->pw_dir);
  *path = malloc(++len);
  memcpy(*path, userInformations->pw_dir, len + 1);
}


x86 assembly (clang, -O0):
<getUserPath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <getuid@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1030 <strmlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
add    $0x1,%edi
mov    %edi,-0x14(%rbp)
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
mov    -0x14(%rbp),%edx
add    $0x1,%edx
call   1060 <memcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getUserPath>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <getuid@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
mov    %rax,%r15
mov    (%rax),%edi
call   1030 <strmlen@plt>
mov    %eax,%ebx
lea    0x1(%rbx),%edi
call   1070 <malloc@plt>
mov    %rax,(%r14)
mov    (%r15),%esi
add    $0x2,%ebx
mov    %rax,%rdi
mov    %ebx,%edx
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <memcpy@plt>

LLVM IR (-O0):
%struct.passwd = type { i32 }
define void @getUserPath(i8** %0) {
%2 = alloca i8**
%3 = alloca %struct.passwd*
%4 = alloca i32
store i8** %0, i8*** %2
%5 = call i32 (...) @getuid()
%6 = call %struct.passwd* @getpwuid(i32 %5)
store %struct.passwd* %6, %struct.passwd** %3
%7 = load %struct.passwd*, %struct.passwd** %3
%8 = getelementptr inbounds %struct.passwd, %struct.passwd* %7, i32 0, i32 0
%9 = load i32, i32* %8
%10 = call i32 @strmlen(i32 %9)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = add nsw i32 %11, 1
store i32 %12, i32* %4
%13 = call i8* @malloc(i32 %12)
%14 = load i8**, i8*** %2
store i8* %13, i8** %14
%15 = load i8**, i8*** %2
%16 = load i8*, i8** %15
%17 = load %struct.passwd*, %struct.passwd** %3
%18 = getelementptr inbounds %struct.passwd, %struct.passwd* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
%22 = call i32 @memcpy(i8* %16, i32 %19, i32 %21)
ret void
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
define void @getUserPath(i8** nocapture writeonly %0) {
%2 = tail call i32 (...) @getuid()
%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 @strmlen(i32 %5)
%7 = add nsw i32 %6, 1
%8 = tail call i8* @malloc(i32 %7)
store i8* %8, i8** %0
%9 = load i32, i32* %4
%10 = add nsw i32 %6, 2
%11 = tail call i32 @memcpy(i8* %8, i32 %9, i32 %10)
ret void
}