#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 scalar_t__ uid_t;
struct passwd {
  scalar_t__ pw_uid;
  char *pw_dir;
};

/* Variables and functions */
int /*<<< orphan*/ endpwent();
struct passwd *getpwent();
scalar_t__ getuid();
char *getudir() {
  struct passwd *upwent;
  uid_t uid;
  uid = getuid();
  if ((upwent = getpwent())) {
    while (upwent->pw_uid != uid) {
      if (!(upwent = getpwent())) {
        return NULL;
      }
    }
    endpwent();
    return upwent->pw_dir;
  }
  endpwent();
  return NULL;
}


x86 assembly (clang, -O0):
<getudir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <getpwent@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11ad <getudir+0x7d>
jmp    115d <getudir+0x2d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
cmp    -0x18(%rbp),%rax
je     1195 <getudir+0x65>
mov    $0x0,%al
call   1040 <getpwent@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1190 <getudir+0x60>
movq   $0x0,-0x8(%rbp)
jmp    11bc <getudir+0x8c>
jmp    115d <getudir+0x2d>
mov    $0x0,%al
call   1050 <endpwent@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11bc <getudir+0x8c>
mov    $0x0,%al
call   1050 <endpwent@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getudir>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
call   1030 <getuid@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1040 <getpwent@plt>
test   %rax,%rax
je     1176 <getudir+0x46>
mov    %rax,%rbx
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    %r15,(%rbx)
je     1182 <getudir+0x52>
xor    %eax,%eax
call   1040 <getpwent@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1160 <getudir+0x30>
jmp    118d <getudir+0x5d>
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <endpwent@plt>
jmp    118d <getudir+0x5d>
xor    %eax,%eax
call   1050 <endpwent@plt>
mov    0x8(%rbx),%r14
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.passwd = type { i64, i8* }
define i8* @getudir() {
%1 = alloca i8*
%2 = alloca %struct.passwd*
%3 = alloca i64
%4 = call i64 (...) @getuid()
store i64 %4, i64* %3
%5 = call %struct.passwd* (...) @getpwent()
store %struct.passwd* %5, %struct.passwd** %2
%6 = icmp ne %struct.passwd* %5, null
br i1 %6, label %7, label %24
7: ; preds = %0
br label %8
8: ; preds = %18, %7
%9 = load %struct.passwd*, %struct.passwd** %2
%10 = getelementptr inbounds %struct.passwd, %struct.passwd* %9, i32 0, i32 0
%11 = load i64, i64* %10
%12 = load i64, i64* %3
%13 = icmp ne i64 %11, %12
br i1 %13, label %14, label %19
14: ; preds = %8
%15 = call %struct.passwd* (...) @getpwent()
store %struct.passwd* %15, %struct.passwd** %2
%16 = icmp ne %struct.passwd* %15, null
br i1 %16, label %18, label %17
17: ; preds = %14
store i8* null, i8** %1
br label %26
18: ; preds = %14
br label %8
19: ; preds = %8
%20 = call i32 (...) @endpwent()
%21 = load %struct.passwd*, %struct.passwd** %2
%22 = getelementptr inbounds %struct.passwd, %struct.passwd* %21, i32 0, i32 1
%23 = load i8*, i8** %22
store i8* %23, i8** %1
br label %26
24: ; preds = %0
%25 = call i32 (...) @endpwent()
store i8* null, i8** %1
br label %26
26: ; preds = %24, %19, %17
%27 = load i8*, i8** %1
ret i8* %27
}

LLVM IR (-O2):
%struct.passwd = type { i64, i8* }
define i8* @getudir() {
%1 = tail call i64 (...) @getuid()
%2 = tail call %struct.passwd* (...) @getpwent()
%3 = icmp eq %struct.passwd* %2, null
br i1 %3, label %16, label %4
4: ; preds = %0, %9
%5 = phi %struct.passwd* [ %10, %9 ], [ %2, %0 ]
%6 = getelementptr inbounds %struct.passwd, %struct.passwd* %5, i64 0, i32 0
%7 = load i64, i64* %6
%8 = icmp eq i64 %7, %1
br i1 %8, label %12, label %9
9: ; preds = %4
%10 = tail call %struct.passwd* (...) @getpwent()
%11 = icmp eq %struct.passwd* %10, null
br i1 %11, label %18, label %4
12: ; preds = %4
%13 = tail call i32 (...) @endpwent()
%14 = getelementptr inbounds %struct.passwd, %struct.passwd* %5, i64 0, i32 1
%15 = load i8*, i8** %14
br label %18
16: ; preds = %0
%17 = tail call i32 (...) @endpwent()
br label %18
18: ; preds = %9, %16, %12
%19 = phi i8* [ %15, %12 ], [ null, %16 ], [ null, %9 ]
ret i8* %19
}