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

/* Variables and functions */
char *getlogin();
int getlogin_r(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
scalar_t__ strcmp(char *, char *);
char *strerror(int);
int main(void) {
  char *login;
  int errors = 0;
  login = getlogin();
  if (login == NULL)
    puts("getlogin returned NULL, no further tests");
  else {
    char name[1024];
    int ret;
    printf("getlogin returned: `%s'\n", login);
    ret = getlogin_r(name, sizeof(name));
    if (ret == 0) {
      printf("getlogin_r returned: `%s'\n", name);
      if (strcmp(name, login) != 0) {
        puts("Error: getlogin and getlogin_r returned different names");
        ++errors;
      }
    } else {
      printf("Error: getlogin_r returned: %d (%s)\n", ret, strerror(ret));
      ++errors;
    }
  }
  return errors != 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1060 <getlogin@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a0 <main+0x40>
lea    0xe6a(%rip),%rdi
call   1030 <puts@plt>
jmp    125b <main+0xfb>
mov    -0x10(%rbp),%rsi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x420(%rbp),%rdi
mov    $0x400,%esi
call   1070 <getlogin_r@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0x0,-0x424(%rbp)
jne    121f <main+0xbf>
lea    -0x420(%rbp),%rsi
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     121a <main+0xba>
lea    0xe51(%rip),%rdi
call   1030 <puts@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1256 <main+0xf6>
mov    -0x424(%rbp),%eax
mov    %eax,-0x428(%rbp)
mov    -0x424(%rbp),%edi
call   1080 <strerror@plt>
mov    -0x428(%rbp),%esi
mov    %rax,%rdx
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    125b <main+0xfb>
cmpl   $0x0,-0x14(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
xor    %r14d,%r14d
xor    %eax,%eax
call   1060 <getlogin@plt>
test   %rax,%rax
je     11c0 <main+0x60>
mov    %rax,%rbx
lea    0xea5(%rip),%rdi
xor    %r14d,%r14d
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rdi
mov    $0x400,%esi
call   1070 <getlogin_r@plt>
test   %eax,%eax
je     11ce <main+0x6e>
mov    %eax,%ebp
mov    %eax,%edi
call   1080 <strerror@plt>
lea    0xee3(%rip),%rdi
mov    %ebp,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11fe <main+0x9e>
lea    0xe39(%rip),%rdi
call   1030 <puts@plt>
jmp    1204 <main+0xa4>
lea    0xe6d(%rip),%rdi
mov    %rsp,%rbp
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1204 <main+0xa4>
lea    0xe64(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"getlogin returned NULL, no further tests\00"
@.str.1 = [25 x i8] c"getlogin returned: `%s'\0A\00"
@.str.2 = [27 x i8] c"getlogin_r returned: `%s'\0A\00"
@.str.3 = [56 x i8] c"Error: getlogin and getlogin_r returned different names\00"
@.str.4 = [37 x i8] c"Error: getlogin_r returned: %d (%s)\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%6 = call i8* (...) @getlogin()
store i8* %6, i8** %2
%7 = load i8*, i8** %2
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @puts(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %38
11: ; preds = %0
%12 = load i8*, i8** %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%15 = call i32 @getlogin_r(i8* %14, i32 1024)
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %30
18: ; preds = %11
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%22 = load i8*, i8** %2
%23 = call i64 @strcmp(i8* %21, i8* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %18
%26 = call i32 @puts(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0))
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %29
29: ; preds = %25, %18
br label %37
30: ; preds = %11
%31 = load i32, i32* %5
%32 = load i32, i32* %5
%33 = call i8* @strerror(i32 %32)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i32 %31, i8* %33)
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
store i32 %36, i32* %3
br label %37
37: ; preds = %30, %29
br label %38
38: ; preds = %37, %9
%39 = load i32, i32* %3
%40 = icmp ne i32 %39, 0
%41 = zext i1 %40 to i32
ret i32 %41
}

LLVM IR (-O2):
@.str = [41 x i8] c"getlogin returned NULL, no further tests\00"
@.str.1 = [25 x i8] c"getlogin returned: `%s'\0A\00"
@.str.2 = [27 x i8] c"getlogin_r returned: `%s'\0A\00"
@.str.3 = [56 x i8] c"Error: getlogin and getlogin_r returned different names\00"
@.str.4 = [37 x i8] c"Error: getlogin_r returned: %d (%s)\0A\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = tail call i8* (...) @getlogin()
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %22
6: ; preds = %0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%9 = call i32 @getlogin_r(i8* %7, i32 1024)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %6
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%13 = call i64 @strcmp(i8* %7, i8* %2)
%14 = icmp eq i64 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %11
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0))
br label %20
17: ; preds = %6
%18 = tail call i8* @strerror(i32 %9)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i32 %9, i8* %18)
br label %20
20: ; preds = %11, %15, %17
%21 = phi i32 [ 1, %15 ], [ 0, %11 ], [ 1, %17 ]
br label %22
22: ; preds = %20, %4
%23 = phi i32 [ 0, %4 ], [ %21, %20 ]
%24 = icmp ne i32 %23, 0
%25 = zext i1 %24 to i32
ret i32 %25
}