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

/* Variables and functions */
int /*<<< orphan*/ execv(char *, char **);
int /*<<< orphan*/ exit(int);
int login(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ ureadline(char *, int, int /*<<< orphan*/);
int main() {
  char password[32];
  printf("Enter root password: ");
  ureadline((char *)&password, sizeof(password) - 1, 0);
  printf("\n");
  if (login(0, password) == -1) {
    printf("Login failed\n");
    exit(1);
  }
  char *args[] = {"/bin/sh", 0};
  execv(args[0], args);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xea1(%rip),%rdi
call   1030 <printf@plt>
lea    -0x20(%rbp),%rdi
mov    $0x1f,%esi
xor    %edx,%edx
call   1040 <ureadline@plt>
lea    0xea7(%rip),%rdi
call   1030 <printf@plt>
lea    -0x20(%rbp),%rsi
xor    %edi,%edi
call   1050 <login@plt>
cmp    $0xffffffff,%eax
jne    11aa <main+0x5a>
lea    0xe7b(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2c5f(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c5c(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1070 <execv@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
lea    0xe84(%rip),%rdi
call   1050 <printf@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1f,%esi
xor    %edx,%edx
call   1060 <ureadline@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1070 <login@plt>
cmp    $0xffffffff,%eax
je     11d0 <main+0x60>
movaps 0x2c5b(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xe56(%rip),%rdi
mov    %rsp,%rsi
call   1090 <execv@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret
lea    0xe47(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"Enter root password: \00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [14 x i8] c"Login failed\0A\00"
@.str.3 = [8 x i8] c"/bin/sh\00"
@__const.main.args = [2 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i32 0, i32 0), i8* null]
define i32 @main() {
%1 = alloca [32 x i8]
%2 = alloca [2 x i8*]
%3 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%4 = bitcast [32 x i8]* %1 to i8*
%5 = call i32 @ureadline(i8* %4, i32 31, i32 0)
%6 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%8 = call i32 @login(i32 0, i8* %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = bitcast [2 x i8*]* %2 to i8*
%15 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 0
%16 = load i8*, i8** %15
%17 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 0
%18 = call i32 @execv(i8* %16, i8** %17)
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"Enter root password: \00"
@.str.3 = [8 x i8] c"/bin/sh\00"
@__const.main.args = [2 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i32 0, i32 0), i8* null]
@str = [13 x i8] c"Login failed\00"
define i32 @main() {
%1 = alloca [32 x i8]
%2 = alloca [2 x i8*]
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @ureadline(i8* %3, i32 31, i32 0)
%6 = call i32 @putchar(i32 10)
%7 = call i32 @login(i32 0, i8* %3)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = bitcast [2 x i8*]* %2 to i8*
%14 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 0
%15 = call i32 @execv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8** %14)
ret i32 0
}