#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 = "64.233.184.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));
  if (1)
    printf("socket opened to  %s:%d  at local port %d\n", stun_server_ip,
           stun_server_port, local_port);
  *(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)) {
    if (1)
      printf("STUN binding resp: success !\n");
    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);
  printf("socket closed !\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    -0x138(%rbp),%rsi
movswl -0x13a(%rbp),%edx
movswl -0x13c(%rbp),%ecx
lea    0xd18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
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    13b1 <stunGetPublicIP+0x1d1>
lea    0xc9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15b7 <stunGetPublicIP+0x3d7>
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    140e <stunGetPublicIP+0x22e>
lea    0xc4d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    15b7 <stunGetPublicIP+0x3d7>
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    1597 <stunGetPublicIP+0x3b7>
lea    0xc18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movswl -0xfe(%rbp),%edi
call   1030 <htons@plt>
mov    %ax,-0x130(%rbp)
movl   $0x14,-0x108(%rbp)
movslq -0x108(%rbp),%rax
cmp    $0xc8,%rax
jae    1592 <stunGetPublicIP+0x3b2>
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    1577 <stunGetPublicIP+0x397>
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    0xb17(%rip),%rsi
movzbl %dl,%edx
movzbl %cl,%ecx
movzbl %r8b,%r8d
movzbl %al,%r9d
call   10e0 <sprintf@plt>
jmp    1592 <stunGetPublicIP+0x3b2>
movswl -0x12c(%rbp),%eax
add    $0x4,%eax
add    -0x108(%rbp),%eax
mov    %eax,-0x108(%rbp)
jmp    1464 <stunGetPublicIP+0x284>
jmp    1597 <stunGetPublicIP+0x3b7>
mov    -0x104(%rbp),%edi
call   1070 <close@plt>
lea    0xad9(%rip),%rdi
mov    $0x0,%al
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    0x2dda(%rip),%rbp
mov    0x0(%rbp),%rdi
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,%r12d
lea    0x30(%rsp),%rdi
mov    $0x10,%esi
call   10e0 <bzero@plt>
mov    0x0(%rbp),%rdi
mov    %rdi,0x38(%rsp)
lea    0x34(%rsp),%rdx
lea    0xdb7(%rip),%rsi
call   10a0 <inet_pton@plt>
mov    $0x4b66,%edi
call   1040 <htons@plt>
mov    %ax,0x30(%rsp)
lea    0x20(%rsp),%rdi
mov    $0x10,%esi
call   10e0 <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     1295 <stunGetPublicIP+0xa5>
mov    %rbx,%rdi
call   1090 <inet_addr@plt>
mov    %eax,0x24(%rsp)
lea    0x20(%rsp),%rsi
mov    %r12d,%edi
mov    $0x10,%edx
call   10d0 <bind@plt>
lea    0xd61(%rip),%rdi
lea    0xd4b(%rip),%rsi
mov    $0x4b66,%edx
mov    $0x22b8,%ecx
xor    %eax,%eax
call   1050 <printf@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   1060 <htonl@plt>
mov    %eax,0x4(%rsp)
mov    $0x63c7117e,%edi
call   1060 <htonl@plt>
mov    %eax,0x8(%rsp)
mov    $0x714278f,%edi
call   1060 <htonl@plt>
mov    %eax,0xc(%rsp)
mov    $0x5ded3221,%edi
call   1060 <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   1070 <sendto@plt>
cmp    $0xffff,%ax
je     13d0 <stunGetPublicIP+0x1e0>
mov    $0x1,%edi
call   1100 <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   10b0 <recvfrom@plt>
cmp    $0xffff,%ax
je     13de <stunGetPublicIP+0x1ee>
movzwl 0x40(%rsp),%ebx
mov    $0x101,%edi
call   1040 <htons@plt>
cmp    %ax,%bx
jne    142f <stunGetPublicIP+0x23f>
lea    0xccb(%rip),%rdi
call   1030 <puts@plt>
movswl 0x42(%rsp),%edi
call   1040 <htons@plt>
mov    $0x14,%ebp
nop
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     13ec <stunGetPublicIP+0x1fc>
cwtl
add    %eax,%ebp
add    $0x4,%ebp
cmp    $0xc8,%ebp
jb     13a0 <stunGetPublicIP+0x1b0>
jmp    142f <stunGetPublicIP+0x23f>
mov    $0xffffffff,%ebx
lea    0xca6(%rip),%rdi
jmp    1440 <stunGetPublicIP+0x250>
mov    $0xfffffffe,%ebx
lea    0xc89(%rip),%rdi
jmp    1440 <stunGetPublicIP+0x250>
movswl 0x6(%rbx,%r15,1),%edi
call   10c0 <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    0xc13(%rip),%rsi
mov    %r14,%rdi
call   10f0 <sprintf@plt>
mov    %r12d,%edi
call   1080 <close@plt>
xor    %ebx,%ebx
lea    0xc06(%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"64.233.184.127\00"
@AF_INET = global i8* null
@SOCK_DGRAM = global i32 0
@.str.1 = [43 x i8] c"socket opened to %s:%d at local port %d\0A\00"
@.str.2 = [14 x i8] c"sendto error\0A\00"
@.str.3 = [16 x i8] c"recvfrom error\0A\00"
@.str.4 = [30 x i8] c"STUN binding resp: success !\0A\00"
@.str.5 = [12 x i8] c"%d.%d.%d.%d\00"
@.str.6 = [17 x i8] c"socket closed !\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 = load i8*, i8** %18
%52 = load i16, i16* %19
%53 = sext i16 %52 to i32
%54 = load i16, i16* %20
%55 = sext i16 %54 to i32
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %51, i32 %53, i32 %55)
%57 = call signext i16 @htons(i16 signext 1)
%58 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%59 = bitcast i8* %58 to i16*
store i16 %57, i16* %59
%60 = call signext i16 @htons(i16 signext 0)
%61 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 2
%62 = bitcast i8* %61 to i16*
store i16 %60, i16* %62
%63 = call i32 @htonl(i32 554869826)
%64 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 4
%65 = bitcast i8* %64 to i32*
store i32 %63, i32* %65
%66 = call i32 @htonl(i32 1673990526)
%67 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 8
%68 = bitcast i8* %67 to i32*
store i32 %66, i32* %68
%69 = call i32 @htonl(i32 118761359)
%70 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 12
%71 = bitcast i8* %70 to i32*
store i32 %69, i32* %71
%72 = call i32 @htonl(i32 1575825953)
%73 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 16
%74 = bitcast i8* %73 to i32*
store i32 %72, i32* %74
%75 = load i32, i32* %9
%76 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%77 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%78 = call signext i16 @sendto(i32 %75, i8* %76, i32 20, i32 0, %struct.sockaddr* %77, i32 16)
store i16 %78, i16* %17
%79 = load i16, i16* %17
%80 = sext i16 %79 to i32
%81 = icmp eq i32 %80, -1
br i1 %81, label %82, label %84
82: ; preds = %47
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %186
84: ; preds = %47
%85 = call i32 @sleep(i32 1)
%86 = load i32, i32* %9
%87 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%88 = call signext i16 @recvfrom(i32 %86, i8* %87, i32 200, i32 0, i32* null, i32 0)
store i16 %88, i16* %17
%89 = load i16, i16* %17
%90 = sext i16 %89 to i32
%91 = icmp eq i32 %90, -1
br i1 %91, label %92, label %94
92: ; preds = %84
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
store i32 -2, i32* %3
br label %186
94: ; preds = %84
%95 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%96 = bitcast i8* %95 to i16*
%97 = load i16, i16* %96
%98 = sext i16 %97 to i32
%99 = call signext i16 @htons(i16 signext 257)
%100 = sext i16 %99 to i32
%101 = icmp eq i32 %98, %100
br i1 %101, label %102, label %182
102: ; preds = %94
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
%104 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 2
%105 = bitcast i8* %104 to i16*
%106 = load i16, i16* %105
%107 = call signext i16 @htons(i16 signext %106)
store i16 %107, i16* %17
store i32 20, i32* %10
br label %108
108: ; preds = %175, %102
%109 = load i32, i32* %10
%110 = sext i32 %109 to i64
%111 = icmp ult i64 %110, 200
br i1 %111, label %112, label %181
112: ; preds = %108
%113 = load i32, i32* %10
%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* %14
%119 = load i32, i32* %10
%120 = add nsw i32 %119, 2
%121 = sext i32 %120 to i64
%122 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 %121
%123 = bitcast i8* %122 to i16*
%124 = load i16, i16* %123
%125 = call signext i16 @htons(i16 signext %124)
store i16 %125, i16* %15
%126 = load i16, i16* %14
%127 = sext i16 %126 to i32
%128 = icmp eq i32 %127, 32
br i1 %128, label %129, label %175
129: ; preds = %112
%130 = load i32, i32* %10
%131 = add nsw i32 %130, 6
%132 = sext i32 %131 to i64
%133 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 %132
%134 = bitcast i8* %133 to i16*
%135 = load i16, i16* %134
%136 = call signext i16 @ntohs(i16 signext %135)
store i16 %136, i16* %16
%137 = load i16, i16* %16
%138 = sext i16 %137 to i32
%139 = xor i32 %138, 8466
%140 = trunc i32 %139 to i16
store i16 %140, i16* %16
%141 = load i8*, i8** %4
%142 = load i32, i32* %10
%143 = add nsw i32 %142, 8
%144 = sext i32 %143 to i64
%145 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 %144
%146 = load i8, i8* %145
%147 = zext i8 %146 to i32
%148 = xor i32 %147, 33
%149 = trunc i32 %148 to i8
%150 = load i32, i32* %10
%151 = add nsw i32 %150, 9
%152 = sext i32 %151 to i64
%153 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 %152
%154 = load i8, i8* %153
%155 = zext i8 %154 to i32
%156 = xor i32 %155, 18
%157 = trunc i32 %156 to i8
%158 = load i32, i32* %10
%159 = add nsw i32 %158, 10
%160 = sext i32 %159 to i64
%161 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 %160
%162 = load i8, i8* %161
%163 = zext i8 %162 to i32
%164 = xor i32 %163, 164
%165 = trunc i32 %164 to i8
%166 = load i32, i32* %10
%167 = add nsw i32 %166, 11
%168 = sext i32 %167 to i64
%169 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 %168
%170 = load i8, i8* %169
%171 = zext i8 %170 to i32
%172 = xor i32 %171, 66
%173 = trunc i32 %172 to i8
%174 = call i32 @sprintf(i8* %141, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8 zeroext %149, i8 zeroext %157, i8 zeroext %165, i8 zeroext %173)
br label %181
175: ; preds = %112
%176 = load i16, i16* %15
%177 = sext i16 %176 to i32
%178 = add nsw i32 4, %177
%179 = load i32, i32* %10
%180 = add nsw i32 %179, %178
store i32 %180, i32* %10
br label %108
181: ; preds = %129, %108
br label %182
182: ; preds = %181, %94
%183 = load i32, i32* %9
%184 = call i32 @close(i32 %183)
%185 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %3
br label %186
186: ; preds = %182, %92, %82
%187 = load i32, i32* %3
ret i32 %187
}

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"64.233.184.127\00"
@AF_INET = global i8* null
@SOCK_DGRAM = global i32 0
@.str.1 = [43 x i8] c"socket opened to %s:%d at local port %d\0A\00"
@.str.5 = [12 x i8] c"%d.%d.%d.%d\00"
@str = [16 x i8] c"socket closed !\00"
@str.7 = [29 x i8] c"STUN binding resp: success !\00"
@str.8 = [15 x i8] c"recvfrom error\00"
@str.9 = [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 i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 19302, i32 8888)
%34 = call signext i16 @htons(i16 signext 1)
%35 = bitcast [20 x i8]* %6 to i16*
store i16 %34, i16* %35
%36 = call signext i16 @htons(i16 signext 0)
%37 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 2
%38 = bitcast i8* %37 to i16*
store i16 %36, i16* %38
%39 = call i32 @htonl(i32 554869826)
%40 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 4
%41 = bitcast i8* %40 to i32*
store i32 %39, i32* %41
%42 = call i32 @htonl(i32 1673990526)
%43 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 8
%44 = bitcast i8* %43 to i32*
store i32 %42, i32* %44
%45 = call i32 @htonl(i32 118761359)
%46 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 12
%47 = bitcast i8* %46 to i32*
store i32 %45, i32* %47
%48 = call i32 @htonl(i32 1575825953)
%49 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 16
%50 = bitcast i8* %49 to i32*
store i32 %48, i32* %50
%51 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%52 = call signext i16 @sendto(i32 %13, i8* %10, i32 20, i32 0, %struct.sockaddr* %51, i32 16)
%53 = icmp eq i16 %52, -1
br i1 %53, label %118, label %54
54: ; preds = %30
%55 = call i32 @sleep(i32 1)
%56 = call signext i16 @recvfrom(i32 %13, i8* %9, i32 200, i32 0, i32* null, i32 0)
%57 = icmp eq i16 %56, -1
br i1 %57, label %118, label %58
58: ; preds = %54
%59 = bitcast [200 x i8]* %5 to i16*
%60 = load i16, i16* %59
%61 = call signext i16 @htons(i16 signext 257)
%62 = icmp eq i16 %60, %61
br i1 %62, label %63, label %116
63: ; preds = %58
%64 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.7, i64 0, i64 0))
%65 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 2
%66 = bitcast i8* %65 to i16*
%67 = load i16, i16* %66
%68 = call signext i16 @htons(i16 signext %67)
br label %69
69: ; preds = %63, %111
%70 = phi i32 [ 20, %63 ], [ %114, %111 ]
%71 = zext i32 %70 to i64
%72 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 %71
%73 = bitcast i8* %72 to i16*
%74 = load i16, i16* %73
%75 = call signext i16 @htons(i16 signext %74)
%76 = add nuw nsw i32 %70, 2
%77 = zext i32 %76 to i64
%78 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 %77
%79 = bitcast i8* %78 to i16*
%80 = load i16, i16* %79
%81 = call signext i16 @htons(i16 signext %80)
%82 = icmp eq i16 %75, 32
br i1 %82, label %83, label %111
83: ; preds = %69
%84 = add nuw nsw i32 %70, 6
%85 = zext i32 %84 to i64
%86 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 %85
%87 = bitcast i8* %86 to i16*
%88 = load i16, i16* %87
%89 = call signext i16 @ntohs(i16 signext %88)
%90 = add nuw nsw i32 %70, 8
%91 = zext i32 %90 to i64
%92 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 %91
%93 = load i8, i8* %92
%94 = xor i8 %93, 33
%95 = add nuw nsw i32 %70, 9
%96 = zext i32 %95 to i64
%97 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 %96
%98 = load i8, i8* %97
%99 = xor i8 %98, 18
%100 = add nuw nsw i32 %70, 10
%101 = zext i32 %100 to i64
%102 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 %101
%103 = load i8, i8* %102
%104 = xor i8 %103, -92
%105 = add nuw nsw i32 %70, 11
%106 = zext i32 %105 to i64
%107 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 %106
%108 = load i8, i8* %107
%109 = xor i8 %108, 66
%110 = call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8 zeroext %94, i8 zeroext %99, i8 zeroext %104, i8 zeroext %109)
br label %116
111: ; preds = %69
%112 = sext i16 %81 to i32
%113 = add nuw nsw i32 %70, 4
%114 = add nsw i32 %113, %112
%115 = icmp ult i32 %114, 200
br i1 %115, label %69, label %116
116: ; preds = %111, %83, %58
%117 = call i32 @close(i32 %13)
br label %118
118: ; preds = %54, %30, %116
%119 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0), %116 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @str.9, i64 0, i64 0), %30 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @str.8, i64 0, i64 0), %54 ]
%120 = phi i32 [ 0, %116 ], [ -1, %30 ], [ -2, %54 ]
%121 = call i32 @puts(i8* dereferenceable(1) %119)
ret i32 %120
}