#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 {
  short sin_port;
  TYPE_1__ sin_addr;
  void *sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ servaddr;
typedef int /*<<< orphan*/ localaddr;
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ bindingReq;

/* Variables and functions */
void *AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
short bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int htonl(int);
short htons(short);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ inet_pton(void *, char *, TYPE_1__ *);
short ntohs(short);
int /*<<< orphan*/ printf(char *);
short recvfrom(int, unsigned char *, int, int /*<<< orphan*/,
               int /*<<< orphan*/ *, int /*<<< orphan*/);
short sendto(int, unsigned char *, int, int /*<<< orphan*/, struct sockaddr *,
             int);
int /*<<< orphan*/ sleep(int);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char, unsigned char,
                           unsigned char, unsigned char);
int stunGetPublicIP(char *return_ip_port, char *localaddr2) {
  struct sockaddr_in servaddr;
  struct sockaddr_in localaddr;
  unsigned char buf[200];
  int sockfd, i;
  unsigned char bindingReq[20];
  int stun_method, msg_length;
  short attr_type;
  short attr_length;
  short port;
  short n;
  char *stun_server_ip = "173.194.65.127";
  short stun_server_port = 19302;
  short local_port = 8888;
  sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  inet_pton(AF_INET, stun_server_ip, &servaddr.sin_addr);
  servaddr.sin_port = htons(stun_server_port);
  bzero(&localaddr, sizeof(localaddr));
  localaddr.sin_family = AF_INET;
  localaddr.sin_port = htons(local_port);
  if (localaddr2 != NULL) {
    localaddr.sin_addr.s_addr = inet_addr(localaddr2);
  }
  n = bind(sockfd, (struct sockaddr *)&localaddr, sizeof(localaddr));
  *(short *)(&bindingReq[0]) = htons(0x0001);
  *(short *)(&bindingReq[2]) = htons(0x0000);
  *(int *)(&bindingReq[4]) = htonl(0x2112A442);
  *(int *)(&bindingReq[8]) = htonl(0x63c7117e);
  *(int *)(&bindingReq[12]) = htonl(0x0714278f);
  *(int *)(&bindingReq[16]) = htonl(0x5ded3221);
  n = sendto(sockfd, bindingReq, sizeof(bindingReq), 0,
             (struct sockaddr *)&servaddr, sizeof(servaddr));
  if (n == -1) {
    printf("sendto error\n");
    return -1;
  }
  sleep(1);
  n = recvfrom(sockfd, buf, 200, 0, NULL, 0);
  if (n == -1) {
    printf("recvfrom error\n");
    return -2;
  }
  if (*(short *)(&buf[0]) == htons(0x0101)) {
    n = htons(*(short *)(&buf[2]));
    i = 20;
    while (i < sizeof(buf)) {
      attr_type = htons(*(short *)(&buf[i]));
      attr_length = htons(*(short *)(&buf[i + 2]));
      if (attr_type == 0x0020) {
        port = ntohs(*(short *)(&buf[i + 6]));
        port ^= 0x2112;
        sprintf(return_ip_port, "%d.%d.%d.%d", buf[i + 8] ^ 0x21,
                buf[i + 9] ^ 0x12, buf[i + 10] ^ 0xA4, buf[i + 11] ^ 0x42);
        break;
      }
      i += (4 + attr_length);
    }
  }
  close(sockfd);
  if (1)
    printf("Public ip successfully translated!\n");
  return 0;
}


x86 assembly (clang, -O0):
<stunGetPublicIP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xe06(%rip),%rax
mov    %rax,-0x138(%rbp)
movw   $0x4b66,-0x13a(%rbp)
66 4b
movw   $0x22b8,-0x13c(%rbp)
b8 22
mov    0x2dce(%rip),%rax
mov    (%rax),%rdi
mov    0x2dbc(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x104(%rbp)
lea    -0x28(%rbp),%rdi
mov    $0x10,%esi
call   10d0 <bzero@plt>
mov    0x2da0(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2d92(%rip),%rax
mov    (%rax),%rdi
mov    -0x138(%rbp),%rsi
lea    -0x28(%rbp),%rdx
add    $0x4,%rdx
call   1090 <inet_pton@plt>
movswl -0x13a(%rbp),%edi
call   1030 <htons@plt>
mov    %ax,-0x28(%rbp)
lea    -0x38(%rbp),%rdi
mov    $0x10,%esi
call   10d0 <bzero@plt>
mov    0x2d56(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
movswl -0x13c(%rbp),%edi
call   1030 <htons@plt>
mov    %ax,-0x38(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12c0 <stunGetPublicIP+0xe0>
mov    -0x18(%rbp),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x34(%rbp)
mov    -0x104(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0x10,%edx
call   10c0 <bind@plt>
mov    %ax,-0x130(%rbp)
mov    $0x1,%edi
call   1030 <htons@plt>
mov    %ax,-0x120(%rbp)
xor    %edi,%edi
call   1030 <htons@plt>
mov    %ax,-0x11e(%rbp)
mov    $0x2112a442,%edi
call   1050 <htonl@plt>
mov    %eax,-0x11c(%rbp)
mov    $0x63c7117e,%edi
call   1050 <htonl@plt>
mov    %eax,-0x118(%rbp)
mov    $0x714278f,%edi
call   1050 <htonl@plt>
mov    %eax,-0x114(%rbp)
mov    $0x5ded3221,%edi
call   1050 <htonl@plt>
mov    %eax,-0x110(%rbp)
mov    -0x104(%rbp),%edi
lea    -0x120(%rbp),%rsi
lea    -0x28(%rbp),%r8
mov    $0x14,%edx
xor    %ecx,%ecx
mov    $0x10,%r9d
call   1060 <sendto@plt>
mov    %ax,-0x130(%rbp)
movswl -0x130(%rbp),%eax
cmp    $0xffffffff,%eax
jne    138c <stunGetPublicIP+0x1ac>
lea    0xc94(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1580 <stunGetPublicIP+0x3a0>
mov    $0x1,%edi
call   10f0 <sleep@plt>
mov    -0x104(%rbp),%edi
lea    -0x100(%rbp),%rsi
mov    $0xc8,%edx
xor    %r9d,%r9d
xor    %eax,%eax
mov    %eax,%r8d
mov    %r9d,%ecx
call   10a0 <recvfrom@plt>
mov    %ax,-0x130(%rbp)
movswl -0x130(%rbp),%eax
cmp    $0xffffffff,%eax
jne    13e7 <stunGetPublicIP+0x207>
lea    0xc47(%rip),%rdi
call   1040 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1580 <stunGetPublicIP+0x3a0>
movswl -0x100(%rbp),%eax
mov    %eax,-0x140(%rbp)
mov    $0x101,%edi
call   1030 <htons@plt>
mov    %ax,%cx
mov    -0x140(%rbp),%eax
movswl %cx,%ecx
cmp    %ecx,%eax
jne    1562 <stunGetPublicIP+0x382>
movswl -0xfe(%rbp),%edi
call   1030 <htons@plt>
mov    %ax,-0x130(%rbp)
movl   $0x14,-0x108(%rbp)
movslq -0x108(%rbp),%rax
cmp    $0xc8,%rax
jae    155d <stunGetPublicIP+0x37d>
movslq -0x108(%rbp),%rax
movswl -0x100(%rbp,%rax,1),%edi
ff
call   1030 <htons@plt>
mov    %ax,-0x12a(%rbp)
mov    -0x108(%rbp),%eax
add    $0x2,%eax
cltq
movswl -0x100(%rbp,%rax,1),%edi
ff
call   1030 <htons@plt>
mov    %ax,-0x12c(%rbp)
movswl -0x12a(%rbp),%eax
cmp    $0x20,%eax
jne    1542 <stunGetPublicIP+0x362>
mov    -0x108(%rbp),%eax
add    $0x6,%eax
cltq
movswl -0x100(%rbp,%rax,1),%edi
ff
call   10b0 <ntohs@plt>
mov    %ax,-0x12e(%rbp)
movswl -0x12e(%rbp),%eax
xor    $0x2112,%eax
mov    %ax,-0x12e(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x108(%rbp),%eax
add    $0x8,%eax
cltq
movzbl -0x100(%rbp,%rax,1),%eax
ff
xor    $0x21,%eax
mov    %al,%dl
mov    -0x108(%rbp),%eax
add    $0x9,%eax
cltq
movzbl -0x100(%rbp,%rax,1),%eax
ff
xor    $0x12,%eax
mov    %al,%cl
mov    -0x108(%rbp),%eax
add    $0xa,%eax
cltq
movzbl -0x100(%rbp,%rax,1),%eax
ff
xor    $0xa4,%eax
mov    %al,%r8b
mov    -0x108(%rbp),%eax
add    $0xb,%eax
cltq
movzbl -0x100(%rbp,%rax,1),%eax
ff
xor    $0x42,%eax
lea    0xb03(%rip),%rsi
movzbl %dl,%edx
movzbl %cl,%ecx
movzbl %r8b,%r8d
movzbl %al,%r9d
call   10e0 <sprintf@plt>
jmp    155d <stunGetPublicIP+0x37d>
movswl -0x12c(%rbp),%eax
add    $0x4,%eax
add    -0x108(%rbp),%eax
mov    %eax,-0x108(%rbp)
jmp    142f <stunGetPublicIP+0x24f>
jmp    1562 <stunGetPublicIP+0x382>
mov    -0x104(%rbp),%edi
call   1070 <close@plt>
lea    0xac5(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stunGetPublicIP>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2dea(%rip),%rbp
mov    0x0(%rbp),%rdi
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,%r12d
lea    0x30(%rsp),%rdi
mov    $0x10,%esi
call   10d0 <bzero@plt>
mov    0x0(%rbp),%rdi
mov    %rdi,0x38(%rsp)
lea    0x34(%rsp),%rdx
lea    0xdc7(%rip),%rsi
call   1090 <inet_pton@plt>
mov    $0x4b66,%edi
call   1040 <htons@plt>
mov    %ax,0x30(%rsp)
lea    0x20(%rsp),%rdi
mov    $0x10,%esi
call   10d0 <bzero@plt>
mov    0x0(%rbp),%rax
mov    %rax,0x28(%rsp)
mov    $0x22b8,%edi
call   1040 <htons@plt>
mov    %ax,0x20(%rsp)
test   %rbx,%rbx
je     1285 <stunGetPublicIP+0xa5>
mov    %rbx,%rdi
call   1080 <inet_addr@plt>
mov    %eax,0x24(%rsp)
lea    0x20(%rsp),%rsi
mov    %r12d,%edi
mov    $0x10,%edx
call   10c0 <bind@plt>
mov    $0x1,%edi
call   1040 <htons@plt>
mov    %ax,(%rsp)
xor    %edi,%edi
call   1040 <htons@plt>
mov    %ax,0x2(%rsp)
mov    $0x2112a442,%edi
call   1050 <htonl@plt>
mov    %eax,0x4(%rsp)
mov    $0x63c7117e,%edi
call   1050 <htonl@plt>
mov    %eax,0x8(%rsp)
mov    $0x714278f,%edi
call   1050 <htonl@plt>
mov    %eax,0xc(%rsp)
mov    $0x5ded3221,%edi
call   1050 <htonl@plt>
mov    %eax,0x10(%rsp)
mov    %rsp,%rsi
lea    0x30(%rsp),%r8
mov    %r12d,%edi
mov    $0x14,%edx
xor    %ecx,%ecx
mov    $0x10,%r9d
call   1060 <sendto@plt>
cmp    $0xffff,%ax
je     13a0 <stunGetPublicIP+0x1c0>
mov    $0x1,%edi
call   10f0 <sleep@plt>
lea    0x40(%rsp),%r15
mov    %r12d,%edi
mov    %r15,%rsi
mov    $0xc8,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   10a0 <recvfrom@plt>
cmp    $0xffff,%ax
je     13ae <stunGetPublicIP+0x1ce>
movzwl 0x40(%rsp),%ebx
mov    $0x101,%edi
call   1040 <htons@plt>
cmp    %ax,%bx
jne    13ff <stunGetPublicIP+0x21f>
movswl 0x42(%rsp),%edi
call   1040 <htons@plt>
mov    $0x14,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%ebx
movswl 0x40(%rsp,%rbx,1),%edi
call   1040 <htons@plt>
mov    %eax,%r13d
movswl 0x42(%rsp,%rbx,1),%edi
call   1040 <htons@plt>
cmp    $0x20,%r13w
je     13bc <stunGetPublicIP+0x1dc>
cwtl
add    %eax,%ebp
add    $0x4,%ebp
cmp    $0xc8,%ebp
jb     1370 <stunGetPublicIP+0x190>
jmp    13ff <stunGetPublicIP+0x21f>
mov    $0xffffffff,%ebx
lea    0xca1(%rip),%rdi
jmp    1410 <stunGetPublicIP+0x230>
mov    $0xfffffffe,%ebx
lea    0xc84(%rip),%rdi
jmp    1410 <stunGetPublicIP+0x230>
movswl 0x6(%rbx,%r15,1),%edi
call   10b0 <ntohs@plt>
movzbl 0x8(%rbx,%r15,1),%edx
movzbl 0x9(%rbx,%r15,1),%ecx
movzbl 0xa(%rbx,%r15,1),%r8d
movzbl 0xb(%rbx,%r15,1),%r9d
xor    $0x21,%edx
xor    $0x12,%ecx
xor    $0xa4,%r8d
xor    $0x42,%r9d
lea    0xc18(%rip),%rsi
mov    %r14,%rdi
call   10e0 <sprintf@plt>
mov    %r12d,%edi
call   1070 <close@plt>
xor    %ebx,%ebx
lea    0xc0b(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i16, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [15 x i8] c"173.194.65.127\00"
@AF_INET = global i8* null
@SOCK_DGRAM = global i32 0
@.str.1 = [14 x i8] c"sendto error\0A\00"
@.str.2 = [16 x i8] c"recvfrom error\0A\00"
@.str.3 = [12 x i8] c"%d.%d.%d.%d\00"
@.str.4 = [36 x i8] c"Public ip successfully translated!\0A\00"
define i32 @stunGetPublicIP(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.sockaddr_in
%8 = alloca [200 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca [20 x i8]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i16
%15 = alloca i16
%16 = alloca i16
%17 = alloca i16
%18 = alloca i8*
%19 = alloca i16
%20 = alloca i16
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %18
store i16 19302, i16* %19
store i16 8888, i16* %20
%21 = load i8*, i8** @AF_INET
%22 = load i32, i32* @SOCK_DGRAM
%23 = call i32 @socket(i8* %21, i32 %22, i32 0)
store i32 %23, i32* %9
%24 = call i32 @bzero(%struct.sockaddr_in* %6, i32 16)
%25 = load i8*, i8** @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i8* %25, i8** %26
%27 = load i8*, i8** @AF_INET
%28 = load i8*, i8** %18
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%30 = call i32 @inet_pton(i8* %27, i8* %28, %struct.TYPE_2__* %29)
%31 = load i16, i16* %19
%32 = call signext i16 @htons(i16 signext %31)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i16 %32, i16* %33
%34 = call i32 @bzero(%struct.sockaddr_in* %7, i32 16)
%35 = load i8*, i8** @AF_INET
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i8* %35, i8** %36
%37 = load i16, i16* %20
%38 = call signext i16 @htons(i16 signext %37)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i16 %38, i16* %39
%40 = load i8*, i8** %5
%41 = icmp ne i8* %40, null
br i1 %41, label %42, label %47
42: ; preds = %2
%43 = load i8*, i8** %5
%44 = call i32 @inet_addr(i8* %43)
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%46 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %45, i32 0, i32 0
store i32 %44, i32* %46
br label %47
47: ; preds = %42, %2
%48 = load i32, i32* %9
%49 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%50 = call signext i16 @bind(i32 %48, %struct.sockaddr* %49, i32 16)
store i16 %50, i16* %17
%51 = call signext i16 @htons(i16 signext 1)
%52 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%53 = bitcast i8* %52 to i16*
store i16 %51, i16* %53
%54 = call signext i16 @htons(i16 signext 0)
%55 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 2
%56 = bitcast i8* %55 to i16*
store i16 %54, i16* %56
%57 = call i32 @htonl(i32 554869826)
%58 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 4
%59 = bitcast i8* %58 to i32*
store i32 %57, i32* %59
%60 = call i32 @htonl(i32 1673990526)
%61 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 8
%62 = bitcast i8* %61 to i32*
store i32 %60, i32* %62
%63 = call i32 @htonl(i32 118761359)
%64 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 12
%65 = bitcast i8* %64 to i32*
store i32 %63, i32* %65
%66 = call i32 @htonl(i32 1575825953)
%67 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 16
%68 = bitcast i8* %67 to i32*
store i32 %66, i32* %68
%69 = load i32, i32* %9
%70 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%71 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%72 = call signext i16 @sendto(i32 %69, i8* %70, i32 20, i32 0, %struct.sockaddr* %71, i32 16)
store i16 %72, i16* %17
%73 = load i16, i16* %17
%74 = sext i16 %73 to i32
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %78
76: ; preds = %47
%77 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %179
78: ; preds = %47
%79 = call i32 @sleep(i32 1)
%80 = load i32, i32* %9
%81 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%82 = call signext i16 @recvfrom(i32 %80, i8* %81, i32 200, i32 0, i32* null, i32 0)
store i16 %82, i16* %17
%83 = load i16, i16* %17
%84 = sext i16 %83 to i32
%85 = icmp eq i32 %84, -1
br i1 %85, label %86, label %88
86: ; preds = %78
%87 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i32 -2, i32* %3
br label %179
88: ; preds = %78
%89 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%90 = bitcast i8* %89 to i16*
%91 = load i16, i16* %90
%92 = sext i16 %91 to i32
%93 = call signext i16 @htons(i16 signext 257)
%94 = sext i16 %93 to i32
%95 = icmp eq i32 %92, %94
br i1 %95, label %96, label %175
96: ; preds = %88
%97 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 2
%98 = bitcast i8* %97 to i16*
%99 = load i16, i16* %98
%100 = call signext i16 @htons(i16 signext %99)
store i16 %100, i16* %17
store i32 20, i32* %10
br label %101
101: ; preds = %168, %96
%102 = load i32, i32* %10
%103 = sext i32 %102 to i64
%104 = icmp ult i64 %103, 200
br i1 %104, label %105, label %174
105: ; preds = %101
%106 = load i32, i32* %10
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 %107
%109 = bitcast i8* %108 to i16*
%110 = load i16, i16* %109
%111 = call signext i16 @htons(i16 signext %110)
store i16 %111, i16* %14
%112 = load i32, i32* %10
%113 = add nsw i32 %112, 2
%114 = sext i32 %113 to i64
%115 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 %114
%116 = bitcast i8* %115 to i16*
%117 = load i16, i16* %116
%118 = call signext i16 @htons(i16 signext %117)
store i16 %118, i16* %15
%119 = load i16, i16* %14
%120 = sext i16 %119 to i32
%121 = icmp eq i32 %120, 32
br i1 %121, label %122, label %168
122: ; preds = %105
%123 = load i32, i32* %10
%124 = add nsw i32 %123, 6
%125 = sext i32 %124 to i64
%126 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 %125
%127 = bitcast i8* %126 to i16*
%128 = load i16, i16* %127
%129 = call signext i16 @ntohs(i16 signext %128)
store i16 %129, i16* %16
%130 = load i16, i16* %16
%131 = sext i16 %130 to i32
%132 = xor i32 %131, 8466
%133 = trunc i32 %132 to i16
store i16 %133, i16* %16
%134 = load i8*, i8** %4
%135 = load i32, i32* %10
%136 = add nsw i32 %135, 8
%137 = sext i32 %136 to i64
%138 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 %137
%139 = load i8, i8* %138
%140 = zext i8 %139 to i32
%141 = xor i32 %140, 33
%142 = trunc i32 %141 to i8
%143 = load i32, i32* %10
%144 = add nsw i32 %143, 9
%145 = sext i32 %144 to i64
%146 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 %145
%147 = load i8, i8* %146
%148 = zext i8 %147 to i32
%149 = xor i32 %148, 18
%150 = trunc i32 %149 to i8
%151 = load i32, i32* %10
%152 = add nsw i32 %151, 10
%153 = sext i32 %152 to i64
%154 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 %153
%155 = load i8, i8* %154
%156 = zext i8 %155 to i32
%157 = xor i32 %156, 164
%158 = trunc i32 %157 to i8
%159 = load i32, i32* %10
%160 = add nsw i32 %159, 11
%161 = sext i32 %160 to i64
%162 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 %161
%163 = load i8, i8* %162
%164 = zext i8 %163 to i32
%165 = xor i32 %164, 66
%166 = trunc i32 %165 to i8
%167 = call i32 @sprintf(i8* %134, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %142, i8 zeroext %150, i8 zeroext %158, i8 zeroext %166)
br label %174
168: ; preds = %105
%169 = load i16, i16* %15
%170 = sext i16 %169 to i32
%171 = add nsw i32 4, %170
%172 = load i32, i32* %10
%173 = add nsw i32 %172, %171
store i32 %173, i32* %10
br label %101
174: ; preds = %122, %101
br label %175
175: ; preds = %174, %88
%176 = load i32, i32* %9
%177 = call i32 @close(i32 %176)
%178 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %179
179: ; preds = %175, %86, %76
%180 = load i32, i32* %3
ret i32 %180
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i16, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [15 x i8] c"173.194.65.127\00"
@AF_INET = global i8* null
@SOCK_DGRAM = global i32 0
@.str.3 = [12 x i8] c"%d.%d.%d.%d\00"
@str = [35 x i8] c"Public ip successfully translated!\00"
@str.5 = [15 x i8] c"recvfrom error\00"
@str.6 = [13 x i8] c"sendto error\00"
define i32 @stunGetPublicIP(i8* nocapture writeonly %0, i8* %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca [200 x i8]
%6 = alloca [20 x i8]
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%11 = load i8*, i8** @AF_INET
%12 = load i32, i32* @SOCK_DGRAM
%13 = tail call i32 @socket(i8* %11, i32 %12, i32 0)
%14 = call i32 @bzero(%struct.sockaddr_in* %3, i32 16)
%15 = load i8*, i8** @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i8* %15, i8** %16
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%18 = call i32 @inet_pton(i8* %15, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %struct.TYPE_2__* %17)
%19 = call signext i16 @htons(i16 signext 19302)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i16 %19, i16* %20
%21 = call i32 @bzero(%struct.sockaddr_in* %4, i32 16)
%22 = load i8*, i8** @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i8* %22, i8** %23
%24 = call signext i16 @htons(i16 signext 8888)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i16 %24, i16* %25
%26 = icmp eq i8* %1, null
br i1 %26, label %30, label %27
27: ; preds = %2
%28 = call i32 @inet_addr(i8* %1)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %28, i32* %29
br label %30
30: ; preds = %27, %2
%31 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%32 = call signext i16 @bind(i32 %13, %struct.sockaddr* %31, i32 16)
%33 = call signext i16 @htons(i16 signext 1)
%34 = bitcast [20 x i8]* %6 to i16*
store i16 %33, i16* %34
%35 = call signext i16 @htons(i16 signext 0)
%36 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 2
%37 = bitcast i8* %36 to i16*
store i16 %35, i16* %37
%38 = call i32 @htonl(i32 554869826)
%39 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 4
%40 = bitcast i8* %39 to i32*
store i32 %38, i32* %40
%41 = call i32 @htonl(i32 1673990526)
%42 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 8
%43 = bitcast i8* %42 to i32*
store i32 %41, i32* %43
%44 = call i32 @htonl(i32 118761359)
%45 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 12
%46 = bitcast i8* %45 to i32*
store i32 %44, i32* %46
%47 = call i32 @htonl(i32 1575825953)
%48 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 16
%49 = bitcast i8* %48 to i32*
store i32 %47, i32* %49
%50 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%51 = call signext i16 @sendto(i32 %13, i8* %10, i32 20, i32 0, %struct.sockaddr* %50, i32 16)
%52 = icmp eq i16 %51, -1
br i1 %52, label %116, label %53
53: ; preds = %30
%54 = call i32 @sleep(i32 1)
%55 = call signext i16 @recvfrom(i32 %13, i8* %9, i32 200, i32 0, i32* null, i32 0)
%56 = icmp eq i16 %55, -1
br i1 %56, label %116, label %57
57: ; preds = %53
%58 = bitcast [200 x i8]* %5 to i16*
%59 = load i16, i16* %58
%60 = call signext i16 @htons(i16 signext 257)
%61 = icmp eq i16 %59, %60
br i1 %61, label %62, label %114
62: ; preds = %57
%63 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 2
%64 = bitcast i8* %63 to i16*
%65 = load i16, i16* %64
%66 = call signext i16 @htons(i16 signext %65)
br label %67
67: ; preds = %62, %109
%68 = phi i32 [ 20, %62 ], [ %112, %109 ]
%69 = zext i32 %68 to i64
%70 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 %69
%71 = bitcast i8* %70 to i16*
%72 = load i16, i16* %71
%73 = call signext i16 @htons(i16 signext %72)
%74 = add nuw nsw i32 %68, 2
%75 = zext i32 %74 to i64
%76 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 %75
%77 = bitcast i8* %76 to i16*
%78 = load i16, i16* %77
%79 = call signext i16 @htons(i16 signext %78)
%80 = icmp eq i16 %73, 32
br i1 %80, label %81, label %109
81: ; preds = %67
%82 = add nuw nsw i32 %68, 6
%83 = zext i32 %82 to i64
%84 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 %83
%85 = bitcast i8* %84 to i16*
%86 = load i16, i16* %85
%87 = call signext i16 @ntohs(i16 signext %86)
%88 = add nuw nsw i32 %68, 8
%89 = zext i32 %88 to i64
%90 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 %89
%91 = load i8, i8* %90
%92 = xor i8 %91, 33
%93 = add nuw nsw i32 %68, 9
%94 = zext i32 %93 to i64
%95 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 %94
%96 = load i8, i8* %95
%97 = xor i8 %96, 18
%98 = add nuw nsw i32 %68, 10
%99 = zext i32 %98 to i64
%100 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 %99
%101 = load i8, i8* %100
%102 = xor i8 %101, -92
%103 = add nuw nsw i32 %68, 11
%104 = zext i32 %103 to i64
%105 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 %104
%106 = load i8, i8* %105
%107 = xor i8 %106, 66
%108 = call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %92, i8 zeroext %97, i8 zeroext %102, i8 zeroext %107)
br label %114
109: ; preds = %67
%110 = sext i16 %79 to i32
%111 = add nuw nsw i32 %68, 4
%112 = add nsw i32 %111, %110
%113 = icmp ult i32 %112, 200
br i1 %113, label %67, label %114
114: ; preds = %109, %81, %57
%115 = call i32 @close(i32 %13)
br label %116
116: ; preds = %53, %30, %114
%117 = phi i8* [ getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0), %114 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @str.6, i64 0, i64 0), %30 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @str.5, i64 0, i64 0), %53 ]
%118 = phi i32 [ 0, %114 ], [ -1, %30 ], [ -2, %53 ]
%119 = call i32 @puts(i8* dereferenceable(1) %117)
ret i32 %118
}