#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 */
scalar_t__ EFAULT;
scalar_t__ EINVAL;
scalar_t__ EPERM;
int /*<<< orphan*/ assert(int);
scalar_t__ errno;
int /*<<< orphan*/ *getlogin();
scalar_t__ seteuid(int);
int setlogin(char const *);
scalar_t__ strcmp(int /*<<< orphan*/ *, char const *);
int test_session_login_name(void) {
  const char *name = "foo";
  assert(getlogin() == NULL);
  assert(setlogin(name) == 0);
  assert(getlogin() != NULL);
  assert(strcmp(getlogin(), name) == 0);
  assert(setlogin("this_is_a_very_long_name") == -1);
  assert(errno == EINVAL);
  assert(getlogin() != NULL);
  assert(strcmp(getlogin(), name) == 0);
  assert(seteuid(1) == 0);
  assert(setlogin(name) == -1);
  assert(errno == EPERM);
  assert(getlogin() != NULL);
  assert(strcmp(getlogin(), name) == 0);
  assert(seteuid(0) == 0);
  assert(setlogin((void *)1) == -1);
  assert(errno == EFAULT);
  assert(getlogin() != NULL);
  assert(strcmp(getlogin(), name) == 0);
  assert(setlogin("") == 0);
  assert(getlogin() == NULL);
  return 0;
}


x86 assembly (clang, -O0):
<test_session_login_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    $0x0,%al
call   1050 <getlogin@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1060 <setlogin@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    $0x0,%al
call   1050 <getlogin@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    $0x0,%al
call   1050 <getlogin@plt>
mov    %rax,%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xe2d(%rip),%rdi
call   1060 <setlogin@plt>
cmp    $0xffffffff,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%rax
mov    0x2dd3(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    $0x0,%al
call   1050 <getlogin@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    $0x0,%al
call   1050 <getlogin@plt>
mov    %rax,%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    $0x1,%edi
call   1070 <seteuid@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1060 <setlogin@plt>
cmp    $0xffffffff,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2d54(%rip),%rax
mov    (%rax),%rax
mov    0x2d32(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    $0x0,%al
call   1050 <getlogin@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    $0x0,%al
call   1050 <getlogin@plt>
mov    %rax,%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
xor    %edi,%edi
call   1070 <seteuid@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    $0x1,%edi
call   1060 <setlogin@plt>
cmp    $0xffffffff,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2cc5(%rip),%rax
mov    (%rax),%rax
mov    0x2cdb(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    $0x0,%al
call   1050 <getlogin@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    $0x0,%al
call   1050 <getlogin@plt>
mov    %rax,%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xcac(%rip),%rdi
call   1060 <setlogin@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    $0x0,%al
call   1050 <getlogin@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_session_login_name>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <getlogin@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
lea    0xe90(%rip),%rbx
mov    %rbx,%rdi
call   1060 <setlogin@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
xor    %eax,%eax
call   1050 <getlogin@plt>
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1040 <assert@plt>
xor    %eax,%eax
call   1050 <getlogin@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
lea    0xe43(%rip),%rdi
call   1060 <setlogin@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1040 <assert@plt>
mov    0x2dfd(%rip),%r14
mov    (%r14),%rax
mov    0x2deb(%rip),%rcx
xor    %edi,%edi
cmp    (%rcx),%rax
sete   %dil
call   1040 <assert@plt>
xor    %eax,%eax
call   1050 <getlogin@plt>
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1040 <assert@plt>
xor    %eax,%eax
call   1050 <getlogin@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
mov    $0x1,%edi
call   1070 <seteuid@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
call   1060 <setlogin@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1040 <assert@plt>
mov    (%r14),%rax
mov    0x2d60(%rip),%rcx
xor    %edi,%edi
cmp    (%rcx),%rax
sete   %dil
call   1040 <assert@plt>
xor    %eax,%eax
call   1050 <getlogin@plt>
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1040 <assert@plt>
xor    %eax,%eax
call   1050 <getlogin@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
xor    %edi,%edi
call   1070 <seteuid@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
mov    $0x1,%edi
call   1060 <setlogin@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1040 <assert@plt>
mov    (%r14),%rax
mov    0x2d1e(%rip),%rcx
xor    %edi,%edi
cmp    (%rcx),%rax
sete   %dil
call   1040 <assert@plt>
xor    %eax,%eax
call   1050 <getlogin@plt>
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1040 <assert@plt>
xor    %eax,%eax
call   1050 <getlogin@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
lea    0xcf8(%rip),%rdi
call   1060 <setlogin@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
xor    %eax,%eax
call   1050 <getlogin@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"foo\00"
@.str.1 = [25 x i8] c"this_is_a_very_long_name\00"
@errno = global i64 0
@EINVAL = global i64 0
@EPERM = global i64 0
@EFAULT = global i64 0
@.str.2 = [1 x i8] zeroinitializer
define i32 @test_session_login_name() {
%1 = alloca i8*
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %1
%2 = call i32* (...) @getlogin()
%3 = icmp eq i32* %2, null
%4 = zext i1 %3 to i32
%5 = call i32 @assert(i32 %4)
%6 = load i8*, i8** %1
%7 = call i32 @setlogin(i8* %6)
%8 = icmp eq i32 %7, 0
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = call i32* (...) @getlogin()
%12 = icmp ne i32* %11, null
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = call i32* (...) @getlogin()
%16 = load i8*, i8** %1
%17 = call i64 @strcmp(i32* %15, i8* %16)
%18 = icmp eq i64 %17, 0
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = call i32 @setlogin(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i32 %21, -1
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = load i64, i64* @errno
%26 = load i64, i64* @EINVAL
%27 = icmp eq i64 %25, %26
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = call i32* (...) @getlogin()
%31 = icmp ne i32* %30, null
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = call i32* (...) @getlogin()
%35 = load i8*, i8** %1
%36 = call i64 @strcmp(i32* %34, i8* %35)
%37 = icmp eq i64 %36, 0
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
%40 = call i64 @seteuid(i32 1)
%41 = icmp eq i64 %40, 0
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
%44 = load i8*, i8** %1
%45 = call i32 @setlogin(i8* %44)
%46 = icmp eq i32 %45, -1
%47 = zext i1 %46 to i32
%48 = call i32 @assert(i32 %47)
%49 = load i64, i64* @errno
%50 = load i64, i64* @EPERM
%51 = icmp eq i64 %49, %50
%52 = zext i1 %51 to i32
%53 = call i32 @assert(i32 %52)
%54 = call i32* (...) @getlogin()
%55 = icmp ne i32* %54, null
%56 = zext i1 %55 to i32
%57 = call i32 @assert(i32 %56)
%58 = call i32* (...) @getlogin()
%59 = load i8*, i8** %1
%60 = call i64 @strcmp(i32* %58, i8* %59)
%61 = icmp eq i64 %60, 0
%62 = zext i1 %61 to i32
%63 = call i32 @assert(i32 %62)
%64 = call i64 @seteuid(i32 0)
%65 = icmp eq i64 %64, 0
%66 = zext i1 %65 to i32
%67 = call i32 @assert(i32 %66)
%68 = call i32 @setlogin(i8* inttoptr (i64 1 to i8*))
%69 = icmp eq i32 %68, -1
%70 = zext i1 %69 to i32
%71 = call i32 @assert(i32 %70)
%72 = load i64, i64* @errno
%73 = load i64, i64* @EFAULT
%74 = icmp eq i64 %72, %73
%75 = zext i1 %74 to i32
%76 = call i32 @assert(i32 %75)
%77 = call i32* (...) @getlogin()
%78 = icmp ne i32* %77, null
%79 = zext i1 %78 to i32
%80 = call i32 @assert(i32 %79)
%81 = call i32* (...) @getlogin()
%82 = load i8*, i8** %1
%83 = call i64 @strcmp(i32* %81, i8* %82)
%84 = icmp eq i64 %83, 0
%85 = zext i1 %84 to i32
%86 = call i32 @assert(i32 %85)
%87 = call i32 @setlogin(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%88 = icmp eq i32 %87, 0
%89 = zext i1 %88 to i32
%90 = call i32 @assert(i32 %89)
%91 = call i32* (...) @getlogin()
%92 = icmp eq i32* %91, null
%93 = zext i1 %92 to i32
%94 = call i32 @assert(i32 %93)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"foo\00"
@.str.1 = [25 x i8] c"this_is_a_very_long_name\00"
@errno = global i64 0
@EINVAL = global i64 0
@EPERM = global i64 0
@EFAULT = global i64 0
@.str.2 = [1 x i8] zeroinitializer
define i32 @test_session_login_name() {
%1 = tail call i32* (...) @getlogin()
%2 = icmp eq i32* %1, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = tail call i32 @setlogin(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %5, 0
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = tail call i32* (...) @getlogin()
%10 = icmp ne i32* %9, null
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = tail call i32* (...) @getlogin()
%14 = tail call i64 @strcmp(i32* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = tail call i32 @setlogin(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i32 %18, -1
%20 = zext i1 %19 to i32
%21 = tail call i32 @assert(i32 %20)
%22 = load i64, i64* @errno
%23 = load i64, i64* @EINVAL
%24 = icmp eq i64 %22, %23
%25 = zext i1 %24 to i32
%26 = tail call i32 @assert(i32 %25)
%27 = tail call i32* (...) @getlogin()
%28 = icmp ne i32* %27, null
%29 = zext i1 %28 to i32
%30 = tail call i32 @assert(i32 %29)
%31 = tail call i32* (...) @getlogin()
%32 = tail call i64 @strcmp(i32* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
%34 = zext i1 %33 to i32
%35 = tail call i32 @assert(i32 %34)
%36 = tail call i64 @seteuid(i32 1)
%37 = icmp eq i64 %36, 0
%38 = zext i1 %37 to i32
%39 = tail call i32 @assert(i32 %38)
%40 = tail call i32 @setlogin(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%41 = icmp eq i32 %40, -1
%42 = zext i1 %41 to i32
%43 = tail call i32 @assert(i32 %42)
%44 = load i64, i64* @errno
%45 = load i64, i64* @EPERM
%46 = icmp eq i64 %44, %45
%47 = zext i1 %46 to i32
%48 = tail call i32 @assert(i32 %47)
%49 = tail call i32* (...) @getlogin()
%50 = icmp ne i32* %49, null
%51 = zext i1 %50 to i32
%52 = tail call i32 @assert(i32 %51)
%53 = tail call i32* (...) @getlogin()
%54 = tail call i64 @strcmp(i32* %53, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%55 = icmp eq i64 %54, 0
%56 = zext i1 %55 to i32
%57 = tail call i32 @assert(i32 %56)
%58 = tail call i64 @seteuid(i32 0)
%59 = icmp eq i64 %58, 0
%60 = zext i1 %59 to i32
%61 = tail call i32 @assert(i32 %60)
%62 = tail call i32 @setlogin(i8* inttoptr (i64 1 to i8*))
%63 = icmp eq i32 %62, -1
%64 = zext i1 %63 to i32
%65 = tail call i32 @assert(i32 %64)
%66 = load i64, i64* @errno
%67 = load i64, i64* @EFAULT
%68 = icmp eq i64 %66, %67
%69 = zext i1 %68 to i32
%70 = tail call i32 @assert(i32 %69)
%71 = tail call i32* (...) @getlogin()
%72 = icmp ne i32* %71, null
%73 = zext i1 %72 to i32
%74 = tail call i32 @assert(i32 %73)
%75 = tail call i32* (...) @getlogin()
%76 = tail call i64 @strcmp(i32* %75, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%77 = icmp eq i64 %76, 0
%78 = zext i1 %77 to i32
%79 = tail call i32 @assert(i32 %78)
%80 = tail call i32 @setlogin(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%81 = icmp eq i32 %80, 0
%82 = zext i1 %81 to i32
%83 = tail call i32 @assert(i32 %82)
%84 = tail call i32* (...) @getlogin()
%85 = icmp eq i32* %84, null
%86 = zext i1 %85 to i32
%87 = tail call i32 @assert(i32 %86)
ret i32 0
}