#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 */
int EXIT_FAILURE;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ getenv(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
char *get_name(void) {
  char *name;
  if ((name = (char *)getenv("NEWNAME")) == NULL)
    if ((name = (char *)getenv("NAME")) == NULL)
      if ((name = (char *)getenv("FULLNAME")) == NULL)
        if ((name = (char *)getenv("USER")) == NULL)
          if ((name = (char *)getenv("LOGNAME")) == NULL) {
            name = (char *)malloc(80);
            if (name == NULL) {
              printf("malloc error\n");
              exit(1);
            }
            printf("Name? ");
            fflush(stdout);
            if (fgets(name, 80, stdin) == NULL) {
              fprintf(stderr, "fgets error\n");
              exit(EXIT_FAILURE);
            }
            if (name[0] == '\0')
              name = "noname";
          }
  return (name);
}


x86 assembly (clang, -O0):
<get_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe81(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    12bb <get_name+0x14b>
lea    0xe80(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    12b6 <get_name+0x146>
lea    0xe55(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    12b1 <get_name+0x141>
lea    0xe44(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    12ac <get_name+0x13c>
lea    0xe2f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    12a7 <get_name+0x137>
mov    $0x50,%edi
call   1070 <malloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1229 <get_name+0xb9>
lea    0xe04(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xdfc(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    -0x8(%rbp),%rdi
mov    0x2d9a(%rip),%rax
mov    (%rax),%edx
mov    $0x50,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
jne    1287 <get_name+0x117>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
lea    0xdbf(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    12a2 <get_name+0x132>
lea    0xda2(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12a7 <get_name+0x137>
jmp    12ac <get_name+0x13c>
jmp    12b1 <get_name+0x141>
jmp    12b6 <get_name+0x146>
jmp    12bb <get_name+0x14b>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_name>:
push   %rbx
lea    0xe78(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1242 <get_name+0xc2>
lea    0xe79(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1242 <get_name+0xc2>
lea    0xe50(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1242 <get_name+0xc2>
lea    0xe45(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1242 <get_name+0xc2>
lea    0xe36(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1242 <get_name+0xc2>
mov    $0x50,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1247 <get_name+0xc7>
mov    %rax,%rbx
lea    0xe18(%rip),%rdi
call   1050 <printf@plt>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x50,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     125d <get_name+0xdd>
cmpb   $0x0,(%rbx)
lea    0xdf4(%rip),%rax
cmove  %rax,%rbx
mov    %rbx,%rax
pop    %rbx
ret
lea    0xdeb(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
lea    0xdb8(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"NEWNAME\00"
@.str.1 = [5 x i8] c"NAME\00"
@.str.2 = [9 x i8] c"FULLNAME\00"
@.str.3 = [5 x i8] c"USER\00"
@.str.4 = [8 x i8] c"LOGNAME\00"
@.str.5 = [14 x i8] c"malloc error\0A\00"
@.str.6 = [7 x i8] c"Name? \00"
@stdout = global i32 0
@stdin = global i32 0
@stderr = global i32 0
@.str.7 = [13 x i8] c"fgets error\0A\00"
@EXIT_FAILURE = global i32 0
@.str.8 = [7 x i8] c"noname\00"
define i8* @get_name() {
%1 = alloca i8*
%2 = call i64 @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%3 = inttoptr i64 %2 to i8*
store i8* %3, i8** %1
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %54
5: ; preds = %0
%6 = call i64 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %1
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %53
9: ; preds = %5
%10 = call i64 @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %1
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %52
13: ; preds = %9
%14 = call i64 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %1
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %51
17: ; preds = %13
%18 = call i64 @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %1
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %50
21: ; preds = %17
%22 = call i64 @malloc(i32 80)
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %1
%24 = load i8*, i8** %1
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %21
%30 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%31 = load i32, i32* @stdout
%32 = call i32 @fflush(i32 %31)
%33 = load i8*, i8** %1
%34 = load i32, i32* @stdin
%35 = call i32* @fgets(i8* %33, i32 80, i32 %34)
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %42
37: ; preds = %29
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %29
%43 = load i8*, i8** %1
%44 = getelementptr inbounds i8, i8* %43, i64 0
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %42
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i8** %1
br label %49
49: ; preds = %48, %42
br label %50
50: ; preds = %49, %17
br label %51
51: ; preds = %50, %13
br label %52
52: ; preds = %51, %9
br label %53
53: ; preds = %52, %5
br label %54
54: ; preds = %53, %0
%55 = load i8*, i8** %1
ret i8* %55
}

LLVM IR (-O2):
@.str = [8 x i8] c"NEWNAME\00"
@.str.1 = [5 x i8] c"NAME\00"
@.str.2 = [9 x i8] c"FULLNAME\00"
@.str.3 = [5 x i8] c"USER\00"
@.str.4 = [8 x i8] c"LOGNAME\00"
@.str.6 = [7 x i8] c"Name? \00"
@stdout = global i32 0
@stdin = global i32 0
@stderr = global i32 0
@.str.7 = [13 x i8] c"fgets error\0A\00"
@EXIT_FAILURE = global i32 0
@.str.8 = [7 x i8] c"noname\00"
@str = [13 x i8] c"malloc error\00"
define i8* @get_name() {
%1 = tail call i64 @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%2 = inttoptr i64 %1 to i8*
%3 = icmp eq i64 %1, 0
br i1 %3, label %4, label %43
4: ; preds = %0
%5 = tail call i64 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%6 = inttoptr i64 %5 to i8*
%7 = icmp eq i64 %5, 0
br i1 %7, label %8, label %43
8: ; preds = %4
%9 = tail call i64 @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%10 = inttoptr i64 %9 to i8*
%11 = icmp eq i64 %9, 0
br i1 %11, label %12, label %43
12: ; preds = %8
%13 = tail call i64 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%14 = inttoptr i64 %13 to i8*
%15 = icmp eq i64 %13, 0
br i1 %15, label %16, label %43
16: ; preds = %12
%17 = tail call i64 @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%18 = inttoptr i64 %17 to i8*
%19 = icmp eq i64 %17, 0
br i1 %19, label %20, label %43
20: ; preds = %16
%21 = tail call i64 @malloc(i32 80)
%22 = inttoptr i64 %21 to i8*
%23 = icmp eq i64 %21, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %20
%28 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%29 = load i32, i32* @stdout
%30 = tail call i32 @fflush(i32 %29)
%31 = load i32, i32* @stdin
%32 = tail call i32* @fgets(i8* %22, i32 80, i32 %31)
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %39
34: ; preds = %27
%35 = load i32, i32* @stderr
%36 = tail call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%37 = load i32, i32* @EXIT_FAILURE
%38 = tail call i32 @exit(i32 %37)
unreachable
39: ; preds = %27
%40 = load i8, i8* %22
%41 = icmp eq i8 %40, 0
%42 = select i1 %41, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i8* %22
br label %43
43: ; preds = %4, %12, %39, %16, %8, %0
%44 = phi i8* [ %42, %39 ], [ %18, %16 ], [ %14, %12 ], [ %10, %8 ], [ %6, %4 ], [ %2, %0 ]
ret i8* %44
}