#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 {
  char *pw_name;
};

/* Variables and functions */
struct passwd *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ getuid();
char *getmylogin() {
  char *nobody_str = "nobody";
  uid_t myuid = getuid();
  struct passwd *pwp = NULL;
  pwp = getpwuid(myuid);
  if (pwp == NULL || pwp->pw_name == NULL)
    return (nobody_str);
  return (pwp->pw_name);
}


x86 assembly (clang, -O0):
<getmylogin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xed1(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getuid@plt>
mov    %eax,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <getpwuid@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     116a <getmylogin+0x4a>
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1177 <getmylogin+0x57>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1182 <getmylogin+0x62>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getmylogin>:
push   %rax
xor    %eax,%eax
call   1040 <getuid@plt>
mov    %eax,%edi
call   1030 <getpwuid@plt>
test   %rax,%rax
je     1147 <getmylogin+0x27>
mov    (%rax),%rcx
test   %rcx,%rcx
lea    0xebf(%rip),%rax
cmovne %rcx,%rax
pop    %rcx
ret
lea    0xeb2(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
%struct.passwd = type { i8* }
@.str = [7 x i8] c"nobody\00"
define i8* @getmylogin() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.passwd*
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %2
%5 = call i32 (...) @getuid()
store i32 %5, i32* %3
store %struct.passwd* null, %struct.passwd** %4
%6 = load i32, i32* %3
%7 = call %struct.passwd* @getpwuid(i32 %6)
store %struct.passwd* %7, %struct.passwd** %4
%8 = load %struct.passwd*, %struct.passwd** %4
%9 = icmp eq %struct.passwd* %8, null
br i1 %9, label %15, label %10
10: ; preds = %0
%11 = load %struct.passwd*, %struct.passwd** %4
%12 = getelementptr inbounds %struct.passwd, %struct.passwd* %11, i32 0, i32 0
%13 = load i8*, i8** %12
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %10, %0
%16 = load i8*, i8** %2
store i8* %16, i8** %1
br label %21
17: ; preds = %10
%18 = load %struct.passwd*, %struct.passwd** %4
%19 = getelementptr inbounds %struct.passwd, %struct.passwd* %18, i32 0, i32 0
%20 = load i8*, i8** %19
store i8* %20, i8** %1
br label %21
21: ; preds = %17, %15
%22 = load i8*, i8** %1
ret i8* %22
}

LLVM IR (-O2):
%struct.passwd = type { i8* }
@.str = [7 x i8] c"nobody\00"
define i8* @getmylogin() {
%1 = tail call i32 (...) @getuid()
%2 = tail call %struct.passwd* @getpwuid(i32 %1)
%3 = icmp eq %struct.passwd* %2, null
br i1 %3, label %9, label %4
4: ; preds = %0
%5 = getelementptr inbounds %struct.passwd, %struct.passwd* %2, i64 0, i32 0
%6 = load i8*, i8** %5
%7 = icmp eq i8* %6, null
%8 = select i1 %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %6
br label %9
9: ; preds = %4, %0
%10 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), %0 ], [ %8, %4 ]
ret i8* %10
}