#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 connect_login(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
scalar_t__ geteuid();
scalar_t__ getuid();
int /*<<< orphan*/ reject_login_name(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc == 2) {
    if ((getuid() == 0) && (geteuid() == 0)) {
      if (!reject_login_name(argv[1])) {
        exit(connect_login(argv[1]));
      } else {
        fprintf(stderr, "%s: illegal length or character(s) in login name.\n",
                argv[0]);
        exit(2);
      }
    } else {
      fprintf(stderr, "%s: not running as root.\n", argv[0]);
      exit(2);
    }
  } else {
    fprintf(stderr, "%s login-name\n%s: bad args.\n", argv[0], argv[0]);
    exit(2);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    121c <main+0xbc>
mov    $0x0,%al
call   1040 <getuid@plt>
cmp    $0x0,%rax
jne    11f4 <main+0x94>
mov    $0x0,%al
call   1050 <geteuid@plt>
cmp    $0x0,%rax
jne    11f4 <main+0x94>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <reject_login_name@plt>
cmp    $0x0,%eax
jne    11cc <main+0x6c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <connect_login@plt>
mov    %eax,%edi
call   1080 <exit@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe1d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe28(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
lea    0xe13(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    119e <main+0x3e>
xor    %eax,%eax
call   1040 <getuid@plt>
test   %rax,%rax
jne    11c5 <main+0x65>
xor    %eax,%eax
call   1050 <geteuid@plt>
test   %rax,%rax
jne    11c5 <main+0x65>
mov    0x8(%rbx),%rdi
call   1030 <reject_login_name@plt>
test   %eax,%eax
jne    11e9 <main+0x89>
mov    0x8(%rbx),%rdi
call   1070 <connect_login@plt>
mov    %eax,%edi
call   1080 <exit@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rcx
lea    0xe9c(%rip),%rsi
mov    %rcx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe5b(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe04(%rip),%rsi
jmp    11d8 <main+0x78>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [51 x i8] c"%s: illegal length or character(s) in login name.\0A\00"
@.str.1 = [26 x i8] c"%s: not running as root.\0A\00"
@.str.2 = [29 x i8] c"%s login-name\0A%s: bad args.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, 2
br i1 %7, label %8, label %40
8: ; preds = %2
%9 = call i64 (...) @getuid()
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %33
11: ; preds = %8
%12 = call i64 (...) @geteuid()
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %33
14: ; preds = %11
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @reject_login_name(i8* %17)
%19 = icmp ne i32 %18, 0
br i1 %19, label %26, label %20
20: ; preds = %14
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @connect_login(i8* %23)
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %14
%27 = load i32, i32* @stderr
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %30)
%32 = call i32 @exit(i32 2)
unreachable
33: ; preds = %11, %8
%34 = load i32, i32* @stderr
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 0
%37 = load i8*, i8** %36
%38 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %37)
%39 = call i32 @exit(i32 2)
unreachable
40: ; preds = %2
%41 = load i32, i32* @stderr
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 0
%44 = load i8*, i8** %43
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 0
%47 = load i8*, i8** %46
%48 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %44, i8* %47)
%49 = call i32 @exit(i32 2)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [51 x i8] c"%s: illegal length or character(s) in login name.\0A\00"
@.str.1 = [26 x i8] c"%s: not running as root.\0A\00"
@.str.2 = [29 x i8] c"%s login-name\0A%s: bad args.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %29
4: ; preds = %2
%5 = tail call i64 (...) @getuid()
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %24
7: ; preds = %4
%8 = tail call i64 (...) @geteuid()
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %24
10: ; preds = %7
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @reject_login_name(i8* %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = load i8*, i8** %11
%17 = tail call i32 @connect_login(i8* %16)
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %10
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %1
%22 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = tail call i32 @exit(i32 2)
unreachable
24: ; preds = %7, %4
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %1
%27 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = tail call i32 @exit(i32 2)
unreachable
29: ; preds = %2
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %1
%32 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %31, i8* %31)
%33 = tail call i32 @exit(i32 2)
unreachable
}