#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 sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ servSockAddr;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ atoi(char *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int get_socket(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sockaddr_init(char const *, unsigned short,
                                 struct sockaddr *);
int udp_receive(int, char *, int, struct sockaddr *);
int udp_send(int, char *, int, struct sockaddr *);
int main(int argc, char *argv[]) {
  const char *address = "";
  const char *forward_address = "192.168.0.12";
  unsigned short port = (unsigned short)atoi(argv[1]);
  struct sockaddr servSockAddr, clitSockAddr, forwardSockAddr;
  char recvBuffer[(4096 + 1)];
  int server_sock = get_socket("udp");
  sockaddr_init(address, port, &servSockAddr);
  sockaddr_init(forward_address, port, &forwardSockAddr);
  if (bind(server_sock, &servSockAddr, sizeof(servSockAddr)) < 0) {
    perror("bind() failed.");
    exit(EXIT_FAILURE);
  }
  while (1) {
    int recvMsgSize =
        udp_receive(server_sock, recvBuffer, (4096 + 1), &clitSockAddr);
    if (recvMsgSize == -1)
      continue;
    int sendMsgSize =
        udp_send(server_sock, recvBuffer, recvMsgSize, &forwardSockAddr);
    if (sendMsgSize == -1)
      continue;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1050,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe7f(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe55(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %ax,-0x22(%rbp)
lea    0xe46(%rip),%rdi
call   1030 <get_socket@plt>
mov    %eax,-0x1044(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rdx
movzwl -0x22(%rbp),%esi
call   10a0 <sockaddr_init@plt>
mov    -0x20(%rbp),%rdi
lea    -0x38(%rbp),%rdx
movzwl -0x22(%rbp),%esi
call   10a0 <sockaddr_init@plt>
mov    -0x1044(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   1050 <bind@plt>
cmp    $0x0,%rax
jge    122c <main+0xac>
lea    0xdf8(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    1231 <main+0xb1>
mov    -0x1044(%rbp),%edi
lea    -0x1040(%rbp),%rsi
mov    $0x1001,%edx
lea    -0x30(%rbp),%rcx
call   1040 <udp_receive@plt>
mov    %eax,-0x1048(%rbp)
cmpl   $0xffffffff,-0x1048(%rbp)
jne    1264 <main+0xe4>
jmp    1231 <main+0xb1>
mov    -0x1044(%rbp),%edi
lea    -0x1040(%rbp),%rsi
mov    -0x1048(%rbp),%edx
lea    -0x38(%rbp),%rcx
call   1070 <udp_send@plt>
mov    %eax,-0x104c(%rbp)
cmpl   $0xffffffff,-0x104c(%rbp)
jne    1298 <main+0x118>
jmp    1231 <main+0xb1>
jmp    1231 <main+0xb1>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1030,%rsp
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %rax,%r14
lea    0xe6b(%rip),%rdi
call   1030 <get_socket@plt>
mov    %eax,%ebx
movzwl %r14w,%ebp
lea    0xe6b(%rip),%rdi
lea    0x18(%rsp),%r14
mov    %ebp,%esi
mov    %r14,%rdx
call   10a0 <sockaddr_init@plt>
lea    0xe36(%rip),%rdi
lea    0x8(%rsp),%rdx
mov    %ebp,%esi
call   10a0 <sockaddr_init@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1050 <bind@plt>
test   %rax,%rax
js     1228 <main+0xa8>
lea    0x20(%rsp),%r14
lea    0x10(%rsp),%r15
lea    0x8(%rsp),%r12
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1001,%edx
mov    %r15,%rcx
call   1040 <udp_receive@plt>
cmp    $0xffffffff,%eax
je     1200 <main+0x80>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
mov    %r12,%rcx
call   1070 <udp_send@plt>
jmp    1200 <main+0x80>
lea    0xde2(%rip),%rdi
call   1060 <perror@plt>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@.str = [1 x i8] zeroinitializer
@.str.1 = [13 x i8] c"192.168.0.12\00"
@.str.2 = [4 x i8] c"udp\00"
@.str.3 = [15 x i8] c"bind() failed.\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i16
%9 = alloca %struct.sockaddr
%10 = alloca %struct.sockaddr
%11 = alloca %struct.sockaddr
%12 = alloca [4097 x i8]
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8** %7
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i64 @atoi(i8* %18)
%20 = trunc i64 %19 to i16
store i16 %20, i16* %8
%21 = call i32 @get_socket(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store i32 %21, i32* %13
%22 = load i8*, i8** %6
%23 = load i16, i16* %8
%24 = call i32 @sockaddr_init(i8* %22, i16 zeroext %23, %struct.sockaddr* %9)
%25 = load i8*, i8** %7
%26 = load i16, i16* %8
%27 = call i32 @sockaddr_init(i8* %25, i16 zeroext %26, %struct.sockaddr* %11)
%28 = load i32, i32* %13
%29 = call i64 @bind(i32 %28, %struct.sockaddr* %9, i32 4)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %2
%32 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %2
br label %36
36: ; preds = %35, %42, %50, %51
%37 = load i32, i32* %13
%38 = getelementptr inbounds [4097 x i8], [4097 x i8]* %12, i64 0, i64 0
%39 = call i32 @udp_receive(i32 %37, i8* %38, i32 4097, %struct.sockaddr* %10)
store i32 %39, i32* %14
%40 = load i32, i32* %14
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %43
42: ; preds = %36
br label %36
43: ; preds = %36
%44 = load i32, i32* %13
%45 = getelementptr inbounds [4097 x i8], [4097 x i8]* %12, i64 0, i64 0
%46 = load i32, i32* %14
%47 = call i32 @udp_send(i32 %44, i8* %45, i32 %46, %struct.sockaddr* %11)
store i32 %47, i32* %15
%48 = load i32, i32* %15
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %51
50: ; preds = %43
br label %36
51: ; preds = %43
br label %36
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@.str = [1 x i8] zeroinitializer
@.str.1 = [13 x i8] c"192.168.0.12\00"
@.str.2 = [4 x i8] c"udp\00"
@.str.3 = [15 x i8] c"bind() failed.\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr
%4 = alloca %struct.sockaddr
%5 = alloca %struct.sockaddr
%6 = alloca [4097 x i8]
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i64 @atoi(i8* %8)
%10 = trunc i64 %9 to i16
%11 = bitcast %struct.sockaddr* %3 to i8*
%12 = bitcast %struct.sockaddr* %4 to i8*
%13 = bitcast %struct.sockaddr* %5 to i8*
%14 = getelementptr inbounds [4097 x i8], [4097 x i8]* %6, i64 0, i64 0
%15 = tail call i32 @get_socket(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @sockaddr_init(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i16 zeroext %10, %struct.sockaddr* %3)
%17 = call i32 @sockaddr_init(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i16 zeroext %10, %struct.sockaddr* %5)
%18 = call i64 @bind(i32 %15, %struct.sockaddr* %3, i32 4)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %2
%21 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %2, %27
%25 = call i32 @udp_receive(i32 %15, i8* %14, i32 4097, %struct.sockaddr* %4)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %28
27: ; preds = %24, %28
br label %24
28: ; preds = %24
%29 = call i32 @udp_send(i32 %15, i8* %14, i32 %25, %struct.sockaddr* %5)
br label %27
}