#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*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ execve(char *, char **, int /*<<< orphan*/ *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(void) {
  struct sockaddr_in srvFd;
  srvFd.sin_family = AF_INET;
  srvFd.sin_port = htons(8888);
  srvFd.sin_addr.s_addr = htonl(INADDR_ANY);
  int srvSoc = socket(AF_INET, SOCK_STREAM, 0);
  bind(srvSoc, (struct sockaddr *)&srvFd, 16);
  listen(srvSoc, 1);
  int clientSoc = accept(srvSoc, NULL, NULL);
  dup2(clientSoc, 1);
  char *argv[] = {"/bin/ls", NULL};
  execve(argv[0], &argv[0], NULL);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    $0x22b8,%edi
call   1030 <htons@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x10(%rbp)
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x10,%edx
call   1080 <bind@plt>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1070 <listen@plt>
mov    -0x14(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1090 <accept@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
mov    $0x1,%esi
call   1040 <dup2@plt>
mov    0x2bd7(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2bd4(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <execve@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
mov    0x2e54(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    $0x22b8,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,(%rsp)
mov    (%rbx),%edi
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x10,%edx
call   1080 <bind@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   1070 <listen@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <accept@plt>
mov    %eax,%edi
mov    $0x1,%esi
call   1040 <dup2@plt>
movaps 0x2bf2(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xdf6(%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 { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@SOCK_STREAM = global i32 0
@.str = [8 x i8] c"/bin/ls\00"
@__const.main.argv = [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 %struct.sockaddr_in
%3 = alloca i32
%4 = alloca i32
%5 = alloca [2 x i8*]
store i32 0, i32* %1
%6 = load i32, i32* @AF_INET
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 2
store i32 %6, i32* %7
%8 = call i32 @htons(i32 8888)
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 1
store i32 %8, i32* %9
%10 = load i32, i32* @INADDR_ANY
%11 = call i32 @htonl(i32 %10)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
%13 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %12, i32 0, i32 0
store i32 %11, i32* %13
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
store i32 %16, i32* %3
%17 = load i32, i32* %3
%18 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%19 = call i32 @bind(i32 %17, %struct.sockaddr* %18, i32 16)
%20 = load i32, i32* %3
%21 = call i32 @listen(i32 %20, i32 1)
%22 = load i32, i32* %3
%23 = call i32 @accept(i32 %22, i32* null, i32* null)
store i32 %23, i32* %4
%24 = load i32, i32* %4
%25 = call i32 @dup2(i32 %24, i32 1)
%26 = bitcast [2 x i8*]* %5 to i8*
%27 = getelementptr inbounds [2 x i8*], [2 x i8*]* %5, i64 0, i64 0
%28 = load i8*, i8** %27
%29 = getelementptr inbounds [2 x i8*], [2 x i8*]* %5, i64 0, i64 0
%30 = call i32 @execve(i8* %28, i8** %29, 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 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@SOCK_STREAM = global i32 0
@.str = [8 x i8] c"/bin/ls\00"
@__const.main.argv = [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 [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 2
store i32 %4, i32* %5
%6 = tail call i32 @htons(i32 8888)
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %6, i32* %7
%8 = load i32, i32* @INADDR_ANY
%9 = tail call i32 @htonl(i32 %8)
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %9, i32* %10
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = tail call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%15 = call i32 @bind(i32 %13, %struct.sockaddr* %14, i32 16)
%16 = call i32 @listen(i32 %13, i32 1)
%17 = call i32 @accept(i32 %13, i32* null, i32* null)
%18 = call i32 @dup2(i32 %17, i32 1)
%19 = bitcast [2 x i8*]* %2 to i8*
%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, i32* null)
ret i32 0
}