#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;
};
typedef int socklen_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(int /*<<< orphan*/, char, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ stunGetPublicIP(char *, char *);
void sendRuleToHop(char *src, char *dst, char *hop, int port, int type) {
  stunGetPublicIP(src, src);
  if (1)
    printf("Going to send rule to hop %s on port %d\n", hop, port);
  int fwdSocket;
  struct sockaddr_in serverAddr;
  socklen_t addr_size;
  char rule[100];
  if (type == 1) {
    strcpy(rule, "A-");
  } else {
    strcpy(rule, "D-");
  }
  strcat(rule, src);
  strcat(rule, "-");
  strcat(rule, dst);
  if (1)
    printf("Preparing to send rule:%s\n", rule);
  fwdSocket = socket(AF_INET, SOCK_STREAM, 0);
  serverAddr.sin_family = AF_INET;
  serverAddr.sin_port = htons(port);
  serverAddr.sin_addr.s_addr = inet_addr(hop);
  memset(serverAddr.sin_zero, '\0', sizeof serverAddr.sin_zero);
  addr_size = sizeof serverAddr;
  int result = connect(fwdSocket, (struct sockaddr *)&serverAddr, addr_size);
  if (1)
    printf("Result of connection: %d\n", result);
  if (1)
    printf("Connecting to socket\n");
  send(fwdSocket, rule, 128, 0);
  bzero(rule, 128);
  while (recv(fwdSocket, rule, 128, 0)) {
    printf("Strlen of buffer:%d\n", (int)strlen(rule));
    if (strlen(rule) > 0)
      break;
  }
  close(fwdSocket);
}


x86 assembly (clang, -O0):
<sendRuleToHop>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   10c0 <stunGetPublicIP@plt>
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
cmpl   $0x1,-0x20(%rbp)
jne    1242 <sendRuleToHop+0x62>
lea    -0xa0(%rbp),%rdi
lea    0xdf1(%rip),%rsi
call   1040 <strcpy@plt>
jmp    1255 <sendRuleToHop+0x75>
lea    -0xa0(%rbp),%rdi
lea    0xddc(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   10e0 <strcat@plt>
lea    -0xa0(%rbp),%rdi
lea    0xdb7(%rip),%rsi
call   10e0 <strcat@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10e0 <strcat@plt>
lea    -0xa0(%rbp),%rsi
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
mov    0x2d2b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x24(%rbp)
mov    0x2d28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,-0x34(%rbp)
mov    -0x38(%rbp),%edi
xor    %esi,%esi
mov    $0x4,%edx
call   1090 <memset@plt>
movl   $0x10,-0x3c(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    -0x3c(%rbp),%edx
call   10f0 <connect@plt>
mov    %eax,-0xa4(%rbp)
mov    -0xa4(%rbp),%esi
lea    0xd36(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xd42(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x24(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
lea    -0xa0(%rbp),%rdi
mov    $0x80,%esi
call   10d0 <bzero@plt>
mov    -0x24(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x0,%rax
je     13ac <sendRuleToHop+0x1cc>
lea    -0xa0(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%esi
lea    0xcf5(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0xa0(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
jle    13a7 <sendRuleToHop+0x1c7>
jmp    13ac <sendRuleToHop+0x1cc>
jmp    1350 <sendRuleToHop+0x170>
mov    -0x24(%rbp),%edi
call   10a0 <close@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendRuleToHop>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    %r8d,%ebx
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbp
mov    %rdi,%rsi
call   10d0 <stunGetPublicIP@plt>
lea    0xde3(%rip),%rdi
mov    %r14,%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1090 <printf@plt>
cmp    $0x1,%ebx
lea    0xdf5(%rip),%rax
lea    0xdf1(%rip),%rsi
cmove  %rax,%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10f0 <strcat@plt>
lea    0xdcc(%rip),%rsi
mov    %rbx,%rdi
call   10f0 <strcat@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10f0 <strcat@plt>
lea    0xdb7(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    0x2d5f(%rip),%r12
mov    (%r12),%edi
mov    0x2d44(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,%ebp
mov    (%r12),%eax
mov    %eax,0xc(%rsp)
mov    %r15d,%edi
call   1070 <htons@plt>
mov    %eax,0x8(%rsp)
mov    %r14,%rdi
call   10c0 <inet_addr@plt>
mov    %eax,0x4(%rsp)
xor    %esi,%esi
mov    $0x4,%edx
call   10a0 <memset@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x10,%edx
call   1100 <connect@plt>
lea    0xd69(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0xd88(%rip),%rdi
call   1050 <puts@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
mov    %rbx,%rdi
mov    $0x80,%esi
call   10e0 <bzero@plt>
lea    0xd49(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
je     1357 <sendRuleToHop+0x167>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
test   %rax,%rax
jle    1320 <sendRuleToHop+0x130>
mov    %ebp,%edi
call   10b0 <close@plt>
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [41 x i8] c"Going to send rule to hop %s on port %d\0A\00"
@.str.1 = [3 x i8] c"A-\00"
@.str.2 = [3 x i8] c"D-\00"
@.str.3 = [2 x i8] c"-\00"
@.str.4 = [27 x i8] c"Preparing to send rule:%s\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.5 = [26 x i8] c"Result of connection: %d\0A\00"
@.str.6 = [22 x i8] c"Connecting to socket\0A\00"
@.str.7 = [21 x i8] c"Strlen of buffer:%d\0A\00"
define void @sendRuleToHop(i8* %0, i8* %1, i8* %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.sockaddr_in
%13 = alloca i32
%14 = alloca [100 x i8]
%15 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%16 = load i8*, i8** %6
%17 = load i8*, i8** %6
%18 = call i32 @stunGetPublicIP(i8* %16, i8* %17)
%19 = load i8*, i8** %8
%20 = load i32, i32* %9
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %19, i32 %20)
%22 = load i32, i32* %10
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %27
24: ; preds = %5
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%26 = call i32 @strcpy(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %30
27: ; preds = %5
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%29 = call i32 @strcpy(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %30
30: ; preds = %27, %24
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%32 = load i8*, i8** %6
%33 = call i32 @strcat(i8* %31, i8* %32)
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%35 = call i32 @strcat(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%36 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%37 = load i8*, i8** %7
%38 = call i32 @strcat(i8* %36, i8* %37)
%39 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %39)
%41 = load i32, i32* @AF_INET
%42 = load i32, i32* @SOCK_STREAM
%43 = call i32 @socket(i32 %41, i32 %42, i32 0)
store i32 %43, i32* %11
%44 = load i32, i32* @AF_INET
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 3
store i32 %44, i32* %45
%46 = load i32, i32* %9
%47 = call i32 @htons(i32 %46)
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 2
store i32 %47, i32* %48
%49 = load i8*, i8** %8
%50 = call i32 @inet_addr(i8* %49)
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
%52 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %51, i32 0, i32 0
store i32 %50, i32* %52
%53 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
%54 = load i32, i32* %53
%55 = call i32 @memset(i32 %54, i8 signext 0, i32 4)
store i32 16, i32* %13
%56 = load i32, i32* %11
%57 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%58 = load i32, i32* %13
%59 = call i32 @connect(i32 %56, %struct.sockaddr* %57, i32 %58)
store i32 %59, i32* %15
%60 = load i32, i32* %15
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %60)
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%63 = load i32, i32* %11
%64 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%65 = call i32 @send(i32 %63, i8* %64, i32 128, i32 0)
%66 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%67 = call i32 @bzero(i8* %66, i32 128)
br label %68
68: ; preds = %82, %30
%69 = load i32, i32* %11
%70 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%71 = call i64 @recv(i32 %69, i8* %70, i32 128, i32 0)
%72 = icmp ne i64 %71, 0
br i1 %72, label %73, label %83
73: ; preds = %68
%74 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%75 = call i64 @strlen(i8* %74)
%76 = trunc i64 %75 to i32
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i32 %76)
%78 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%79 = call i64 @strlen(i8* %78)
%80 = icmp sgt i64 %79, 0
br i1 %80, label %81, label %82
81: ; preds = %73
br label %83
82: ; preds = %73
br label %68
83: ; preds = %81, %68
%84 = load i32, i32* %11
%85 = call i32 @close(i32 %84)
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [41 x i8] c"Going to send rule to hop %s on port %d\0A\00"
@.str.1 = [3 x i8] c"A-\00"
@.str.2 = [3 x i8] c"D-\00"
@.str.3 = [2 x i8] c"-\00"
@.str.4 = [27 x i8] c"Preparing to send rule:%s\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.5 = [26 x i8] c"Result of connection: %d\0A\00"
@.str.7 = [21 x i8] c"Strlen of buffer:%d\0A\00"
@str = [21 x i8] c"Connecting to socket\00"
define void @sendRuleToHop(i8* %0, i8* %1, i8* %2, i32 %3, i32 %4) {
%6 = alloca %struct.sockaddr_in
%7 = alloca [100 x i8]
%8 = tail call i32 @stunGetPublicIP(i8* %0, i8* %0)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %2, i32 %3)
%10 = bitcast %struct.sockaddr_in* %6 to i8*
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%12 = icmp eq i32 %4, 1
%13 = select i1 %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
%14 = call i32 @strcpy(i8* %11, i8* %13)
%15 = call i32 @strcat(i8* %11, i8* %0)
%16 = call i32 @strcat(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 @strcat(i8* %11, i8* %1)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %11)
%19 = load i32, i32* @AF_INET
%20 = load i32, i32* @SOCK_STREAM
%21 = call i32 @socket(i32 %19, i32 %20, i32 0)
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 3
store i32 %22, i32* %23
%24 = call i32 @htons(i32 %3)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 2
store i32 %24, i32* %25
%26 = call i32 @inet_addr(i8* %2)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 1, i32 0
store i32 %26, i32* %27
%28 = call i32 @memset(i32 undef, i8 signext 0, i32 4)
%29 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%30 = call i32 @connect(i32 %21, %struct.sockaddr* %29, i32 16)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %30)
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%33 = call i32 @send(i32 %21, i8* %11, i32 128, i32 0)
%34 = call i32 @bzero(i8* %11, i32 128)
br label %35
35: ; preds = %38, %5
%36 = call i64 @recv(i32 %21, i8* %11, i32 128, i32 0)
%37 = icmp eq i64 %36, 0
br i1 %37, label %44, label %38
38: ; preds = %35
%39 = call i64 @strlen(i8* %11)
%40 = trunc i64 %39 to i32
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i32 %40)
%42 = call i64 @strlen(i8* %11)
%43 = icmp sgt i64 %42, 0
br i1 %43, label %44, label %35
44: ; preds = %38, %35
%45 = call i32 @close(i32 %21)
ret void
}