#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 *);
struct passwd *getpwuid(scalar_t__);
scalar_t__ getuid();
struct passwd *get_my_pwent() {
  uid_t uid = getuid();
  char *name = getlogin();
  if (name && *name) {
    struct passwd *pw = getpwnam(name);
    if (pw && pw->pw_uid == uid)
      return pw;
  }
  return getpwuid(uid);
}


x86 assembly (clang, -O0):
<get_my_pwent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1040 <getuid@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1060 <getlogin@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11b4 <get_my_pwent+0x74>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11b4 <get_my_pwent+0x74>
mov    -0x18(%rbp),%rdi
call   1050 <getpwnam@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11af <get_my_pwent+0x6f>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
cmp    -0x10(%rbp),%rax
jne    11af <get_my_pwent+0x6f>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11c1 <get_my_pwent+0x81>
jmp    11b4 <get_my_pwent+0x74>
mov    -0x10(%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   %rbx
xor    %eax,%eax
call   1040 <getuid@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1060 <getlogin@plt>
test   %rax,%rax
je     1170 <get_my_pwent+0x30>
cmpb   $0x0,(%rax)
je     1170 <get_my_pwent+0x30>
mov    %rax,%rdi
call   1050 <getpwnam@plt>
test   %rax,%rax
je     1170 <get_my_pwent+0x30>
cmp    %rbx,(%rax)
jne    1170 <get_my_pwent+0x30>
pop    %rbx
ret
mov    %rbx,%rdi
pop    %rbx
jmp    1030 <getpwuid@plt>

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

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