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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ execv(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int start_shell(int s) {
  char *name[3];
  dup2(s, 0);
  dup2(s, 1);
  dup2(s, 2);
  name[0] = "/bin/sh";
  name[1] = "-i";
  name[2] = NULL;
  execv(name[0], name);
  exit(EXIT_FAILURE);
  return 0;
}


x86 assembly (clang, -O0):
<start_shell>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
mov    -0x4(%rbp),%edi
mov    $0x2,%esi
call   1030 <dup2@plt>
lea    0xe9a(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe97(%rip),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <execv@plt>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>

x86 assembly (clang, -O2):
<start_shell>:
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
xor    %esi,%esi
call   1030 <dup2@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
mov    %ebx,%edi
mov    $0x2,%esi
call   1030 <dup2@plt>
lea    0xea3(%rip),%rdi
mov    %rdi,(%rsp)
lea    0xea0(%rip),%rax
mov    %rax,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    %rsp,%rsi
call   1050 <execv@plt>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"/bin/sh\00"
@.str.1 = [3 x i8] c"-i\00"
@EXIT_FAILURE = global i32 0
define i32 @start_shell(i32 %0) {
%2 = alloca i32
%3 = alloca [3 x i8*]
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call i32 @dup2(i32 %4, i32 0)
%6 = load i32, i32* %2
%7 = call i32 @dup2(i32 %6, i32 1)
%8 = load i32, i32* %2
%9 = call i32 @dup2(i32 %8, i32 2)
%10 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %10
%11 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %11
%12 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 2
store i8* null, i8** %12
%13 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 0
%14 = load i8*, i8** %13
%15 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 0
%16 = call i32 @execv(i8* %14, i8** %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
}

LLVM IR (-O2):
@.str = [8 x i8] c"/bin/sh\00"
@.str.1 = [3 x i8] c"-i\00"
@EXIT_FAILURE = global i32 0
define i32 @start_shell(i32 %0) {
%2 = alloca [3 x i8*]
%3 = bitcast [3 x i8*]* %2 to i8*
%4 = tail call i32 @dup2(i32 %0, i32 0)
%5 = tail call i32 @dup2(i32 %0, i32 1)
%6 = tail call i32 @dup2(i32 %0, i32 2)
%7 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %7
%8 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %8
%9 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 2
store i8* null, i8** %9
%10 = call i32 @execv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %7)
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
}