#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 passwd {
  int /*<<< orphan*/ pw_uid;
  int /*<<< orphan*/ pw_gid;
  int /*<<< orphan*/ pw_name;
};

/* Variables and functions */
int /*<<< orphan*/ bail(char *);
int /*<<< orphan*/ die();
int /*<<< orphan*/ endgrent();
int /*<<< orphan*/ endpwent();
scalar_t__ execv(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct passwd *getpwnam(char *);
scalar_t__ initgroups(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ setuid(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  int a = 1;
  struct passwd *p;
  if (argc < 3 ||
      (argc > a && (!strcmp("-h", argv[a]) || !strcmp("--help", argv[a]))))
    usage(argv[0]);
  if (!strcmp("--", argv[a]))
    a++;
  if (!(p = getpwnam(argv[a]))) {
    fprintf(stderr, "%s: No such user.\n", argv[0]);
    die();
  }
  if (initgroups(p->pw_name, p->pw_gid))
    bail(argv[0]);
  endgrent();
  if (setuid(p->pw_uid))
    bail(argv[0]);
  endpwent();
  ++a;
  if (execv(argv[a], argv + a))
    bail(argv[a]);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x3,-0x8(%rbp)
jl     1235 <main+0x75>
mov    -0x8(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    1241 <main+0x81>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xdfa(%rip),%rdi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
je     1235 <main+0x75>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xddc(%rip),%rdi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1241 <main+0x81>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1080 <usage@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xdb6(%rip),%rdi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    126b <main+0xab>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <getpwnam@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    12ad <main+0xed>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd6c(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x0,%al
call   10a0 <die@plt>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%esi
call   10d0 <initgroups@plt>
cmp    $0x0,%rax
je     12d6 <main+0x116>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1090 <bail@plt>
mov    $0x0,%al
call   1030 <endgrent@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
call   10c0 <setuid@plt>
cmp    $0x0,%rax
je     12fe <main+0x13e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1090 <bail@plt>
mov    $0x0,%al
call   1070 <endpwent@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
call   10e0 <execv@plt>
cmp    $0x0,%rax
je     1349 <main+0x189>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1090 <bail@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
cmp    $0x3,%edi
jl     11f7 <main+0x37>
mov    0x8(%r14),%rbx
lea    0xe28(%rip),%rdi
mov    %rbx,%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
je     11f7 <main+0x37>
lea    0xe18(%rip),%rdi
mov    %rbx,%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
jne    1203 <main+0x43>
mov    (%r14),%rdi
call   1080 <usage@plt>
mov    0x8(%r14),%rbx
lea    0xe00(%rip),%rdi
mov    %rbx,%rsi
call   1040 <strcmp@plt>
cmp    $0x1,%eax
mov    $0x1,%r15d
adc    $0x0,%r15d
mov    (%r14,%r15,8),%rdi
call   1050 <getpwnam@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    124f <main+0x8f>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xdca(%rip),%rsi
call   1060 <fprintf@plt>
xor    %eax,%eax
call   10a0 <die@plt>
mov    0x4(%rbx),%esi
mov    0x8(%rbx),%edi
call   10d0 <initgroups@plt>
test   %rax,%rax
je     1267 <main+0xa7>
mov    (%r14),%rdi
call   1090 <bail@plt>
xor    %eax,%eax
call   1030 <endgrent@plt>
mov    (%rbx),%edi
call   10c0 <setuid@plt>
test   %rax,%rax
je     1282 <main+0xc2>
mov    (%r14),%rdi
call   1090 <bail@plt>
xor    %eax,%eax
call   1070 <endpwent@plt>
mov    %r15d,%eax
lea    (%r14,%rax,8),%rbx
add    $0x8,%rbx
mov    0x8(%r14,%rax,8),%rdi
mov    %rbx,%rsi
call   10e0 <execv@plt>
test   %rax,%rax
je     12ae <main+0xee>
mov    (%rbx),%rdi
call   1090 <bail@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.passwd = type { i32, i32, i32 }
@.str = [3 x i8] c"-h\00"
@.str.1 = [7 x i8] c"--help\00"
@.str.2 = [3 x i8] c"--\00"
@stderr = global i32 0
@.str.3 = [19 x i8] c"%s: No such user.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.passwd*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 3
br i1 %9, label %30, label %10
10: ; preds = %2
%11 = load i32, i32* %4
%12 = load i32, i32* %6
%13 = icmp sgt i32 %11, %12
br i1 %13, label %14, label %35
14: ; preds = %10
%15 = load i8**, i8*** %5
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %15, i64 %17
%19 = load i8*, i8** %18
%20 = call i32 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %14
%23 = load i8**, i8*** %5
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
%28 = call i32 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %35, label %30
30: ; preds = %22, %14, %2
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 0
%33 = load i8*, i8** %32
%34 = call i32 @usage(i8* %33)
br label %35
35: ; preds = %30, %22, %10
%36 = load i8**, i8*** %5
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %36, i64 %38
%40 = load i8*, i8** %39
%41 = call i32 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %40)
%42 = icmp ne i32 %41, 0
br i1 %42, label %46, label %43
43: ; preds = %35
%44 = load i32, i32* %6
%45 = add nsw i32 %44, 1
store i32 %45, i32* %6
br label %46
46: ; preds = %43, %35
%47 = load i8**, i8*** %5
%48 = load i32, i32* %6
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8*, i8** %47, i64 %49
%51 = load i8*, i8** %50
%52 = call %struct.passwd* @getpwnam(i8* %51)
store %struct.passwd* %52, %struct.passwd** %7
%53 = icmp ne %struct.passwd* %52, null
br i1 %53, label %61, label %54
54: ; preds = %46
%55 = load i32, i32* @stderr
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 0
%58 = load i8*, i8** %57
%59 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %58)
%60 = call i32 (...) @die()
br label %61
61: ; preds = %54, %46
%62 = load %struct.passwd*, %struct.passwd** %7
%63 = getelementptr inbounds %struct.passwd, %struct.passwd* %62, i32 0, i32 2
%64 = load i32, i32* %63
%65 = load %struct.passwd*, %struct.passwd** %7
%66 = getelementptr inbounds %struct.passwd, %struct.passwd* %65, i32 0, i32 1
%67 = load i32, i32* %66
%68 = call i64 @initgroups(i32 %64, i32 %67)
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %75
70: ; preds = %61
%71 = load i8**, i8*** %5
%72 = getelementptr inbounds i8*, i8** %71, i64 0
%73 = load i8*, i8** %72
%74 = call i32 @bail(i8* %73)
br label %75
75: ; preds = %70, %61
%76 = call i32 (...) @endgrent()
%77 = load %struct.passwd*, %struct.passwd** %7
%78 = getelementptr inbounds %struct.passwd, %struct.passwd* %77, i32 0, i32 0
%79 = load i32, i32* %78
%80 = call i64 @setuid(i32 %79)
%81 = icmp ne i64 %80, 0
br i1 %81, label %82, label %87
82: ; preds = %75
%83 = load i8**, i8*** %5
%84 = getelementptr inbounds i8*, i8** %83, i64 0
%85 = load i8*, i8** %84
%86 = call i32 @bail(i8* %85)
br label %87
87: ; preds = %82, %75
%88 = call i32 (...) @endpwent()
%89 = load i32, i32* %6
%90 = add nsw i32 %89, 1
store i32 %90, i32* %6
%91 = load i8**, i8*** %5
%92 = load i32, i32* %6
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i8*, i8** %91, i64 %93
%95 = load i8*, i8** %94
%96 = load i8**, i8*** %5
%97 = load i32, i32* %6
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds i8*, i8** %96, i64 %98
%100 = call i64 @execv(i8* %95, i8** %99)
%101 = icmp ne i64 %100, 0
br i1 %101, label %102, label %109
102: ; preds = %87
%103 = load i8**, i8*** %5
%104 = load i32, i32* %6
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds i8*, i8** %103, i64 %105
%107 = load i8*, i8** %106
%108 = call i32 @bail(i8* %107)
br label %109
109: ; preds = %102, %87
%110 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.passwd = type { i32, i32, i32 }
@.str = [3 x i8] c"-h\00"
@.str.1 = [7 x i8] c"--help\00"
@.str.2 = [3 x i8] c"--\00"
@stderr = global i32 0
@.str.3 = [19 x i8] c"%s: No such user.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %12, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @strcmp(i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* dereferenceable(1) %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %4
%10 = tail call i32 @strcmp(i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* dereferenceable(1) %6)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %9, %4, %2
%13 = load i8*, i8** %1
%14 = tail call i32 @usage(i8* %13)
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
br label %17
17: ; preds = %12, %9
%18 = phi i8* [ %16, %12 ], [ %6, %9 ]
%19 = tail call i32 @strcmp(i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* dereferenceable(1) %18)
%20 = icmp eq i32 %19, 0
%21 = select i1 %20, i32 2, i32 1
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %1, i64 %22
%24 = load i8*, i8** %23
%25 = tail call %struct.passwd* @getpwnam(i8* %24)
%26 = icmp eq %struct.passwd* %25, null
br i1 %26, label %27, label %32
27: ; preds = %17
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %1
%30 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %29)
%31 = tail call i32 (...) @die()
br label %32
32: ; preds = %27, %17
%33 = getelementptr inbounds %struct.passwd, %struct.passwd* %25, i64 0, i32 2
%34 = load i32, i32* %33
%35 = getelementptr inbounds %struct.passwd, %struct.passwd* %25, i64 0, i32 1
%36 = load i32, i32* %35
%37 = tail call i64 @initgroups(i32 %34, i32 %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %42, label %39
39: ; preds = %32
%40 = load i8*, i8** %1
%41 = tail call i32 @bail(i8* %40)
br label %42
42: ; preds = %39, %32
%43 = tail call i32 (...) @endgrent()
%44 = getelementptr inbounds %struct.passwd, %struct.passwd* %25, i64 0, i32 0
%45 = load i32, i32* %44
%46 = tail call i64 @setuid(i32 %45)
%47 = icmp eq i64 %46, 0
br i1 %47, label %51, label %48
48: ; preds = %42
%49 = load i8*, i8** %1
%50 = tail call i32 @bail(i8* %49)
br label %51
51: ; preds = %48, %42
%52 = tail call i32 (...) @endpwent()
%53 = add nuw nsw i32 %21, 1
%54 = zext i32 %53 to i64
%55 = getelementptr inbounds i8*, i8** %1, i64 %54
%56 = load i8*, i8** %55
%57 = tail call i64 @execv(i8* %56, i8** %55)
%58 = icmp eq i64 %57, 0
br i1 %58, label %62, label %59
59: ; preds = %51
%60 = load i8*, i8** %55
%61 = tail call i32 @bail(i8* %60)
br label %62
62: ; preds = %59, %51
%63 = tail call i32 @exit(i32 0)
unreachable
}