#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;
};

/* Variables and functions */
char *getlogin();
struct passwd *getpwnam(char const *);
struct passwd *getpwuid(scalar_t__);
scalar_t__ getuid();
struct passwd *get_my_pwent(void) {
  struct passwd *pw;
  const char *cp = getlogin();
  uid_t ruid = getuid();
  if (cp && *cp && (pw = getpwnam(cp)) && pw->pw_uid == ruid)
    return pw;
  return getpwuid(ruid);
}


x86 assembly (clang, -O0):
<get_my_pwent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1060 <getlogin@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <getuid@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ae <get_my_pwent+0x6e>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ae <get_my_pwent+0x6e>
mov    -0x18(%rbp),%rdi
call   1050 <getpwnam@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11ae <get_my_pwent+0x6e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
cmp    -0x20(%rbp),%rax
jne    11ae <get_my_pwent+0x6e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11bb <get_my_pwent+0x7b>
mov    -0x20(%rbp),%rdi
call   1030 <getpwuid@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_my_pwent>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <getlogin@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <getuid@plt>
mov    %rax,%r14
test   %rbx,%rbx
je     117c <get_my_pwent+0x3c>
cmpb   $0x0,(%rbx)
je     117c <get_my_pwent+0x3c>
mov    %rbx,%rdi
call   1050 <getpwnam@plt>
test   %rax,%rax
je     117c <get_my_pwent+0x3c>
cmp    %r14,(%rax)
jne    117c <get_my_pwent+0x3c>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <getpwuid@plt>

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

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