#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*/ dup2(int, int);
int /*<<< orphan*/ execv(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *);
int start_shell(int s) {
  char *name[3];
  printf("+ Starting shell\n");
  dup2(s, 0);
  dup2(s, 1);
  dup2(s, 2);
  name[0] = "/bin/sh";
  name[1] = "-i";
  name[2] = NULL;
  execv(name[0], name);
  exit(1);
  return 0;
}


x86 assembly (clang, -O0):
<start_shell>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    0xeae(%rip),%rdi
call   1040 <printf@plt>
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    0xe90(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe8d(%rip),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <execv@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

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

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

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