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

/* Variables and functions */
int /*<<< orphan*/ SIGKILL;
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ getppid();
int /*<<< orphan*/ htons(short);
int /*<<< orphan*/ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ shell(int);
int socket(int, int, int);
void callback(short port) {
  struct sockaddr_in sin;
  int s, slen = 16;
  sin.sin_family = 2;
  sin.sin_addr.s_addr = 0;
  sin.sin_port = htons(port);
  s = socket(2, 1, 6);
  if (bind(s, (struct sockaddr *)&sin, 16)) {
    kill(getppid(), SIGKILL);
    {
      perror("[-] shell.bind");
      exit(1);
    };
  }
  listen(s, 1);
  s = accept(s, (struct sockaddr *)&sin, &slen);
  shell(s);
  printf("crap\n");
}


x86 assembly (clang, -O0):
<callback>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
movl   $0x10,-0x20(%rbp)
movl   $0x2,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
movswl -0x2(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    $0x2,%edi
mov    $0x1,%esi
mov    $0x6,%edx
call   10d0 <socket@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   1070 <bind@plt>
cmp    $0x0,%rax
je     1240 <callback+0x90>
mov    $0x0,%al
call   10a0 <getppid@plt>
mov    %eax,%edi
mov    0x2dbd(%rip),%rax
mov    (%rax),%esi
call   1050 <kill@plt>
lea    0xdcf(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x1c(%rbp),%edi
mov    $0x1,%esi
call   1060 <listen@plt>
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1090 <accept@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   10c0 <shell@plt>
lea    0xda0(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<callback>:
push   %rbx
sub    $0x20,%rsp
movl   $0x10,0xc(%rsp)
movl   $0x2,0x10(%rsp)
movq   $0x0,0x18(%rsp)
call   1040 <htons@plt>
mov    %eax,0x14(%rsp)
mov    $0x2,%edi
mov    $0x1,%esi
mov    $0x6,%edx
call   10d0 <socket@plt>
mov    %eax,%ebx
lea    0x10(%rsp),%rsi
mov    %eax,%edi
mov    $0x10,%edx
call   1070 <bind@plt>
test   %rax,%rax
jne    1239 <callback+0x89>
mov    %ebx,%edi
mov    $0x1,%esi
call   1060 <listen@plt>
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   1090 <accept@plt>
mov    %eax,%edi
call   10c0 <shell@plt>
lea    0xde1(%rip),%rdi
call   1030 <puts@plt>
add    $0x20,%rsp
pop    %rbx
ret
xor    %eax,%eax
call   10a0 <getppid@plt>
mov    0x2d99(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1050 <kill@plt>
lea    0xda9(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64 }
%struct.sockaddr = type { i32 }
@SIGKILL = global i32 0
@.str = [15 x i8] c"[-] shell.bind\00"
@.str.1 = [6 x i8] c"crap\0A\00"
define void @callback(i16 signext %0) {
%2 = alloca i16
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca i32
store i16 %0, i16* %2
store i32 16, i32* %5
%6 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 2, i32* %6
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
%8 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %7, i32 0, i32 0
store i64 0, i64* %8
%9 = load i16, i16* %2
%10 = call i32 @htons(i16 signext %9)
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %10, i32* %11
%12 = call i32 @socket(i32 2, i32 1, i32 6)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%15 = call i64 @bind(i32 %13, %struct.sockaddr* %14, i32 16)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %1
%18 = call i32 (...) @getppid()
%19 = load i32, i32* @SIGKILL
%20 = call i32 @kill(i32 %18, i32 %19)
%21 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %1
%24 = load i32, i32* %4
%25 = call i32 @listen(i32 %24, i32 1)
%26 = load i32, i32* %4
%27 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%28 = call i32 @accept(i32 %26, %struct.sockaddr* %27, i32* %5)
store i32 %28, i32* %4
%29 = load i32, i32* %4
%30 = call i32 @shell(i32 %29)
%31 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64 }
%struct.sockaddr = type { i32 }
@SIGKILL = global i32 0
@.str = [15 x i8] c"[-] shell.bind\00"
@str = [5 x i8] c"crap\00"
define void @callback(i16 signext %0) {
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = bitcast %struct.sockaddr_in* %2 to i8*
%5 = bitcast i32* %3 to i8*
store i32 16, i32* %3
%6 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
store i32 2, i32* %6
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2, i32 0
store i64 0, i64* %7
%8 = tail call i32 @htons(i16 signext %0)
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %8, i32* %9
%10 = tail call i32 @socket(i32 2, i32 1, i32 6)
%11 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%12 = call i64 @bind(i32 %10, %struct.sockaddr* %11, i32 16)
%13 = icmp eq i64 %12, 0
br i1 %13, label %20, label %14
14: ; preds = %1
%15 = call i32 (...) @getppid()
%16 = load i32, i32* @SIGKILL
%17 = call i32 @kill(i32 %15, i32 %16)
%18 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %1
%21 = call i32 @listen(i32 %10, i32 1)
%22 = call i32 @accept(i32 %10, %struct.sockaddr* %11, i32* %3)
%23 = call i32 @shell(i32 %22)
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
ret void
}