#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 *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char toupper(char);
char *standardname(void) {
  char *tmp;
  static char name[40];
  tmp = getenv("USER");
  if (tmp == NULL)
    tmp = getenv("LOGNAME");
  if (tmp == NULL)
    name[0] = 0;
  else {
    strncpy(name, tmp, 39);
    name[39] = 0;
    name[0] = toupper(name[0]);
  }
  return (name);
}


x86 assembly (clang, -O0):
<standardname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1163 <standardname+0x33>
lea    0xeab(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    117a <standardname+0x4a>
movb   $0x0,0x2edb(%rip)
jmp    11a8 <standardname+0x78>
mov    -0x8(%rbp),%rsi
lea    0x2ecb(%rip),%rdi
mov    $0x27,%edx
call   1040 <strncpy@plt>
movb   $0x0,0x2ee1(%rip)
movsbl 0x2eb3(%rip),%edi
call   1050 <toupper@plt>
mov    %al,0x2ea8(%rip)
lea    0x2ea1(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<standardname>:
push   %rax
lea    0xec8(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    1153 <standardname+0x23>
lea    0xebc(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1189 <standardname+0x59>
lea    0x2ef6(%rip),%rdi
mov    %rax,%rsi
mov    $0x27,%edx
call   1040 <strncpy@plt>
movb   $0x0,0x2f09(%rip)
movsbl 0x2edb(%rip),%edi
call   1050 <toupper@plt>
mov    %al,0x2ed0(%rip)
lea    0x2ec9(%rip),%rax
pop    %rcx
ret
xor    %eax,%eax
jmp    117a <standardname+0x4a>

LLVM IR (-O0):
@standardname.name = internal global [40 x i8] zeroinitializer
@.str = [5 x i8] c"USER\00"
@.str.1 = [8 x i8] c"LOGNAME\00"
define i8* @standardname() {
%1 = alloca i8*
%2 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %2, i8** %1
%3 = load i8*, i8** %1
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i8* %6, i8** %1
br label %7
7: ; preds = %5, %0
%8 = load i8*, i8** %1
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %7
store i8 0, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @standardname.name, i64 0, i64 0)
br label %16
11: ; preds = %7
%12 = load i8*, i8** %1
%13 = call i32 @strncpy(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @standardname.name, i64 0, i64 0), i8* %12, i32 39)
store i8 0, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @standardname.name, i64 0, i64 39)
%14 = load i8, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @standardname.name, i64 0, i64 0)
%15 = call signext i8 @toupper(i8 signext %14)
store i8 %15, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @standardname.name, i64 0, i64 0)
br label %16
16: ; preds = %11, %10
ret i8* getelementptr inbounds ([40 x i8], [40 x i8]* @standardname.name, i64 0, i64 0)
}

LLVM IR (-O2):
@standardname.name = internal global [40 x i8] zeroinitializer
@.str = [5 x i8] c"USER\00"
@.str.1 = [8 x i8] c"LOGNAME\00"
define i8* @standardname() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %11, label %6
6: ; preds = %0, %3
%7 = phi i8* [ %4, %3 ], [ %1, %0 ]
%8 = tail call i32 @strncpy(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @standardname.name, i64 0, i64 0), i8* %7, i32 39)
store i8 0, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @standardname.name, i64 0, i64 39)
%9 = load i8, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @standardname.name, i64 0, i64 0)
%10 = tail call signext i8 @toupper(i8 signext %9)
br label %11
11: ; preds = %3, %6
%12 = phi i8 [ %10, %6 ], [ 0, %3 ]
store i8 %12, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @standardname.name, i64 0, i64 0)
ret i8* getelementptr inbounds ([40 x i8], [40 x i8]* @standardname.name, i64 0, i64 0)
}