#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 */
struct spwd {
  int /*<<< orphan*/ sp_pwdp;
};
struct passwd {
  int pw_uid;
  int /*<<< orphan*/ pw_passwd;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ _SC_LOGIN_NAME_MAX;
char *crypt(char *, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, long, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *getpass(char *);
struct passwd *getpwnam(char *);
struct spwd *getspnam(char *);
scalar_t__ getuid();
char *malloc(long);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, int /*<<< orphan*/);
char *strerror(scalar_t__);
size_t strlen(char *);
long sysconf(int /*<<< orphan*/);
int main(void) {
  char *username = NULL;
  char *password = NULL;
  char *encrypted = NULL;
  long login_max = 0;
  size_t len = 0;
  struct passwd *pwd = NULL;
  struct spwd *shpw = NULL;
  if (getuid() != 0) {
    fprintf(stderr, "Sorry, you're not root. Login as root please.\n");
    exit(EXIT_FAILURE);
  }
  login_max = sysconf(_SC_LOGIN_NAME_MAX);
  if (login_max < 0)
    login_max = 256;
  username = malloc(login_max);
  if (username == NULL) {
    fprintf(stderr, "Err. malloc() failed: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  printf("Username: ");
  fflush(stdout);
  if (fgets(username, login_max, stdin) == NULL) {
    fprintf(stderr, "Err. fgets() failed: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  len = strlen(username);
  if (username[len - 1] == '\n')
    username[len - 1] = '\0';
  pwd = getpwnam(username);
  if (pwd == NULL) {
    if (errno == 0) {
      fprintf(stderr, "Account Not Found.\n");
      exit(EXIT_FAILURE);
    } else {
      fprintf(stderr, "Err. getpwnam() failed.\n");
      exit(EXIT_FAILURE);
    }
  }
  shpw = getspnam(username);
  if (shpw == NULL) {
    if (errno == 0 && errno) {
      fprintf(stderr, "Account Not Found.\n");
      exit(EXIT_FAILURE);
    } else {
      fprintf(stderr, "Err. getspnam() failed.\n");
      exit(EXIT_FAILURE);
    }
  }
  if (shpw != NULL)
    pwd->pw_passwd = shpw->sp_pwdp;
  password = getpass("Password: ");
  encrypted = crypt(password, pwd->pw_passwd);
  while (*password != '\0')
    *password++ = '\0';
  if (strcmp(encrypted, pwd->pw_passwd) != 0) {
    fprintf(stderr, "Authentication failed.\n");
    exit(EXIT_FAILURE);
  }
  printf("Authenticated UID = %d\n", pwd->pw_uid);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    $0x0,%al
call   1050 <getuid@plt>
cmp    $0x0,%rax
je     126d <main+0x7d>
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
lea    0xda8(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
call   10f0 <sysconf@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jge    1292 <main+0xa2>
movq   $0x100,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   10b0 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    12e7 <main+0xf7>
mov    0x2d1f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2d0b(%rip),%rax
mov    (%rax),%rdi
call   1110 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    %rax,%rdx
lea    0xd5d(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2ce0(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
lea    0xd5b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2cbc(%rip),%rax
mov    (%rax),%edi
call   10c0 <fflush@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    0x2cd6(%rip),%rax
mov    (%rax),%edx
call   1070 <fgets@plt>
cmp    $0x0,%rax
jne    1360 <main+0x170>
mov    0x2ca6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2c92(%rip),%rax
mov    (%rax),%rdi
call   1110 <strerror@plt>
mov    -0x48(%rbp),%edi
mov    %rax,%rdx
lea    0xd09(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2c67(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1396 <main+0x1a6>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1090 <getpwnam@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1409 <main+0x219>
mov    0x2c13(%rip),%rax
cmpq   $0x0,(%rax)
jne    13e4 <main+0x1f4>
mov    0x2c0a(%rip),%rax
mov    (%rax),%edi
lea    0xc9e(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2be3(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    0x2be5(%rip),%rax
mov    (%rax),%edi
lea    0xc8d(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2bbe(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x10(%rbp),%rdi
call   10e0 <getspnam@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    148d <main+0x29d>
mov    0x2ba0(%rip),%rax
cmpq   $0x0,(%rax)
jne    1468 <main+0x278>
mov    0x2b8f(%rip),%rax
cmpq   $0x0,(%rax)
je     1468 <main+0x278>
mov    0x2b86(%rip),%rax
mov    (%rax),%edi
lea    0xc1a(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2b5f(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    0x2b61(%rip),%rax
mov    (%rax),%edi
lea    0xc22(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2b3a(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
cmpq   $0x0,-0x40(%rbp)
je     14a5 <main+0x2b5>
mov    -0x40(%rbp),%rax
mov    (%rax),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,0x4(%rax)
lea    0xc07(%rip),%rdi
call   10d0 <getpass@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    0x4(%rax),%esi
call   1030 <crypt@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     14f0 <main+0x300>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,(%rax)
jmp    14c9 <main+0x2d9>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    0x4(%rax),%esi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     152f <main+0x33f>
mov    0x2abf(%rip),%rax
mov    (%rax),%edi
lea    0xba4(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2a98(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x38(%rbp),%rax
mov    (%rax),%esi
lea    0xb9a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2a66(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <getuid@plt>
test   %rax,%rax
jne    1314 <main+0x124>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   10f0 <sysconf@plt>
test   %rax,%rax
mov    $0x100,%r14d
cmovns %rax,%r14
mov    %r14,%rdi
call   10b0 <malloc@plt>
test   %rax,%rax
je     1329 <main+0x139>
mov    %rax,%rbx
lea    0xe0f(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
call   10c0 <fflush@plt>
mov    0x2d92(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <fgets@plt>
test   %rax,%rax
je     134a <main+0x15a>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    1280 <main+0x90>
movb   $0x0,-0x1(%rbx,%rax,1)
mov    %rbx,%rdi
call   1090 <getpwnam@plt>
test   %rax,%rax
je     1377 <main+0x187>
mov    %rax,%r14
mov    %rbx,%rdi
call   10e0 <getspnam@plt>
test   %rax,%rax
je     1396 <main+0x1a6>
mov    (%rax),%eax
mov    %eax,0x4(%r14)
lea    0xe01(%rip),%rdi
call   10d0 <getpass@plt>
mov    %rax,%rbx
mov    0x4(%r14),%esi
mov    %rax,%rdi
call   1030 <crypt@plt>
cmpb   $0x0,(%rbx)
je     12dd <main+0xed>
add    $0x1,%rbx
nop
movb   $0x0,-0x1(%rbx)
cmpb   $0x0,(%rbx)
lea    0x1(%rbx),%rbx
jne    12d0 <main+0xe0>
mov    0x4(%r14),%esi
mov    %rax,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    13a8 <main+0x1b8>
mov    (%r14),%esi
lea    0xdda(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2ca6(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2cb5(%rip),%rax
mov    (%rax),%edi
lea    0xcdc(%rip),%rsi
jmp    13c1 <main+0x1d1>
mov    0x2ca0(%rip),%rax
mov    (%rax),%ebx
mov    0x2c8f(%rip),%rax
mov    (%rax),%rdi
call   1110 <strerror@plt>
lea    0xce7(%rip),%rsi
jmp    1369 <main+0x179>
mov    0x2c7f(%rip),%rax
mov    (%rax),%ebx
mov    0x2c6e(%rip),%rax
mov    (%rax),%rdi
call   1110 <strerror@plt>
lea    0xceb(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    13c8 <main+0x1d8>
mov    0x2c4a(%rip),%rax
cmpq   $0x0,(%rax)
mov    0x2c47(%rip),%rax
mov    (%rax),%edi
jne    13ba <main+0x1ca>
lea    0xcd9(%rip),%rsi
jmp    13c1 <main+0x1d1>
mov    0x2c33(%rip),%rax
mov    (%rax),%edi
lea    0xcf4(%rip),%rsi
jmp    13c1 <main+0x1d1>
mov    0x2c21(%rip),%rax
mov    (%rax),%edi
lea    0xd06(%rip),%rsi
jmp    13c1 <main+0x1d1>
lea    0xcc0(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0x2bf1(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.passwd = type { i32, i32 }
%struct.spwd = type { i32 }
@stderr = global i32 0
@.str = [47 x i8] c"Sorry, you're not root. Login as root please.\0A\00"
@EXIT_FAILURE = global i32 0
@_SC_LOGIN_NAME_MAX = global i32 0
@.str.1 = [26 x i8] c"Err. malloc() failed: %s\0A\00"
@errno = global i64 0
@.str.2 = [11 x i8] c"Username: \00"
@stdout = global i32 0
@stdin = global i32 0
@.str.3 = [25 x i8] c"Err. fgets() failed: %s\0A\00"
@.str.4 = [20 x i8] c"Account Not Found.\0A\00"
@.str.5 = [25 x i8] c"Err. getpwnam() failed.\0A\00"
@.str.6 = [25 x i8] c"Err. getspnam() failed.\0A\00"
@.str.7 = [11 x i8] c"Password: \00"
@.str.8 = [24 x i8] c"Authentication failed.\0A\00"
@.str.9 = [24 x i8] c"Authenticated UID = %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca %struct.passwd*
%8 = alloca %struct.spwd*
store i32 0, i32* %1
store i8* null, i8** %2
store i8* null, i8** %3
store i8* null, i8** %4
store i64 0, i64* %5
store i64 0, i64* %6
store %struct.passwd* null, %struct.passwd** %7
store %struct.spwd* null, %struct.spwd** %8
%9 = call i64 (...) @getuid()
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %0
%17 = load i32, i32* @_SC_LOGIN_NAME_MAX
%18 = call i64 @sysconf(i32 %17)
store i64 %18, i64* %5
%19 = load i64, i64* %5
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16
store i64 256, i64* %5
br label %22
22: ; preds = %21, %16
%23 = load i64, i64* %5
%24 = call i8* @malloc(i64 %23)
store i8* %24, i8** %2
%25 = load i8*, i8** %2
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %34
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = load i64, i64* @errno
%30 = call i8* @strerror(i64 %29)
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %22
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%36 = load i32, i32* @stdout
%37 = call i32 @fflush(i32 %36)
%38 = load i8*, i8** %2
%39 = load i64, i64* %5
%40 = load i32, i32* @stdin
%41 = call i32* @fgets(i8* %38, i64 %39, i32 %40)
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %50
43: ; preds = %34
%44 = load i32, i32* @stderr
%45 = load i64, i64* @errno
%46 = call i8* @strerror(i64 %45)
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %46)
%48 = load i32, i32* @EXIT_FAILURE
%49 = call i32 @exit(i32 %48)
unreachable
50: ; preds = %34
%51 = load i8*, i8** %2
%52 = call i64 @strlen(i8* %51)
store i64 %52, i64* %6
%53 = load i8*, i8** %2
%54 = load i64, i64* %6
%55 = sub i64 %54, 1
%56 = getelementptr inbounds i8, i8* %53, i64 %55
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %58, 10
br i1 %59, label %60, label %65
60: ; preds = %50
%61 = load i8*, i8** %2
%62 = load i64, i64* %6
%63 = sub i64 %62, 1
%64 = getelementptr inbounds i8, i8* %61, i64 %63
store i8 0, i8* %64
br label %65
65: ; preds = %60, %50
%66 = load i8*, i8** %2
%67 = call %struct.passwd* @getpwnam(i8* %66)
store %struct.passwd* %67, %struct.passwd** %7
%68 = load %struct.passwd*, %struct.passwd** %7
%69 = icmp eq %struct.passwd* %68, null
br i1 %69, label %70, label %83
70: ; preds = %65
%71 = load i64, i64* @errno
%72 = icmp eq i64 %71, 0
br i1 %72, label %73, label %78
73: ; preds = %70
%74 = load i32, i32* @stderr
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%76 = load i32, i32* @EXIT_FAILURE
%77 = call i32 @exit(i32 %76)
unreachable
78: ; preds = %70
%79 = load i32, i32* @stderr
%80 = call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%81 = load i32, i32* @EXIT_FAILURE
%82 = call i32 @exit(i32 %81)
unreachable
83: ; preds = %65
%84 = load i8*, i8** %2
%85 = call %struct.spwd* @getspnam(i8* %84)
store %struct.spwd* %85, %struct.spwd** %8
%86 = load %struct.spwd*, %struct.spwd** %8
%87 = icmp eq %struct.spwd* %86, null
br i1 %87, label %88, label %104
88: ; preds = %83
%89 = load i64, i64* @errno
%90 = icmp eq i64 %89, 0
br i1 %90, label %91, label %99
91: ; preds = %88
%92 = load i64, i64* @errno
%93 = icmp ne i64 %92, 0
br i1 %93, label %94, label %99
94: ; preds = %91
%95 = load i32, i32* @stderr
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%97 = load i32, i32* @EXIT_FAILURE
%98 = call i32 @exit(i32 %97)
unreachable
99: ; preds = %91, %88
%100 = load i32, i32* @stderr
%101 = call i32 (i32, i8*, ...) @fprintf(i32 %100, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
%102 = load i32, i32* @EXIT_FAILURE
%103 = call i32 @exit(i32 %102)
unreachable
104: ; preds = %83
%105 = load %struct.spwd*, %struct.spwd** %8
%106 = icmp ne %struct.spwd* %105, null
br i1 %106, label %107, label %113
107: ; preds = %104
%108 = load %struct.spwd*, %struct.spwd** %8
%109 = getelementptr inbounds %struct.spwd, %struct.spwd* %108, i32 0, i32 0
%110 = load i32, i32* %109
%111 = load %struct.passwd*, %struct.passwd** %7
%112 = getelementptr inbounds %struct.passwd, %struct.passwd* %111, i32 0, i32 1
store i32 %110, i32* %112
br label %113
113: ; preds = %107, %104
%114 = call i8* @getpass(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
store i8* %114, i8** %3
%115 = load i8*, i8** %3
%116 = load %struct.passwd*, %struct.passwd** %7
%117 = getelementptr inbounds %struct.passwd, %struct.passwd* %116, i32 0, i32 1
%118 = load i32, i32* %117
%119 = call i8* @crypt(i8* %115, i32 %118)
store i8* %119, i8** %4
br label %120
120: ; preds = %125, %113
%121 = load i8*, i8** %3
%122 = load i8, i8* %121
%123 = sext i8 %122 to i32
%124 = icmp ne i32 %123, 0
br i1 %124, label %125, label %128
125: ; preds = %120
%126 = load i8*, i8** %3
%127 = getelementptr inbounds i8, i8* %126, i32 1
store i8* %127, i8** %3
store i8 0, i8* %126
br label %120
128: ; preds = %120
%129 = load i8*, i8** %4
%130 = load %struct.passwd*, %struct.passwd** %7
%131 = getelementptr inbounds %struct.passwd, %struct.passwd* %130, i32 0, i32 1
%132 = load i32, i32* %131
%133 = call i64 @strcmp(i8* %129, i32 %132)
%134 = icmp ne i64 %133, 0
br i1 %134, label %135, label %140
135: ; preds = %128
%136 = load i32, i32* @stderr
%137 = call i32 (i32, i8*, ...) @fprintf(i32 %136, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
%138 = load i32, i32* @EXIT_FAILURE
%139 = call i32 @exit(i32 %138)
unreachable
140: ; preds = %128
%141 = load %struct.passwd*, %struct.passwd** %7
%142 = getelementptr inbounds %struct.passwd, %struct.passwd* %141, i32 0, i32 0
%143 = load i32, i32* %142
%144 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i32 %143)
%145 = load i32, i32* @EXIT_SUCCESS
ret i32 %145
}

LLVM IR (-O2):
%struct.passwd = type { i32, i32 }
%struct.spwd = type { i32 }
@stderr = global i32 0
@.str = [47 x i8] c"Sorry, you're not root. Login as root please.\0A\00"
@EXIT_FAILURE = global i32 0
@_SC_LOGIN_NAME_MAX = global i32 0
@.str.1 = [26 x i8] c"Err. malloc() failed: %s\0A\00"
@errno = global i64 0
@.str.2 = [11 x i8] c"Username: \00"
@stdout = global i32 0
@stdin = global i32 0
@.str.3 = [25 x i8] c"Err. fgets() failed: %s\0A\00"
@.str.4 = [20 x i8] c"Account Not Found.\0A\00"
@.str.5 = [25 x i8] c"Err. getpwnam() failed.\0A\00"
@.str.6 = [25 x i8] c"Err. getspnam() failed.\0A\00"
@.str.7 = [11 x i8] c"Password: \00"
@.str.8 = [24 x i8] c"Authentication failed.\0A\00"
@.str.9 = [24 x i8] c"Authenticated UID = %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call i64 (...) @getuid()
%2 = icmp eq i64 %1, 0
br i1 %2, label %8, label %3
3: ; preds = %0
%4 = load i32, i32* @stderr
%5 = tail call i32 (i32, i8*, ...) @fprintf(i32 %4, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %0
%9 = load i32, i32* @_SC_LOGIN_NAME_MAX
%10 = tail call i64 @sysconf(i32 %9)
%11 = icmp slt i64 %10, 0
%12 = select i1 %11, i64 256, i64 %10
%13 = tail call i8* @malloc(i64 %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %22
15: ; preds = %8
%16 = load i32, i32* @stderr
%17 = load i64, i64* @errno
%18 = tail call i8* @strerror(i64 %17)
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %8
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%24 = load i32, i32* @stdout
%25 = tail call i32 @fflush(i32 %24)
%26 = load i32, i32* @stdin
%27 = tail call i32* @fgets(i8* %13, i64 %12, i32 %26)
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %36
29: ; preds = %22
%30 = load i32, i32* @stderr
%31 = load i64, i64* @errno
%32 = tail call i8* @strerror(i64 %31)
%33 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %32)
%34 = load i32, i32* @EXIT_FAILURE
%35 = tail call i32 @exit(i32 %34)
unreachable
36: ; preds = %22
%37 = tail call i64 @strlen(i8* %13)
%38 = add i64 %37, -1
%39 = getelementptr inbounds i8, i8* %13, i64 %38
%40 = load i8, i8* %39
%41 = icmp eq i8 %40, 10
br i1 %41, label %42, label %43
42: ; preds = %36
store i8 0, i8* %39
br label %43
43: ; preds = %42, %36
%44 = tail call %struct.passwd* @getpwnam(i8* %13)
%45 = icmp eq %struct.passwd* %44, null
br i1 %45, label %46, label %58
46: ; preds = %43
%47 = load i64, i64* @errno
%48 = icmp eq i64 %47, 0
%49 = load i32, i32* @stderr
br i1 %48, label %50, label %54
50: ; preds = %46
%51 = tail call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%52 = load i32, i32* @EXIT_FAILURE
%53 = tail call i32 @exit(i32 %52)
unreachable
54: ; preds = %46
%55 = tail call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%56 = load i32, i32* @EXIT_FAILURE
%57 = tail call i32 @exit(i32 %56)
unreachable
58: ; preds = %43
%59 = tail call %struct.spwd* @getspnam(i8* %13)
%60 = icmp eq %struct.spwd* %59, null
br i1 %60, label %61, label %66
61: ; preds = %58
%62 = load i32, i32* @stderr
%63 = tail call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
%64 = load i32, i32* @EXIT_FAILURE
%65 = tail call i32 @exit(i32 %64)
unreachable
66: ; preds = %58
%67 = getelementptr inbounds %struct.spwd, %struct.spwd* %59, i64 0, i32 0
%68 = load i32, i32* %67
%69 = getelementptr inbounds %struct.passwd, %struct.passwd* %44, i64 0, i32 1
store i32 %68, i32* %69
%70 = tail call i8* @getpass(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%71 = load i32, i32* %69
%72 = tail call i8* @crypt(i8* %70, i32 %71)
%73 = load i8, i8* %70
%74 = icmp eq i8 %73, 0
br i1 %74, label %80, label %75
75: ; preds = %66, %75
%76 = phi i8* [ %77, %75 ], [ %70, %66 ]
%77 = getelementptr inbounds i8, i8* %76, i64 1
store i8 0, i8* %76
%78 = load i8, i8* %77
%79 = icmp eq i8 %78, 0
br i1 %79, label %80, label %75
80: ; preds = %75, %66
%81 = load i32, i32* %69
%82 = tail call i64 @strcmp(i8* %72, i32 %81)
%83 = icmp eq i64 %82, 0
br i1 %83, label %89, label %84
84: ; preds = %80
%85 = load i32, i32* @stderr
%86 = tail call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
%87 = load i32, i32* @EXIT_FAILURE
%88 = tail call i32 @exit(i32 %87)
unreachable
89: ; preds = %80
%90 = getelementptr inbounds %struct.passwd, %struct.passwd* %44, i64 0, i32 0
%91 = load i32, i32* %90
%92 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i32 %91)
%93 = load i32, i32* @EXIT_SUCCESS
ret i32 %93
}