#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 */

/* Variables and functions */
char *getenv(char *);
char *getlogin(void) {
  char *s;
  s = getenv("CVSUSER");
  if (s && *s)
    return s;
  s = getenv("USER");
  if (s && *s)
    return s;
  return NULL;
}


x86 assembly (clang, -O0):
<getlogin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xee1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1150 <getlogin+0x40>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1150 <getlogin+0x40>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1190 <getlogin+0x80>
lea    0xeac(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1188 <getlogin+0x78>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1188 <getlogin+0x78>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1190 <getlogin+0x80>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getlogin>:
push   %rax
lea    0xee8(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1129 <getlogin+0x19>
cmpb   $0x0,(%rax)
je     1129 <getlogin+0x19>
pop    %rcx
ret
lea    0xed3(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     113f <getlogin+0x2f>
cmpb   $0x0,(%rax)
jne    1127 <getlogin+0x17>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"CVSUSER\00"
@.str.1 = [5 x i8] c"USER\00"
define i8* @getlogin() {
%1 = alloca i8*
%2 = alloca i8*
%3 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i8* %3, i8** %2
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %6, label %13
6: ; preds = %0
%7 = load i8*, i8** %2
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = load i8*, i8** %2
store i8* %12, i8** %1
br label %25
13: ; preds = %6, %0
%14 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %14, i8** %2
%15 = load i8*, i8** %2
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %24
17: ; preds = %13
%18 = load i8*, i8** %2
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = load i8*, i8** %2
store i8* %23, i8** %1
br label %25
24: ; preds = %17, %13
store i8* null, i8** %1
br label %25
25: ; preds = %24, %22, %11
%26 = load i8*, i8** %1
ret i8* %26
}

LLVM IR (-O2):
@.str = [8 x i8] c"CVSUSER\00"
@.str.1 = [5 x i8] c"USER\00"
define i8* @getlogin() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %6, label %3
3: ; preds = %0
%4 = load i8, i8* %1
%5 = icmp eq i8 %4, 0
br i1 %5, label %6, label %13
6: ; preds = %3, %0
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = load i8, i8* %7
%11 = icmp eq i8 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %9, %6
br label %13
13: ; preds = %9, %3, %12
%14 = phi i8* [ null, %12 ], [ %1, %3 ], [ %7, %9 ]
ret i8* %14
}