#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 {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ buff;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ INADDR_NONE;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
scalar_t__ inet_addr(char *);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int random();
int sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct sockaddr *, int);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char **argv) {
  struct sockaddr_in addr;
  int sock;
  char m_val[256];
  char buff[512];
  int len;
  if (argc != 3) {
    printf("--<%s:%d>--"
           "Usage: %s ip port"
           "--\n",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/princeofdream/debug_src_full/refs/heads/"
           "master/network_utils/udp_hole_punch/demo.c",
           41, argv[0]);
    exit(1);
  }
  printf("--<%s:%d>--"
         "This is a UDP client"
         "--\n",
         "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
         "2022-01-22/02-19-57/repos/princeofdream/debug_src_full/refs/heads/"
         "master/network_utils/udp_hole_punch/demo.c",
         44);
  if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    perror("socket");
    exit(1);
  }
  addr.sin_family = AF_INET;
  addr.sin_port = htons(atoi(argv[2]));
  addr.sin_addr.s_addr = inet_addr(argv[1]);
  if (addr.sin_addr.s_addr == INADDR_NONE) {
    printf("Incorrect ip address!");
    close(sock);
    exit(1);
  }
  len = sizeof(addr);
  while (1) {
    int n;
    memset(buff, 0x0, sizeof(buff));
    sprintf(buff, "demo by JamesL %03d", random() % 1000);
    printf("--<%s:%d>--"
           "send: %s"
           "--\n",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/princeofdream/debug_src_full/refs/heads/"
           "master/network_utils/udp_hole_punch/demo.c",
           67, buff);
    n = sendto(sock, buff, strlen(buff), 0, (struct sockaddr *)&addr,
               sizeof(addr));
    if (n < 0) {
      perror("sendto");
      close(sock);
      break;
    }
    sleep(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x350,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     122e <main+0x4e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
lea    0xdef(%rip),%rdi
lea    0xe08(%rip),%rsi
mov    $0x29,%edx
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    0xe98(%rip),%rdi
lea    0xde4(%rip),%rsi
mov    $0x2c,%edx
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
mov    0x2d80(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    1283 <main+0xa3>
lea    0xe7c(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2d5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <inet_addr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2d1e(%rip),%rcx
cmp    (%rcx),%rax
jne    12eb <main+0x10b>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
movl   $0x10,-0x334(%rbp)
lea    -0x330(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1060 <memset@plt>
lea    -0x330(%rbp),%rax
mov    %rax,-0x350(%rbp)
mov    $0x0,%al
call   10a0 <random@plt>
mov    -0x350(%rbp),%rdi
mov    $0x3e8,%ecx
cltd
idiv   %ecx
lea    0xdda(%rip),%rsi
call   10d0 <sprintf@plt>
lea    -0x330(%rbp),%rcx
lea    0xddb(%rip),%rdi
lea    0xcd3(%rip),%rsi
mov    $0x43,%edx
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x344(%rbp)
lea    -0x330(%rbp),%rax
mov    %rax,-0x340(%rbp)
lea    -0x330(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x344(%rbp),%edi
mov    -0x340(%rbp),%rsi
mov    %eax,%edx
lea    -0x20(%rbp),%r8
xor    %ecx,%ecx
mov    $0x10,%r9d
call   1070 <sendto@plt>
mov    %eax,-0x338(%rbp)
cmpl   $0x0,-0x338(%rbp)
jge    13c8 <main+0x1e8>
lea    0xd82(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
jmp    13d7 <main+0x1f7>
mov    $0x1,%edi
call   10f0 <sleep@plt>
jmp    12f5 <main+0x115>
xor    %eax,%eax
add    $0x350,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    133e <main+0x15e>
lea    0xec9(%rip),%rdi
lea    0xe15(%rip),%rsi
mov    $0x2c,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2dca(%rip),%r14
mov    (%r14),%edi
mov    0x2db0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
test   %eax,%eax
js     1365 <main+0x185>
mov    %eax,%ebp
mov    (%r14),%eax
mov    %eax,0xc(%rsp)
mov    0x10(%rbx),%rdi
call   10c0 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,0x8(%rsp)
mov    0x8(%rbx),%rdi
call   1090 <inet_addr@plt>
mov    %rax,(%rsp)
mov    0x2d76(%rip),%rcx
cmp    (%rcx),%rax
je     137b <main+0x19b>
lea    0x10(%rsp),%rbx
lea    0xe8e(%rip),%r14
lea    0xe9b(%rip),%r15
lea    0xd93(%rip),%r12
mov    %rsp,%r13
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1060 <memset@plt>
xor    %eax,%eax
call   10a0 <random@plt>
movslq %eax,%rdx
imul   $0x10624dd3,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
imul   $0x3e8,%eax,%eax
sub    %eax,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   10d0 <sprintf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x43,%edx
mov    %rbx,%rcx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r13,%r8
mov    $0x10,%r9d
call   1070 <sendto@plt>
test   %eax,%eax
js     1317 <main+0x137>
mov    $0x1,%edi
call   10f0 <sleep@plt>
jmp    1290 <main+0xb0>
lea    0xe1a(%rip),%rdi
call   10b0 <perror@plt>
mov    %ebp,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%rcx
lea    0xcb8(%rip),%rdi
lea    0xcd1(%rip),%rsi
mov    $0x29,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    0xd84(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    0xd75(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
call   1080 <close@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.sockaddr = type { i32 }
@.str = [32 x i8] c"--<%s:%d>--Usage: %s ip port--\0A\00"
@.str.1 = [173 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/princeofdream/debug_src_full/refs/heads/master/network_utils/udp_hole_punch/demo.c\00"
@.str.2 = [35 x i8] c"--<%s:%d>--This is a UDP client--\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.3 = [7 x i8] c"socket\00"
@INADDR_NONE = global i64 0
@.str.4 = [22 x i8] c"Incorrect ip address!\00"
@.str.5 = [20 x i8] c"demo by JamesL %03d\00"
@.str.6 = [23 x i8] c"--<%s:%d>--send: %s--\0A\00"
@.str.7 = [7 x i8] c"sendto\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca [256 x i8]
%9 = alloca [512 x i8]
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str.1, i64 0, i64 0), i32 41, i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str.1, i64 0, i64 0), i32 44)
%22 = load i32, i32* @AF_INET
%23 = load i32, i32* @SOCK_DGRAM
%24 = call i32 @socket(i32 %22, i32 %23, i32 0)
store i32 %24, i32* %7
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %20
%30 = load i32, i32* @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %30, i32* %31
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i32 @atoi(i8* %34)
%36 = call i32 @htons(i32 %35)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %36, i32* %37
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i64 @inet_addr(i8* %40)
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%43 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %42, i32 0, i32 0
store i64 %41, i64* %43
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%45 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %44, i32 0, i32 0
%46 = load i64, i64* %45
%47 = load i64, i64* @INADDR_NONE
%48 = icmp eq i64 %46, %47
br i1 %48, label %49, label %54
49: ; preds = %29
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%51 = load i32, i32* %7
%52 = call i32 @close(i32 %51)
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %29
store i32 16, i32* %10
br label %55
55: ; preds = %54, %76
%56 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%57 = call i32 @memset(i8* %56, i32 0, i32 512)
%58 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%59 = call i32 (...) @random()
%60 = srem i32 %59, 1000
%61 = call i32 @sprintf(i8* %58, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 %60)
%62 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str.1, i64 0, i64 0), i32 67, i8* %62)
%64 = load i32, i32* %7
%65 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%66 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%67 = call i32 @strlen(i8* %66)
%68 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%69 = call i32 @sendto(i32 %64, i8* %65, i32 %67, i32 0, %struct.sockaddr* %68, i32 16)
store i32 %69, i32* %11
%70 = load i32, i32* %11
%71 = icmp slt i32 %70, 0
br i1 %71, label %72, label %76
72: ; preds = %55
%73 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%74 = load i32, i32* %7
%75 = call i32 @close(i32 %74)
br label %78
76: ; preds = %55
%77 = call i32 @sleep(i32 1)
br label %55
78: ; preds = %72
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.sockaddr = type { i32 }
@.str = [32 x i8] c"--<%s:%d>--Usage: %s ip port--\0A\00"
@.str.1 = [173 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/princeofdream/debug_src_full/refs/heads/master/network_utils/udp_hole_punch/demo.c\00"
@.str.2 = [35 x i8] c"--<%s:%d>--This is a UDP client--\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.3 = [7 x i8] c"socket\00"
@INADDR_NONE = global i64 0
@.str.4 = [22 x i8] c"Incorrect ip address!\00"
@.str.5 = [20 x i8] c"demo by JamesL %03d\00"
@.str.6 = [23 x i8] c"--<%s:%d>--send: %s--\0A\00"
@.str.7 = [7 x i8] c"sendto\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [512 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 3
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str.1, i64 0, i64 0), i32 41, i8* %9)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str.1, i64 0, i64 0), i32 44)
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_DGRAM
%16 = tail call i32 @socket(i32 %14, i32 %15, i32 0)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %12
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %22, i32* %23
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
%26 = tail call i32 @atoi(i8* %25)
%27 = tail call i32 @htons(i32 %26)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %27, i32* %28
%29 = getelementptr inbounds i8*, i8** %1, i64 1
%30 = load i8*, i8** %29
%31 = tail call i64 @inet_addr(i8* %30)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i64 %31, i64* %32
%33 = load i64, i64* @INADDR_NONE
%34 = icmp eq i64 %31, %33
br i1 %34, label %37, label %35
35: ; preds = %21
%36 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %41
37: ; preds = %21
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%39 = tail call i32 @close(i32 %16)
%40 = tail call i32 @exit(i32 1)
unreachable
41: ; preds = %35, %50
%42 = call i32 @memset(i8* %6, i32 0, i32 512)
%43 = call i32 (...) @random()
%44 = srem i32 %43, 1000
%45 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 %44)
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str.1, i64 0, i64 0), i32 67, i8* %6)
%47 = call i32 @strlen(i8* %6)
%48 = call i32 @sendto(i32 %16, i8* %6, i32 %47, i32 0, %struct.sockaddr* %36, i32 16)
%49 = icmp slt i32 %48, 0
br i1 %49, label %52, label %50
50: ; preds = %41
%51 = call i32 @sleep(i32 1)
br label %41
52: ; preds = %41
%53 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%54 = call i32 @close(i32 %16)
ret i32 0
}