#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 LOG_AUTH;
int LOG_INFO;
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ auth_finish();
int /*<<< orphan*/ closeall();
int /*<<< orphan*/ execle(char *, char *, char *, char *, char const *,
                          char const *, char const *, char **, ...);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fatal(int /*<<< orphan*/, char *, int);
char *malloc(scalar_t__);
int /*<<< orphan*/ setup_term(int /*<<< orphan*/, char const *);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char const *);
int /*<<< orphan*/ syslog(int, char *);
void child(const char *hname, const char *termtype, const char *localuser,
           int authenticated) {
  char *termenv[2];
  char **env;
  setup_term(0, termtype);
  termenv[0] = malloc(strlen(termtype) + 6);
  if (termenv[0]) {
    strcpy(termenv[0], "TERM=");
    strcat(termenv[0], termtype);
  }
  termenv[1] = NULL;
  env = &termenv[0];
  if (authenticated) {
    auth_finish();
    closeall();
    execle("/bin/login", "login", "-p", "-h", hname, "-f", localuser, NULL,
           env);
  } else {
    if (localuser[0] == '-') {
      syslog(LOG_AUTH | LOG_INFO, "mrlogin with an option as a name!");
      exit(1);
    }
    auth_finish();
    closeall();
    execle("/bin/login", "login", "-p", "-h", hname, localuser, NULL, env);
  }
  fatal(STDERR_FILENO, "/bin/login", 1);
}


x86 assembly (clang, -O0):
<child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x10(%rbp),%rsi
xor    %edi,%edi
call   1080 <setup_term@plt>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x6,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1213 <child+0x63>
mov    -0x30(%rbp),%rdi
lea    0xdff(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10a0 <strcat@plt>
movq   $0x0,-0x28(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     128b <child+0xdb>
mov    $0x0,%al
call   1030 <auth_finish@plt>
mov    $0x0,%al
call   1090 <closeall@plt>
mov    -0x8(%rbp),%r8
mov    -0x18(%rbp),%r10
mov    -0x38(%rbp),%rax
lea    0xdb8(%rip),%rdi
lea    0xdb6(%rip),%rsi
lea    0xdb5(%rip),%rdx
lea    0xdb1(%rip),%rcx
lea    0xdad(%rip),%r9
xor    %r11d,%r11d
mov    %r10,(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rax,0x10(%rsp)
mov    $0x0,%al
call   10c0 <execle@plt>
jmp    1310 <child+0x160>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    12c3 <child+0x113>
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
mov    0x2d25(%rip),%rax
or     (%rax),%edi
lea    0xd66(%rip),%rsi
call   1070 <syslog@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    $0x0,%al
call   1030 <auth_finish@plt>
mov    $0x0,%al
call   1090 <closeall@plt>
mov    -0x8(%rbp),%r8
mov    -0x18(%rbp),%r9
mov    -0x38(%rbp),%rax
lea    0xd22(%rip),%rdi
lea    0xd20(%rip),%rsi
lea    0xd1f(%rip),%rdx
lea    0xd1b(%rip),%rcx
xor    %r10d,%r10d
movq   $0x0,(%rsp)
mov    %rax,0x8(%rsp)
mov    $0x0,%al
call   10c0 <execle@plt>
mov    0x2cc1(%rip),%rax
mov    (%rax),%edi
lea    0xce6(%rip),%rsi
mov    $0x1,%edx
call   10d0 <fatal@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<child>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r12d
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %edi,%edi
call   1080 <setup_term@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x6(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,(%rsp)
test   %rax,%rax
je     1206 <child+0x56>
mov    %rax,%rbp
lea    0xe0d(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10a0 <strcat@plt>
movq   $0x0,0x8(%rsp)
test   %r12d,%r12d
je     1263 <child+0xb3>
xor    %eax,%eax
call   1030 <auth_finish@plt>
xor    %eax,%eax
call   1090 <closeall@plt>
sub    $0x8,%rsp
lea    0x8(%rsp),%rbp
lea    0xdd4(%rip),%rdi
lea    0xdd2(%rip),%rsi
lea    0xdd1(%rip),%rdx
lea    0xdcd(%rip),%rcx
lea    0xdc9(%rip),%r9
mov    %r14,%r8
xor    %eax,%eax
push   %rbp
push   $0x0
push   %r15
call   10c0 <execle@plt>
add    $0x20,%rsp
jmp    12aa <child+0xfa>
cmpb   $0x2d,(%r15)
je     12d1 <child+0x121>
xor    %eax,%eax
call   1030 <auth_finish@plt>
xor    %eax,%eax
call   1090 <closeall@plt>
mov    %rsp,%rbp
lea    0xd85(%rip),%rdi
lea    0xd83(%rip),%rsi
lea    0xd82(%rip),%rdx
lea    0xd7e(%rip),%rcx
mov    %r14,%r8
mov    %r15,%r9
xor    %eax,%eax
push   %rbp
push   $0x0
call   10c0 <execle@plt>
add    $0x10,%rsp
mov    0x2d27(%rip),%rax
mov    (%rax),%edi
lea    0xd4c(%rip),%rsi
mov    $0x1,%edx
call   10d0 <fatal@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d10(%rip),%rax
mov    0x2cf1(%rip),%rcx
mov    (%rcx),%edi
or     (%rax),%edi
lea    0xd30(%rip),%rsi
call   1070 <syslog@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"TERM=\00"
@.str.1 = [11 x i8] c"/bin/login\00"
@.str.2 = [6 x i8] c"login\00"
@.str.3 = [3 x i8] c"-p\00"
@.str.4 = [3 x i8] c"-h\00"
@.str.5 = [3 x i8] c"-f\00"
@LOG_AUTH = global i32 0
@LOG_INFO = global i32 0
@.str.6 = [34 x i8] c"mrlogin with an option as a name!\00"
@STDERR_FILENO = global i32 0
define void @child(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [2 x i8*]
%10 = alloca i8**
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%11 = load i8*, i8** %6
%12 = call i32 @setup_term(i32 0, i8* %11)
%13 = load i8*, i8** %6
%14 = call i64 @strlen(i8* %13)
%15 = add nsw i64 %14, 6
%16 = call i8* @malloc(i64 %15)
%17 = getelementptr inbounds [2 x i8*], [2 x i8*]* %9, i64 0, i64 0
store i8* %16, i8** %17
%18 = getelementptr inbounds [2 x i8*], [2 x i8*]* %9, i64 0, i64 0
%19 = load i8*, i8** %18
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %29
21: ; preds = %4
%22 = getelementptr inbounds [2 x i8*], [2 x i8*]* %9, i64 0, i64 0
%23 = load i8*, i8** %22
%24 = call i32 @strcpy(i8* %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%25 = getelementptr inbounds [2 x i8*], [2 x i8*]* %9, i64 0, i64 0
%26 = load i8*, i8** %25
%27 = load i8*, i8** %6
%28 = call i32 @strcat(i8* %26, i8* %27)
br label %29
29: ; preds = %21, %4
%30 = getelementptr inbounds [2 x i8*], [2 x i8*]* %9, i64 0, i64 1
store i8* null, i8** %30
%31 = getelementptr inbounds [2 x i8*], [2 x i8*]* %9, i64 0, i64 0
store i8** %31, i8*** %10
%32 = load i32, i32* %8
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %41
34: ; preds = %29
%35 = call i32 (...) @auth_finish()
%36 = call i32 (...) @closeall()
%37 = load i8*, i8** %5
%38 = load i8*, i8** %7
%39 = load i8**, i8*** %10
%40 = call i32 (i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8**, ...) @execle(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %38, i8** null, i8** %39)
br label %60
41: ; preds = %29
%42 = load i8*, i8** %7
%43 = getelementptr inbounds i8, i8* %42, i64 0
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 45
br i1 %46, label %47, label %53
47: ; preds = %41
%48 = load i32, i32* @LOG_AUTH
%49 = load i32, i32* @LOG_INFO
%50 = or i32 %48, %49
%51 = call i32 @syslog(i32 %50, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %41
%54 = call i32 (...) @auth_finish()
%55 = call i32 (...) @closeall()
%56 = load i8*, i8** %5
%57 = load i8*, i8** %7
%58 = load i8**, i8*** %10
%59 = call i32 (i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8**, ...) @execle(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %56, i8* %57, i8* null, i8** %58)
br label %60
60: ; preds = %53, %34
%61 = load i32, i32* @STDERR_FILENO
%62 = call i32 @fatal(i32 %61, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 1)
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"TERM=\00"
@.str.1 = [11 x i8] c"/bin/login\00"
@.str.2 = [6 x i8] c"login\00"
@.str.3 = [3 x i8] c"-p\00"
@.str.4 = [3 x i8] c"-h\00"
@.str.5 = [3 x i8] c"-f\00"
@LOG_AUTH = global i32 0
@LOG_INFO = global i32 0
@.str.6 = [34 x i8] c"mrlogin with an option as a name!\00"
@STDERR_FILENO = global i32 0
define void @child(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca [2 x i8*]
%6 = bitcast [2 x i8*]* %5 to i8*
%7 = tail call i32 @setup_term(i32 0, i8* %1)
%8 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%9 = add nsw i64 %8, 6
%10 = tail call i8* @malloc(i64 %9)
%11 = getelementptr inbounds [2 x i8*], [2 x i8*]* %5, i64 0, i64 0
store i8* %10, i8** %11
%12 = icmp eq i8* %10, null
br i1 %12, label %16, label %13
13: ; preds = %4
%14 = tail call i32 @strcpy(i8* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @strcat(i8* %10, i8* %1)
br label %16
16: ; preds = %13, %4
%17 = getelementptr inbounds [2 x i8*], [2 x i8*]* %5, i64 0, i64 1
store i8* null, i8** %17
%18 = icmp eq i32 %3, 0
br i1 %18, label %23, label %19
19: ; preds = %16
%20 = tail call i32 (...) @auth_finish()
%21 = tail call i32 (...) @closeall()
%22 = call i32 (i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8**, ...) @execle(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %2, i8** null, i8** %11)
br label %36
23: ; preds = %16
%24 = load i8, i8* %2
%25 = icmp eq i8 %24, 45
br i1 %25, label %26, label %32
26: ; preds = %23
%27 = load i32, i32* @LOG_AUTH
%28 = load i32, i32* @LOG_INFO
%29 = or i32 %28, %27
%30 = tail call i32 @syslog(i32 %29, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
%31 = tail call i32 @exit(i32 1)
unreachable
32: ; preds = %23
%33 = tail call i32 (...) @auth_finish()
%34 = tail call i32 (...) @closeall()
%35 = call i32 (i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8**, ...) @execle(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %2, i8* null, i8** %11)
br label %36
36: ; preds = %32, %19
%37 = load i32, i32* @STDERR_FILENO
%38 = call i32 @fatal(i32 %37, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 1)
ret void
}