#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_shell;
  int /*<<< orphan*/ pw_dir;
  int /*<<< orphan*/ pw_name;
};

/* Variables and functions */
int EXIT_FAILURE;
int chdir(int /*<<< orphan*/);
int /*<<< orphan*/ execlp(int /*<<< orphan*/, int /*<<< orphan*/, char *,
                          char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ geteuid();
struct passwd *getpwuid(int /*<<< orphan*/);
int setenv(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  struct passwd *user;
  if (1 != argc) {
    (void)fprintf(stderr, "Usage: %s\n", argv[0]);
    goto end;
  }
  user = getpwuid(geteuid());
  if (NULL == user)
    goto end;
  if (-1 == setenv("USER", user->pw_name, 1))
    goto end;
  if (-1 == setenv("HOME", user->pw_dir, 1))
    goto end;
  if (-1 == setenv("SHELL", user->pw_shell, 1))
    goto end;
  if (-1 == chdir(user->pw_dir))
    goto end;
  (void)execlp(user->pw_shell, user->pw_shell, "-l", (char *)NULL);
end:
  return EXIT_FAILURE;
}


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)
mov    $0x1,%eax
cmp    -0x8(%rbp),%eax
je     11a5 <main+0x45>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe65(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1287 <main+0x127>
mov    $0x0,%al
call   1060 <geteuid@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    11c8 <main+0x68>
jmp    1287 <main+0x127>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%esi
lea    0xe35(%rip),%rdi
mov    $0x1,%edx
call   1030 <setenv@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11f4 <main+0x94>
jmp    1287 <main+0x127>
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%esi
lea    0xe0e(%rip),%rdi
mov    $0x1,%edx
call   1030 <setenv@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1220 <main+0xc0>
jmp    1287 <main+0x127>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    0xde8(%rip),%rdi
mov    $0x1,%edx
call   1030 <setenv@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    124b <main+0xeb>
jmp    1287 <main+0x127>
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edi
call   1050 <chdir@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    126b <main+0x10b>
jmp    1287 <main+0x127>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    0xd9d(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1080 <execlp@plt>
mov    0x2d4a(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x1,%edi
jne    11ef <main+0x8f>
xor    %eax,%eax
call   1060 <geteuid@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
test   %rax,%rax
je     1207 <main+0xa7>
mov    %rax,%rbx
mov    0x8(%rax),%esi
lea    0xe7d(%rip),%rdi
mov    $0x1,%edx
call   1030 <setenv@plt>
cmp    $0xffffffff,%eax
je     1207 <main+0xa7>
mov    0x4(%rbx),%esi
lea    0xe69(%rip),%rdi
mov    $0x1,%edx
call   1030 <setenv@plt>
cmp    $0xffffffff,%eax
je     1207 <main+0xa7>
mov    (%rbx),%esi
lea    0xe56(%rip),%rdi
mov    $0x1,%edx
call   1030 <setenv@plt>
cmp    $0xffffffff,%eax
je     1207 <main+0xa7>
mov    0x4(%rbx),%edi
call   1050 <chdir@plt>
cmp    $0xffffffff,%eax
je     1207 <main+0xa7>
mov    (%rbx),%edi
lea    0xe37(%rip),%rdx
mov    %edi,%esi
xor    %ecx,%ecx
call   1080 <execlp@plt>
jmp    1207 <main+0xa7>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xdfe(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.passwd = type { i32, i32, i32 }
@stderr = global i32 0
@.str = [11 x i8] c"Usage: %s\0A\00"
@.str.1 = [5 x i8] c"USER\00"
@.str.2 = [5 x i8] c"HOME\00"
@.str.3 = [6 x i8] c"SHELL\00"
@.str.4 = [3 x i8] c"-l\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.passwd*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 1, %7
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %57
15: ; preds = %2
%16 = call i32 (...) @geteuid()
%17 = call %struct.passwd* @getpwuid(i32 %16)
store %struct.passwd* %17, %struct.passwd** %6
%18 = load %struct.passwd*, %struct.passwd** %6
%19 = icmp eq %struct.passwd* null, %18
br i1 %19, label %20, label %21
20: ; preds = %15
br label %57
21: ; preds = %15
%22 = load %struct.passwd*, %struct.passwd** %6
%23 = getelementptr inbounds %struct.passwd, %struct.passwd* %22, i32 0, i32 2
%24 = load i32, i32* %23
%25 = call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 1)
%26 = icmp eq i32 -1, %25
br i1 %26, label %27, label %28
27: ; preds = %21
br label %57
28: ; preds = %21
%29 = load %struct.passwd*, %struct.passwd** %6
%30 = getelementptr inbounds %struct.passwd, %struct.passwd* %29, i32 0, i32 1
%31 = load i32, i32* %30
%32 = call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %31, i32 1)
%33 = icmp eq i32 -1, %32
br i1 %33, label %34, label %35
34: ; preds = %28
br label %57
35: ; preds = %28
%36 = load %struct.passwd*, %struct.passwd** %6
%37 = getelementptr inbounds %struct.passwd, %struct.passwd* %36, i32 0, i32 0
%38 = load i32, i32* %37
%39 = call i32 @setenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %38, i32 1)
%40 = icmp eq i32 -1, %39
br i1 %40, label %41, label %42
41: ; preds = %35
br label %57
42: ; preds = %35
%43 = load %struct.passwd*, %struct.passwd** %6
%44 = getelementptr inbounds %struct.passwd, %struct.passwd* %43, i32 0, i32 1
%45 = load i32, i32* %44
%46 = call i32 @chdir(i32 %45)
%47 = icmp eq i32 -1, %46
br i1 %47, label %48, label %49
48: ; preds = %42
br label %57
49: ; preds = %42
%50 = load %struct.passwd*, %struct.passwd** %6
%51 = getelementptr inbounds %struct.passwd, %struct.passwd* %50, i32 0, i32 0
%52 = load i32, i32* %51
%53 = load %struct.passwd*, %struct.passwd** %6
%54 = getelementptr inbounds %struct.passwd, %struct.passwd* %53, i32 0, i32 0
%55 = load i32, i32* %54
%56 = call i32 @execlp(i32 %52, i32 %55, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* null)
br label %57
57: ; preds = %49, %48, %41, %34, %27, %20, %9
%58 = load i32, i32* @EXIT_FAILURE
ret i32 %58
}

LLVM IR (-O2):
%struct.passwd = type { i32, i32, i32 }
@stderr = global i32 0
@.str = [11 x i8] c"Usage: %s\0A\00"
@.str.1 = [5 x i8] c"USER\00"
@.str.2 = [5 x i8] c"HOME\00"
@.str.3 = [6 x i8] c"SHELL\00"
@.str.4 = [3 x i8] c"-l\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %34
8: ; preds = %2
%9 = tail call i32 (...) @geteuid()
%10 = tail call %struct.passwd* @getpwuid(i32 %9)
%11 = icmp eq %struct.passwd* %10, null
br i1 %11, label %34, label %12
12: ; preds = %8
%13 = getelementptr inbounds %struct.passwd, %struct.passwd* %10, i64 0, i32 2
%14 = load i32, i32* %13
%15 = tail call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 1)
%16 = icmp eq i32 %15, -1
br i1 %16, label %34, label %17
17: ; preds = %12
%18 = getelementptr inbounds %struct.passwd, %struct.passwd* %10, i64 0, i32 1
%19 = load i32, i32* %18
%20 = tail call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %19, i32 1)
%21 = icmp eq i32 %20, -1
br i1 %21, label %34, label %22
22: ; preds = %17
%23 = getelementptr inbounds %struct.passwd, %struct.passwd* %10, i64 0, i32 0
%24 = load i32, i32* %23
%25 = tail call i32 @setenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %24, i32 1)
%26 = icmp eq i32 %25, -1
br i1 %26, label %34, label %27
27: ; preds = %22
%28 = load i32, i32* %18
%29 = tail call i32 @chdir(i32 %28)
%30 = icmp eq i32 %29, -1
br i1 %30, label %34, label %31
31: ; preds = %27
%32 = load i32, i32* %23
%33 = tail call i32 @execlp(i32 %32, i32 %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* null)
br label %34
34: ; preds = %27, %22, %17, %12, %8, %31, %4
%35 = load i32, i32* @EXIT_FAILURE
ret i32 %35
}