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

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ run_as(char *, char *, int);
int /*<<< orphan*/ sleep(int);
scalar_t__ strcmp(char *, char *);
int main(int argc, char **argv) {
  char *user = NULL;
  char errbuf[128];
  if (argc == 2) {
    if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) {
      printf("usage: %s <username>\n", argv[0]);
      printf("example: %s nobody\n", argv[0]);
      exit(0);
    }
    user = argv[1];
  }
  if (run_as(user, errbuf, sizeof(errbuf)) != 0)
    printf("%s\n", errbuf);
  else
    printf("run as %s\n", user == NULL ? "normal" : user);
  while (1) {
    sleep(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11f0 <main+0xa0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe76(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11b7 <main+0x67>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5b(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11e4 <main+0x94>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe45(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe48(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
mov    $0x80,%edx
call   1030 <run_as@plt>
cmp    $0x0,%rax
je     1227 <main+0xd7>
lea    -0xa0(%rbp),%rsi
lea    0xe1e(%rip),%rdi
call   1040 <printf@plt>
jmp    1263 <main+0x113>
cmpq   $0x0,-0x18(%rbp)
jne    1245 <main+0xf5>
lea    0xe06(%rip),%rax
mov    %rax,-0xa8(%rbp)
jmp    1250 <main+0x100>
mov    -0x18(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0xa8(%rbp),%rsi
lea    0xdd6(%rip),%rdi
call   1040 <printf@plt>
jmp    1268 <main+0x118>
mov    $0x1,%edi
call   1070 <sleep@plt>
jmp    1268 <main+0x118>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x80,%rsp
cmp    $0x2,%edi
jne    1190 <main+0x40>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe95(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11dc <main+0x8c>
mov    0x8(%rbx),%rdi
lea    0xe83(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11dc <main+0x8c>
mov    0x8(%rbx),%rbx
jmp    1192 <main+0x42>
xor    %ebx,%ebx
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0x80,%edx
call   1030 <run_as@plt>
test   %rax,%rax
je     11b3 <main+0x63>
lea    0xe8d(%rip),%rdi
mov    %rsp,%rsi
jmp    11c8 <main+0x78>
test   %rbx,%rbx
lea    0xe82(%rip),%rsi
cmovne %rbx,%rsi
lea    0xe6c(%rip),%rdi
call   1040 <printf@plt>
nopl   (%rax)
mov    $0x1,%edi
call   1070 <sleep@plt>
jmp    11d0 <main+0x80>
mov    (%rbx),%rsi
lea    0xe24(%rip),%rdi
call   1040 <printf@plt>
mov    (%rbx),%rsi
lea    0xe2b(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"-h\00"
@.str.1 = [7 x i8] c"--help\00"
@.str.2 = [22 x i8] c"usage: %s <username>\0A\00"
@.str.3 = [20 x i8] c"example: %s nobody\0A\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [11 x i8] c"run as %s\0A\00"
@.str.6 = [7 x i8] c"normal\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [128 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 2
br i1 %9, label %10, label %36
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %22, label %16
16: ; preds = %10
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %32
22: ; preds = %16, %10
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %29)
%31 = call i32 @exit(i32 0)
unreachable
32: ; preds = %16
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
store i8* %35, i8** %6
br label %36
36: ; preds = %32, %2
%37 = load i8*, i8** %6
%38 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%39 = call i64 @run_as(i8* %37, i8* %38, i32 128)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %36
%42 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%43 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %42)
br label %53
44: ; preds = %36
%45 = load i8*, i8** %6
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %48
47: ; preds = %44
br label %50
48: ; preds = %44
%49 = load i8*, i8** %6
br label %50
50: ; preds = %48, %47
%51 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), %47 ], [ %49, %48 ]
%52 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %51)
br label %53
53: ; preds = %50, %41
br label %54
54: ; preds = %53, %54
%55 = call i32 @sleep(i32 1)
br label %54
}

LLVM IR (-O2):
@.str = [3 x i8] c"-h\00"
@.str.1 = [7 x i8] c"--help\00"
@.str.2 = [22 x i8] c"usage: %s <username>\0A\00"
@.str.3 = [20 x i8] c"example: %s nobody\0A\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [11 x i8] c"run as %s\0A\00"
@.str.6 = [7 x i8] c"normal\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %23
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %6
%12 = load i8*, i8** %7
%13 = tail call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %11, %6
%16 = load i8*, i8** %1
%17 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %1
%19 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %18)
%20 = tail call i32 @exit(i32 0)
unreachable
21: ; preds = %11
%22 = load i8*, i8** %7
br label %23
23: ; preds = %21, %2
%24 = phi i8* [ %22, %21 ], [ null, %2 ]
%25 = call i64 @run_as(i8* %24, i8* %4, i32 128)
%26 = icmp eq i64 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %23
%28 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %4)
br label %33
29: ; preds = %23
%30 = icmp eq i8* %24, null
%31 = select i1 %30, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %24
%32 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %29, %27
br label %34
34: ; preds = %33, %34
%35 = call i32 @sleep(i32 1)
br label %34
}