#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 struct passwd const passwd;

/* Variables and functions */
char *getenv(char *);
struct passwd const *getpwnam(char const *);
struct passwd const *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ getuid();
const struct passwd *get_passwd_info(void) {
  static struct passwd *passwd = NULL;
  if (!passwd) {
    const char *logname = getenv("LOGNAME");
    if (logname) {
      passwd = getpwnam(logname);
    } else {
      passwd = getpwuid(getuid());
    }
  }
  return passwd;
}


x86 assembly (clang, -O0):
<get_passwd_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
cmpq   $0x0,0x2ef8(%rip)
jne    11a0 <get_passwd_info+0x60>
lea    0xea3(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1186 <get_passwd_info+0x46>
mov    -0x8(%rbp),%rdi
call   1060 <getpwnam@plt>
mov    %rax,0x2ec7(%rip)
jmp    119b <get_passwd_info+0x5b>
mov    $0x0,%al
call   1050 <getuid@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
mov    %rax,0x2ead(%rip)
jmp    11a0 <get_passwd_info+0x60>
mov    0x2ea1(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_passwd_info>:
push   %rax
mov    0x2f00(%rip),%rax
test   %rax,%rax
je     114f <get_passwd_info+0xf>
pop    %rcx
ret
lea    0xeaa(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     116a <get_passwd_info+0x2a>
mov    %rax,%rdi
call   1060 <getpwnam@plt>
jmp    1178 <get_passwd_info+0x38>
xor    %eax,%eax
call   1050 <getuid@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
mov    %rax,0x2ec9(%rip)
pop    %rcx
ret

LLVM IR (-O0):
%struct.passwd = type opaque
@get_passwd_info.passwd = internal global %struct.passwd* null
@.str = [8 x i8] c"LOGNAME\00"
define %struct.passwd* @get_passwd_info() {
%1 = alloca i8*
%2 = load %struct.passwd*, %struct.passwd** @get_passwd_info.passwd
%3 = icmp ne %struct.passwd* %2, null
br i1 %3, label %15, label %4
4: ; preds = %0
%5 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %1
%6 = load i8*, i8** %1
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %4
%9 = load i8*, i8** %1
%10 = call %struct.passwd* @getpwnam(i8* %9)
store %struct.passwd* %10, %struct.passwd** @get_passwd_info.passwd
br label %14
11: ; preds = %4
%12 = call i32 (...) @getuid()
%13 = call %struct.passwd* @getpwuid(i32 %12)
store %struct.passwd* %13, %struct.passwd** @get_passwd_info.passwd
br label %14
14: ; preds = %11, %8
br label %15
15: ; preds = %14, %0
%16 = load %struct.passwd*, %struct.passwd** @get_passwd_info.passwd
ret %struct.passwd* %16
}

LLVM IR (-O2):
%struct.passwd = type opaque
@get_passwd_info.passwd = internal unnamed_addr global %struct.passwd* null
@.str = [8 x i8] c"LOGNAME\00"
define %struct.passwd* @get_passwd_info() {
%1 = load %struct.passwd*, %struct.passwd** @get_passwd_info.passwd
%2 = icmp eq %struct.passwd* %1, null
br i1 %2, label %3, label %13
3: ; preds = %0
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call %struct.passwd* @getpwnam(i8* %4)
br label %11
8: ; preds = %3
%9 = tail call i32 (...) @getuid()
%10 = tail call %struct.passwd* @getpwuid(i32 %9)
br label %11
11: ; preds = %8, %6
%12 = phi %struct.passwd* [ %10, %8 ], [ %7, %6 ]
store %struct.passwd* %12, %struct.passwd** @get_passwd_info.passwd
br label %13
13: ; preds = %11, %0
%14 = phi %struct.passwd* [ %12, %11 ], [ %1, %0 ]
ret %struct.passwd* %14
}