#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 termios {
  int c_lflag;
};
struct passwd {
  int /*<<< orphan*/ pw_shell;
  int /*<<< orphan*/ pw_uid;
};

/* Variables and functions */
int ECHO;
int ICANON;
int /*<<< orphan*/ TCSANOW;
int errno;
int /*<<< orphan*/ execlp(int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char getchar();
struct passwd *getpwnam(char *);
scalar_t__ login(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ setsid();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcmp(char *, char *);
char *strerror(int);
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int iRunShell = 0, error = 0, help = 0, nStart = 0, i = 0;
  for (i = 1; i < argc; i++) {
    if (!strcmp(argv[i], "-s"))
      iRunShell = 1;
    else if (!strcmp(argv[i], "-h"))
      help = 1;
    else if (!nStart)
      nStart = i;
  }
  if (error || help || (!nStart && !iRunShell)) {
    fprintf(stderr, "Usage: sudo [-h] [-s|<command>]\n");
    fprintf(stderr, "\n");
    fprintf(stderr, "    -s: Access root shell\n");
    fprintf(stderr, "    -h: Show this help text\n");
    return error;
  }
  struct passwd *pw = getpwnam("root");
  if (!pw) {
    fprintf(stderr, "sudo: user 'root' doesn't exist!\n");
    return 1;
  }
  char password[256], c;
  i = 0;
  struct termios curt;
  tcgetattr(0, &curt);
  curt.c_lflag &= ~(ECHO | ICANON);
  tcsetattr(0, TCSANOW, &curt);
  printf("[sudo] Enter password: ");
  fflush(stdout);
  while (i < 256 && (c = getchar()) != '\n') {
    if (c == '\b') {
      if (i > 0) {
        password[--i] = '\0';
        printf("\b \b");
      }
    } else if (c != '\033') {
      password[i++] = c;
      printf("•");
    }
  }
  tcgetattr(0, &curt);
  curt.c_lflag |= (ECHO | ICANON);
  tcsetattr(0, TCSANOW, &curt);
  printf("\n");
  password[i] = '\0';
  if (login(pw->pw_uid, password) != 0) {
    fprintf(stderr, "sudo: password is incorrect\n");
    return 1;
  }
  setsid();
  if (iRunShell) {
    int pid;
    if ((pid = fork()) == 0) {
      execlp(pw->pw_shell, pw->pw_shell, 0);
      fprintf(stderr, "sudo: couldn't run shell: %s\n", strerror(errno));
      exit(errno);
    } else {
      int status;
      waitpid(pid, &status, 0);
      if (status) {
        exit(status);
      }
    }
  } else {
    int pid;
    if ((pid = fork()) == 0) {
      execvp(argv[nStart], &argv[nStart]);
      fprintf(stderr, "sudo: couldn't run command '%s': %s\n", argv[nStart],
              strerror(errno));
      exit(errno);
    } else {
      int status;
      waitpid(pid, &status, 0);
      if (status) {
        exit(status);
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12d6 <main+0xd6>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd9e(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    127c <main+0x7c>
movl   $0x1,-0x14(%rbp)
jmp    12c3 <main+0xc3>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd74(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    12a9 <main+0xa9>
movl   $0x1,-0x1c(%rbp)
jmp    12be <main+0xbe>
cmpl   $0x0,-0x20(%rbp)
jne    12b9 <main+0xb9>
mov    -0x24(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    12be <main+0xbe>
jmp    12c3 <main+0xc3>
jmp    12c8 <main+0xc8>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1243 <main+0x43>
cmpl   $0x0,-0x18(%rbp)
jne    12fe <main+0xfe>
cmpl   $0x0,-0x1c(%rbp)
jne    12fe <main+0xfe>
cmpl   $0x0,-0x20(%rbp)
jne    1365 <main+0x165>
cmpl   $0x0,-0x14(%rbp)
jne    1365 <main+0x165>
mov    0x2ccb(%rip),%rax
mov    (%rax),%edi
lea    0xcf8(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2cb4(%rip),%rax
mov    (%rax),%edi
lea    0xd5f(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2c9d(%rip),%rax
mov    (%rax),%edi
lea    0xceb(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2c86(%rip),%rax
mov    (%rax),%edi
lea    0xcef(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    16e8 <main+0x4e8>
lea    0xcf3(%rip),%rdi
call   1080 <getpwnam@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    13a3 <main+0x1a3>
mov    0x2c49(%rip),%rax
mov    (%rax),%edi
lea    0xcd4(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16e8 <main+0x4e8>
movl   $0x0,-0x24(%rbp)
xor    %edi,%edi
lea    -0x138(%rbp),%rsi
call   10c0 <tcgetattr@plt>
mov    0x2c21(%rip),%rax
mov    (%rax),%eax
mov    0x2bf0(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x138(%rbp),%eax
mov    %eax,-0x138(%rbp)
mov    0x2c08(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x138(%rbp),%rdx
call   10d0 <tcsetattr@plt>
lea    0xc8f(%rip),%rdi
call   1030 <printf@plt>
mov    0x2bbd(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
xor    %eax,%eax
cmpl   $0x100,-0x24(%rbp)
mov    %al,-0x149(%rbp)
jge    143b <main+0x23b>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %al,-0x131(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x149(%rbp)
mov    -0x149(%rbp),%al
test   $0x1,%al
jne    144e <main+0x24e>
jmp    14cc <main+0x2cc>
movsbl -0x131(%rbp),%eax
cmp    $0x8,%eax
jne    148c <main+0x28c>
cmpl   $0x0,-0x24(%rbp)
jle    1487 <main+0x287>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
cltq
movb   $0x0,-0x130(%rbp,%rax,1)
lea    0xc1c(%rip),%rdi
call   1030 <printf@plt>
jmp    14c7 <main+0x2c7>
movsbl -0x131(%rbp),%eax
cmp    $0x1b,%eax
je     14c2 <main+0x2c2>
mov    -0x131(%rbp),%cl
mov    -0x24(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x24(%rbp)
cltq
mov    %cl,-0x130(%rbp,%rax,1)
lea    0xbe5(%rip),%rdi
call   1030 <printf@plt>
jmp    14c7 <main+0x2c7>
jmp    140a <main+0x20a>
xor    %edi,%edi
lea    -0x138(%rbp),%rsi
call   10c0 <tcgetattr@plt>
mov    0x2aff(%rip),%rax
mov    (%rax),%eax
mov    0x2ace(%rip),%rcx
or     (%rcx),%eax
or     -0x138(%rbp),%eax
mov    %eax,-0x138(%rbp)
mov    0x2ae9(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x138(%rbp),%rdx
call   10d0 <tcsetattr@plt>
lea    0xb6e(%rip),%rdi
call   1030 <printf@plt>
movslq -0x24(%rbp),%rax
movb   $0x0,-0x130(%rbp,%rax,1)
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x130(%rbp),%rsi
call   1050 <login@plt>
cmp    $0x0,%rax
je     1567 <main+0x367>
mov    0x2a85(%rip),%rax
mov    (%rax),%edi
lea    0xb52(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16e8 <main+0x4e8>
mov    $0x0,%al
call   1040 <setsid@plt>
cmpl   $0x0,-0x14(%rbp)
je     1619 <main+0x419>
mov    $0x0,%al
call   1120 <fork@plt>
mov    %eax,-0x13c(%rbp)
cmp    $0x0,%eax
jne    15e3 <main+0x3e3>
mov    -0x30(%rbp),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <execlp@plt>
mov    0x2a28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x150(%rbp)
mov    0x2a11(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x150(%rbp),%edi
mov    %rax,%rdx
lea    0xaf5(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x29ec(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x13c(%rbp),%edi
lea    -0x140(%rbp),%rsi
xor    %edx,%edx
call   10b0 <waitpid@plt>
cmpl   $0x0,-0x140(%rbp)
je     160f <main+0x40f>
mov    -0x140(%rbp),%edi
call   10f0 <exit@plt>
jmp    1614 <main+0x414>
jmp    16e1 <main+0x4e1>
mov    $0x0,%al
call   1120 <fork@plt>
mov    %eax,-0x144(%rbp)
cmp    $0x0,%eax
jne    16ab <main+0x4ab>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x20(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
call   10e0 <execvp@plt>
mov    0x297a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x15c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x158(%rbp)
mov    0x2950(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x15c(%rbp),%edi
mov    -0x158(%rbp),%rdx
mov    %rax,%rcx
lea    0xa4b(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2924(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x144(%rbp),%edi
lea    -0x148(%rbp),%rsi
xor    %edx,%edx
call   10b0 <waitpid@plt>
cmpl   $0x0,-0x148(%rbp)
je     16d7 <main+0x4d7>
mov    -0x148(%rbp),%edi
call   10f0 <exit@plt>
jmp    16dc <main+0x4dc>
jmp    16e1 <main+0x4e1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %rsi,0x18(%rsp)
xor    %ebx,%ebx
mov    $0x0,%ebp
cmp    $0x2,%edi
jl     12c8 <main+0xb8>
mov    %edi,%r13d
xor    %r14d,%r14d
mov    $0x1,%r15d
lea    0xdb7(%rip),%r12
movl   $0x0,0x14(%rsp)
xor    %ebp,%ebp
jmp    126f <main+0x5f>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x1,%r14d
add    $0x1,%r15
cmp    %r15,%r13
je     12ba <main+0xaa>
mov    0x18(%rsp),%rax
mov    (%rax,%r15,8),%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
je     1260 <main+0x50>
mov    %rbx,%rdi
lea    0xd72(%rip),%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
je     12b0 <main+0xa0>
test   %ebp,%ebp
cmove  %r15d,%ebp
jmp    1266 <main+0x56>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movl   $0x1,0x14(%rsp)
jmp    1266 <main+0x56>
cmpl   $0x0,0x14(%rsp)
mov    %r14d,%ebx
jne    13b3 <main+0x1a3>
mov    %ebp,%eax
or     %ebx,%eax
je     13b3 <main+0x1a3>
lea    0xd86(%rip),%rdi
call   1090 <getpwnam@plt>
test   %rax,%rax
je     1474 <main+0x264>
mov    %rax,%r14
lea    0x8(%rsp),%r15
xor    %edi,%edi
mov    %r15,%rsi
call   10d0 <tcgetattr@plt>
mov    0x2ce0(%rip),%rcx
mov    0x2cb1(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
not    %eax
and    %eax,0x8(%rsp)
mov    0x2cd0(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
mov    %r15,%rdx
call   10e0 <tcsetattr@plt>
lea    0xd5b(%rip),%rdi
call   1040 <printf@plt>
mov    0x2c89(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
lea    0xd59(%rip),%r13
lea    0xd56(%rip),%r15
xor    %r12d,%r12d
jmp    1376 <main+0x166>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %al,0x20(%rsp,%rcx,1)
call   1040 <printf@plt>
cmp    $0x100,%r12d
jge    1405 <main+0x1f5>
xor    %eax,%eax
call   1080 <getchar@plt>
cmp    $0x8,%al
je     13a0 <main+0x190>
cmp    $0x1b,%al
je     1369 <main+0x159>
cmp    $0xa,%al
je     1405 <main+0x1f5>
movslq %r12d,%rcx
add    $0x1,%r12d
mov    %r15,%rdi
jmp    1360 <main+0x150>
cs nopw 0x0(%rax,%rax,1)
nop
test   %r12d,%r12d
jle    1369 <main+0x159>
add    $0xffffffff,%r12d
xor    %eax,%eax
mov    %r12,%rcx
mov    %r13,%rdi
jmp    1360 <main+0x150>
mov    0x2c16(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xc42(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xcad(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xc3f(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xc49(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    1503 <main+0x2f3>
lea    0x8(%rsp),%r15
xor    %edi,%edi
mov    %r15,%rsi
call   10d0 <tcgetattr@plt>
mov    0x2b9d(%rip),%rax
mov    (%rax),%eax
mov    0x2bbc(%rip),%rcx
or     (%rcx),%eax
or     %eax,0x8(%rsp)
mov    0x2bb7(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
mov    %r15,%rdx
call   10e0 <tcsetattr@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movslq %r12d,%rax
movb   $0x0,0x20(%rsp,%rax,1)
mov    0x4(%r14),%edi
lea    0x20(%rsp),%rsi
call   1060 <login@plt>
test   %rax,%rax
je     1492 <main+0x282>
mov    0x2b67(%rip),%rax
mov    (%rax),%edi
lea    0xc34(%rip),%rsi
jmp    1484 <main+0x274>
mov    0x2b55(%rip),%rax
mov    (%rax),%edi
lea    0xbe0(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%ebx
jmp    1503 <main+0x2f3>
xor    %eax,%eax
call   1050 <setsid@plt>
xor    %eax,%eax
call   1130 <fork@plt>
test   %ebx,%ebx
je     14e7 <main+0x2d7>
test   %eax,%eax
jne    14eb <main+0x2db>
mov    (%r14),%edi
mov    %edi,%esi
xor    %edx,%edx
call   1110 <execlp@plt>
mov    0x2b15(%rip),%rax
mov    (%rax),%ebx
mov    0x2b04(%rip),%rbp
mov    0x0(%rbp),%edi
call   1120 <strerror@plt>
lea    0xbf0(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0x0(%rbp),%edi
call   1100 <exit@plt>
test   %eax,%eax
je     151c <main+0x30c>
lea    0x10(%rsp),%rsi
xor    %ebx,%ebx
mov    %eax,%edi
xor    %edx,%edx
call   10c0 <waitpid@plt>
mov    0x10(%rsp),%edi
test   %edi,%edi
jne    1517 <main+0x307>
mov    %ebx,%eax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
call   1100 <exit@plt>
movslq %ebp,%rbp
mov    0x18(%rsp),%rbx
lea    (%rbx,%rbp,8),%rsi
mov    (%rbx,%rbp,8),%rdi
call   10f0 <execvp@plt>
mov    0x2a98(%rip),%rax
mov    (%rax),%r15d
mov    (%rbx,%rbp,8),%r14
mov    0x2a82(%rip),%rbp
mov    0x0(%rbp),%edi
call   1120 <strerror@plt>
lea    0xb8c(%rip),%rsi
mov    %r15d,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0x0(%rbp),%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.passwd = type { i32, i32 }
%struct.termios = type { i32 }
@.str = [3 x i8] c"-s\00"
@.str.1 = [3 x i8] c"-h\00"
@stderr = global i32 0
@.str.2 = [33 x i8] c"Usage: sudo [-h] [-s|<command>]\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [27 x i8] c" -s: Access root shell\0A\00"
@.str.5 = [29 x i8] c" -h: Show this help text\0A\00"
@.str.6 = [5 x i8] c"root\00"
@.str.7 = [34 x i8] c"sudo: user 'root' doesn't exist!\0A\00"
@ECHO = global i32 0
@ICANON = global i32 0
@TCSANOW = global i32 0
@.str.8 = [24 x i8] c"[sudo] Enter password: \00"
@stdout = global i32 0
@.str.9 = [4 x i8] c"\08 \08\00"
@.str.10 = [4 x i8] c"\E2\80\A2\00"
@.str.11 = [29 x i8] c"sudo: password is incorrect\0A\00"
@.str.12 = [30 x i8] c"sudo: couldn't run shell: %s\0A\00"
@errno = global i32 0
@.str.13 = [37 x i8] c"sudo: couldn't run command '%s': %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.passwd*
%12 = alloca [256 x i8]
%13 = alloca i8
%14 = alloca %struct.termios
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 1, i32* %10
br label %19
19: ; preds = %49, %2
%20 = load i32, i32* %10
%21 = load i32, i32* %4
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %52
23: ; preds = %19
%24 = load i8**, i8*** %5
%25 = load i32, i32* %10
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%28 = load i8*, i8** %27
%29 = call i32 @strcmp(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%30 = icmp ne i32 %29, 0
br i1 %30, label %32, label %31
31: ; preds = %23
store i32 1, i32* %6
br label %48
32: ; preds = %23
%33 = load i8**, i8*** %5
%34 = load i32, i32* %10
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
%38 = call i32 @strcmp(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%39 = icmp ne i32 %38, 0
br i1 %39, label %41, label %40
40: ; preds = %32
store i32 1, i32* %8
br label %47
41: ; preds = %32
%42 = load i32, i32* %9
%43 = icmp ne i32 %42, 0
br i1 %43, label %46, label %44
44: ; preds = %41
%45 = load i32, i32* %10
store i32 %45, i32* %9
br label %46
46: ; preds = %44, %41
br label %47
47: ; preds = %46, %40
br label %48
48: ; preds = %47, %31
br label %49
49: ; preds = %48
%50 = load i32, i32* %10
%51 = add nsw i32 %50, 1
store i32 %51, i32* %10
br label %19
52: ; preds = %19
%53 = load i32, i32* %7
%54 = icmp ne i32 %53, 0
br i1 %54, label %64, label %55
55: ; preds = %52
%56 = load i32, i32* %8
%57 = icmp ne i32 %56, 0
br i1 %57, label %64, label %58
58: ; preds = %55
%59 = load i32, i32* %9
%60 = icmp ne i32 %59, 0
br i1 %60, label %74, label %61
61: ; preds = %58
%62 = load i32, i32* %6
%63 = icmp ne i32 %62, 0
br i1 %63, label %74, label %64
64: ; preds = %61, %55, %52
%65 = load i32, i32* @stderr
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%67 = load i32, i32* @stderr
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%69 = load i32, i32* @stderr
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%71 = load i32, i32* @stderr
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
%73 = load i32, i32* %7
store i32 %73, i32* %3
br label %221
74: ; preds = %61, %58
%75 = call %struct.passwd* @getpwnam(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
store %struct.passwd* %75, %struct.passwd** %11
%76 = load %struct.passwd*, %struct.passwd** %11
%77 = icmp ne %struct.passwd* %76, null
br i1 %77, label %81, label %78
78: ; preds = %74
%79 = load i32, i32* @stderr
%80 = call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %3
br label %221
81: ; preds = %74
store i32 0, i32* %10
%82 = call i32 @tcgetattr(i32 0, %struct.termios* %14)
%83 = load i32, i32* @ECHO
%84 = load i32, i32* @ICANON
%85 = or i32 %83, %84
%86 = xor i32 %85, -1
%87 = getelementptr inbounds %struct.termios, %struct.termios* %14, i32 0, i32 0
%88 = load i32, i32* %87
%89 = and i32 %88, %86
store i32 %89, i32* %87
%90 = load i32, i32* @TCSANOW
%91 = call i32 @tcsetattr(i32 0, i32 %90, %struct.termios* %14)
%92 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
%93 = load i32, i32* @stdout
%94 = call i32 @fflush(i32 %93)
br label %95
95: ; preds = %130, %81
%96 = load i32, i32* %10
%97 = icmp slt i32 %96, 256
br i1 %97, label %98, label %102
98: ; preds = %95
%99 = call signext i8 (...) @getchar()
store i8 %99, i8* %13
%100 = sext i8 %99 to i32
%101 = icmp ne i32 %100, 10
br label %102
102: ; preds = %98, %95
%103 = phi i1 [ false, %95 ], [ %101, %98 ]
br i1 %103, label %104, label %131
104: ; preds = %102
%105 = load i8, i8* %13
%106 = sext i8 %105 to i32
%107 = icmp eq i32 %106, 8
br i1 %107, label %108, label %118
108: ; preds = %104
%109 = load i32, i32* %10
%110 = icmp sgt i32 %109, 0
br i1 %110, label %111, label %117
111: ; preds = %108
%112 = load i32, i32* %10
%113 = add nsw i32 %112, -1
store i32 %113, i32* %10
%114 = sext i32 %113 to i64
%115 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 %114
store i8 0, i8* %115
%116 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
br label %117
117: ; preds = %111, %108
br label %130
118: ; preds = %104
%119 = load i8, i8* %13
%120 = sext i8 %119 to i32
%121 = icmp ne i32 %120, 27
br i1 %121, label %122, label %129
122: ; preds = %118
%123 = load i8, i8* %13
%124 = load i32, i32* %10
%125 = add nsw i32 %124, 1
store i32 %125, i32* %10
%126 = sext i32 %124 to i64
%127 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 %126
store i8 %123, i8* %127
%128 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
br label %129
129: ; preds = %122, %118
br label %130
130: ; preds = %129, %117
br label %95
131: ; preds = %102
%132 = call i32 @tcgetattr(i32 0, %struct.termios* %14)
%133 = load i32, i32* @ECHO
%134 = load i32, i32* @ICANON
%135 = or i32 %133, %134
%136 = getelementptr inbounds %struct.termios, %struct.termios* %14, i32 0, i32 0
%137 = load i32, i32* %136
%138 = or i32 %137, %135
store i32 %138, i32* %136
%139 = load i32, i32* @TCSANOW
%140 = call i32 @tcsetattr(i32 0, i32 %139, %struct.termios* %14)
%141 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%142 = load i32, i32* %10
%143 = sext i32 %142 to i64
%144 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 %143
store i8 0, i8* %144
%145 = load %struct.passwd*, %struct.passwd** %11
%146 = getelementptr inbounds %struct.passwd, %struct.passwd* %145, i32 0, i32 1
%147 = load i32, i32* %146
%148 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%149 = call i64 @login(i32 %147, i8* %148)
%150 = icmp ne i64 %149, 0
br i1 %150, label %151, label %154
151: ; preds = %131
%152 = load i32, i32* @stderr
%153 = call i32 (i32, i8*, ...) @fprintf(i32 %152, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.11, i64 0, i64 0))
store i32 1, i32* %3
br label %221
154: ; preds = %131
%155 = call i32 (...) @setsid()
%156 = load i32, i32* %6
%157 = icmp ne i32 %156, 0
br i1 %157, label %158, label %185
158: ; preds = %154
%159 = call i32 (...) @fork()
store i32 %159, i32* %15
%160 = icmp eq i32 %159, 0
br i1 %160, label %161, label %175
161: ; preds = %158
%162 = load %struct.passwd*, %struct.passwd** %11
%163 = getelementptr inbounds %struct.passwd, %struct.passwd* %162, i32 0, i32 0
%164 = load i32, i32* %163
%165 = load %struct.passwd*, %struct.passwd** %11
%166 = getelementptr inbounds %struct.passwd, %struct.passwd* %165, i32 0, i32 0
%167 = load i32, i32* %166
%168 = call i32 @execlp(i32 %164, i32 %167, i32 0)
%169 = load i32, i32* @stderr
%170 = load i32, i32* @errno
%171 = call i8* @strerror(i32 %170)
%172 = call i32 (i32, i8*, ...) @fprintf(i32 %169, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.12, i64 0, i64 0), i8* %171)
%173 = load i32, i32* @errno
%174 = call i32 @exit(i32 %173)
unreachable
175: ; preds = %158
%176 = load i32, i32* %15
%177 = call i32 @waitpid(i32 %176, i32* %16, i32 0)
%178 = load i32, i32* %16
%179 = icmp ne i32 %178, 0
br i1 %179, label %180, label %183
180: ; preds = %175
%181 = load i32, i32* %16
%182 = call i32 @exit(i32 %181)
unreachable
183: ; preds = %175
br label %184
184: ; preds = %183
br label %220
185: ; preds = %154
%186 = call i32 (...) @fork()
store i32 %186, i32* %17
%187 = icmp eq i32 %186, 0
br i1 %187, label %188, label %210
188: ; preds = %185
%189 = load i8**, i8*** %5
%190 = load i32, i32* %9
%191 = sext i32 %190 to i64
%192 = getelementptr inbounds i8*, i8** %189, i64 %191
%193 = load i8*, i8** %192
%194 = load i8**, i8*** %5
%195 = load i32, i32* %9
%196 = sext i32 %195 to i64
%197 = getelementptr inbounds i8*, i8** %194, i64 %196
%198 = call i32 @execvp(i8* %193, i8** %197)
%199 = load i32, i32* @stderr
%200 = load i8**, i8*** %5
%201 = load i32, i32* %9
%202 = sext i32 %201 to i64
%203 = getelementptr inbounds i8*, i8** %200, i64 %202
%204 = load i8*, i8** %203
%205 = load i32, i32* @errno
%206 = call i8* @strerror(i32 %205)
%207 = call i32 (i32, i8*, ...) @fprintf(i32 %199, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.13, i64 0, i64 0), i8* %204, i8* %206)
%208 = load i32, i32* @errno
%209 = call i32 @exit(i32 %208)
unreachable
210: ; preds = %185
%211 = load i32, i32* %17
%212 = call i32 @waitpid(i32 %211, i32* %18, i32 0)
%213 = load i32, i32* %18
%214 = icmp ne i32 %213, 0
br i1 %214, label %215, label %218
215: ; preds = %210
%216 = load i32, i32* %18
%217 = call i32 @exit(i32 %216)
unreachable
218: ; preds = %210
br label %219
219: ; preds = %218
br label %220
220: ; preds = %219, %184
store i32 0, i32* %3
br label %221
221: ; preds = %220, %151, %78, %64
%222 = load i32, i32* %3
ret i32 %222
}

LLVM IR (-O2):
%struct.termios = type { i32 }
%struct.passwd = type { i32, i32 }
@.str = [3 x i8] c"-s\00"
@.str.1 = [3 x i8] c"-h\00"
@stderr = global i32 0
@.str.2 = [33 x i8] c"Usage: sudo [-h] [-s|<command>]\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [27 x i8] c" -s: Access root shell\0A\00"
@.str.5 = [29 x i8] c" -h: Show this help text\0A\00"
@.str.6 = [5 x i8] c"root\00"
@.str.7 = [34 x i8] c"sudo: user 'root' doesn't exist!\0A\00"
@ECHO = global i32 0
@ICANON = global i32 0
@TCSANOW = global i32 0
@.str.8 = [24 x i8] c"[sudo] Enter password: \00"
@stdout = global i32 0
@.str.9 = [4 x i8] c"\08 \08\00"
@.str.10 = [4 x i8] c"\E2\80\A2\00"
@.str.11 = [29 x i8] c"sudo: password is incorrect\0A\00"
@.str.12 = [30 x i8] c"sudo: couldn't run shell: %s\0A\00"
@errno = global i32 0
@.str.13 = [37 x i8] c"sudo: couldn't run command '%s': %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [256 x i8]
%4 = alloca %struct.termios
%5 = alloca i32
%6 = alloca i32
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %34
8: ; preds = %2
%9 = zext i32 %0 to i64
br label %10
10: ; preds = %8, %26
%11 = phi i64 [ 1, %8 ], [ %30, %26 ]
%12 = phi i32 [ 0, %8 ], [ %29, %26 ]
%13 = phi i32 [ 0, %8 ], [ %28, %26 ]
%14 = phi i32 [ 0, %8 ], [ %27, %26 ]
%15 = getelementptr inbounds i8*, i8** %1, i64 %11
%16 = load i8*, i8** %15
%17 = tail call i32 @strcmp(i8* dereferenceable(1) %16, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i32 %17, 0
br i1 %18, label %26, label %19
19: ; preds = %10
%20 = tail call i32 @strcmp(i8* dereferenceable(1) %16, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %19
%23 = icmp eq i32 %14, 0
%24 = trunc i64 %11 to i32
%25 = select i1 %23, i32 %24, i32 %14
br label %26
26: ; preds = %22, %19, %10
%27 = phi i32 [ %14, %10 ], [ %14, %19 ], [ %25, %22 ]
%28 = phi i32 [ %13, %10 ], [ 1, %19 ], [ %13, %22 ]
%29 = phi i32 [ 1, %10 ], [ %12, %19 ], [ %12, %22 ]
%30 = add nuw nsw i64 %11, 1
%31 = icmp eq i64 %30, %9
br i1 %31, label %32, label %10
32: ; preds = %26
%33 = icmp eq i32 %28, 0
br i1 %33, label %34, label %40
34: ; preds = %2, %32
%35 = phi i32 [ %29, %32 ], [ 0, %2 ]
%36 = phi i32 [ %27, %32 ], [ 0, %2 ]
%37 = icmp ne i32 %36, 0
%38 = icmp ne i32 %35, 0
%39 = select i1 %37, i1 true, i1 %38
br i1 %39, label %49, label %40
40: ; preds = %34, %32
%41 = load i32, i32* @stderr
%42 = tail call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%43 = load i32, i32* @stderr
%44 = tail call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%45 = load i32, i32* @stderr
%46 = tail call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%47 = load i32, i32* @stderr
%48 = tail call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
br label %158
49: ; preds = %34
%50 = tail call %struct.passwd* @getpwnam(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%51 = icmp eq %struct.passwd* %50, null
br i1 %51, label %52, label %55
52: ; preds = %49
%53 = load i32, i32* @stderr
%54 = tail call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0))
br label %158
55: ; preds = %49
%56 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%57 = bitcast %struct.termios* %4 to i8*
%58 = call i32 @tcgetattr(i32 0, %struct.termios* %4)
%59 = load i32, i32* @ECHO
%60 = load i32, i32* @ICANON
%61 = or i32 %60, %59
%62 = xor i32 %61, -1
%63 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 0
%64 = load i32, i32* %63
%65 = and i32 %64, %62
store i32 %65, i32* %63
%66 = load i32, i32* @TCSANOW
%67 = call i32 @tcsetattr(i32 0, i32 %66, %struct.termios* %4)
%68 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
%69 = load i32, i32* @stdout
%70 = call i32 @fflush(i32 %69)
br label %71
71: ; preds = %55, %89
%72 = phi i32 [ 0, %55 ], [ %90, %89 ]
%73 = call signext i8 (...) @getchar()
switch i8 %73, label %79 [
i8 10, label %92
i8 8, label %74
i8 27, label %89
]
74: ; preds = %71
%75 = icmp sgt i32 %72, 0
br i1 %75, label %76, label %89
76: ; preds = %74
%77 = add nsw i32 %72, -1
%78 = zext i32 %77 to i64
br label %82
79: ; preds = %71
%80 = add nsw i32 %72, 1
%81 = sext i32 %72 to i64
br label %82
82: ; preds = %76, %79
%83 = phi i64 [ %81, %79 ], [ %78, %76 ]
%84 = phi i8 [ %73, %79 ], [ 0, %76 ]
%85 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), %79 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), %76 ]
%86 = phi i32 [ %80, %79 ], [ %77, %76 ]
%87 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %83
store i8 %84, i8* %87
%88 = call i32 @printf(i8* dereferenceable(1) %85)
br label %89
89: ; preds = %82, %71, %74
%90 = phi i32 [ %72, %74 ], [ %72, %71 ], [ %86, %82 ]
%91 = icmp slt i32 %90, 256
br i1 %91, label %71, label %92
92: ; preds = %71, %89
%93 = phi i32 [ %72, %71 ], [ %90, %89 ]
%94 = call i32 @tcgetattr(i32 0, %struct.termios* %4)
%95 = load i32, i32* @ECHO
%96 = load i32, i32* @ICANON
%97 = or i32 %96, %95
%98 = load i32, i32* %63
%99 = or i32 %97, %98
store i32 %99, i32* %63
%100 = load i32, i32* @TCSANOW
%101 = call i32 @tcsetattr(i32 0, i32 %100, %struct.termios* %4)
%102 = call i32 @putchar(i32 10)
%103 = sext i32 %93 to i64
%104 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %103
store i8 0, i8* %104
%105 = getelementptr inbounds %struct.passwd, %struct.passwd* %50, i64 0, i32 1
%106 = load i32, i32* %105
%107 = call i64 @login(i32 %106, i8* %56)
%108 = icmp eq i64 %107, 0
br i1 %108, label %112, label %109
109: ; preds = %92
%110 = load i32, i32* @stderr
%111 = call i32 (i32, i8*, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.11, i64 0, i64 0))
br label %156
112: ; preds = %92
%113 = call i32 (...) @setsid()
%114 = call i32 (...) @fork()
%115 = icmp eq i32 %114, 0
br i1 %38, label %116, label %135
116: ; preds = %112
br i1 %115, label %117, label %127
117: ; preds = %116
%118 = getelementptr inbounds %struct.passwd, %struct.passwd* %50, i64 0, i32 0
%119 = load i32, i32* %118
%120 = call i32 @execlp(i32 %119, i32 %119, i32 0)
%121 = load i32, i32* @stderr
%122 = load i32, i32* @errno
%123 = call i8* @strerror(i32 %122)
%124 = call i32 (i32, i8*, ...) @fprintf(i32 %121, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.12, i64 0, i64 0), i8* %123)
%125 = load i32, i32* @errno
%126 = call i32 @exit(i32 %125)
unreachable
127: ; preds = %116
%128 = bitcast i32* %5 to i8*
%129 = call i32 @waitpid(i32 %114, i32* %5, i32 0)
%130 = load i32, i32* %5
%131 = icmp eq i32 %130, 0
br i1 %131, label %134, label %132
132: ; preds = %127
%133 = call i32 @exit(i32 %130)
unreachable
134: ; preds = %127
br label %156
135: ; preds = %112
br i1 %115, label %136, label %148
136: ; preds = %135
%137 = sext i32 %36 to i64
%138 = getelementptr inbounds i8*, i8** %1, i64 %137
%139 = load i8*, i8** %138
%140 = call i32 @execvp(i8* %139, i8** %138)
%141 = load i32, i32* @stderr
%142 = load i8*, i8** %138
%143 = load i32, i32* @errno
%144 = call i8* @strerror(i32 %143)
%145 = call i32 (i32, i8*, ...) @fprintf(i32 %141, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.13, i64 0, i64 0), i8* %142, i8* %144)
%146 = load i32, i32* @errno
%147 = call i32 @exit(i32 %146)
unreachable
148: ; preds = %135
%149 = bitcast i32* %6 to i8*
%150 = call i32 @waitpid(i32 %114, i32* %6, i32 0)
%151 = load i32, i32* %6
%152 = icmp eq i32 %151, 0
br i1 %152, label %155, label %153
153: ; preds = %148
%154 = call i32 @exit(i32 %151)
unreachable
155: ; preds = %148
br label %156
156: ; preds = %134, %155, %109
%157 = phi i32 [ 1, %109 ], [ 0, %155 ], [ 0, %134 ]
br label %158
158: ; preds = %52, %156, %40
%159 = phi i32 [ 0, %40 ], [ %157, %156 ], [ 1, %52 ]
ret i32 %159
}