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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ atoi(char *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int sock, length, fromlen, n;
  struct sockaddr_in server;
  struct sockaddr_in from;
  char buf[1024];
  if (argc < 2) {
    fprintf(stderr, "ERROR, no port provided\n");
    exit(0);
  }
  sock = socket(AF_INET, SOCK_DGRAM, 0);
  if (sock < 0)
    error("Opening socket");
  length = sizeof(server);
  bzero(&server, length);
  server.sin_family = AF_INET;
  server.sin_addr.s_addr = INADDR_ANY;
  server.sin_port = htons(atoi(argv[1]));
  if (bind(sock, (struct sockaddr *)&server, length) < 0)
    error("binding");
  fromlen = sizeof(struct sockaddr_in);
  write(1, "> server ready to accept connections\n", 200);
  while (1) {
    n = recvfrom(sock, buf, 1024, 0, (struct sockaddr *)&from, &fromlen);
    if (n < 0)
      error("recvfrom");
    write(1, "Received a datagram: ", 21);
    write(1, buf, n);
    n = sendto(sock, "Got your message\n", 17, 0, (struct sockaddr *)&from,
               fromlen);
    if (n < 0)
      error("sendto");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11ef <main+0x3f>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
lea    0xe1d(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1221 <main+0x71>
lea    0xdfd(%rip),%rdi
call   1090 <error@plt>
movl   $0xc,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    -0x30(%rbp),%rdi
call   10a0 <bzero@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1080 <bind@plt>
cmp    $0x0,%rax
jge    1288 <main+0xd8>
lea    0xda5(%rip),%rdi
call   1090 <error@plt>
movl   $0xc,-0x1c(%rbp)
mov    $0x1,%edi
lea    0xd95(%rip),%rsi
mov    $0xc8,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
lea    -0x440(%rbp),%rsi
lea    -0x40(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0x1c(%rbp),%r9
call   1070 <recvfrom@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    12dc <main+0x12c>
lea    0xd7f(%rip),%rdi
call   1090 <error@plt>
mov    $0x1,%edi
lea    0xd77(%rip),%rsi
mov    $0x15,%edx
call   1030 <write@plt>
lea    -0x440(%rbp),%rsi
mov    -0x20(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%r8
mov    -0x1c(%rbp),%r9d
lea    0xd5d(%rip),%rsi
mov    $0x11,%edx
xor    %ecx,%ecx
call   1050 <sendto@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    133d <main+0x18d>
lea    0xd4f(%rip),%rdi
call   1090 <error@plt>
jmp    12a5 <main+0xf5>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
cmp    $0x1,%edi
jle    1309 <main+0x159>
mov    %rsi,%rbp
mov    0x2e14(%rip),%r15
mov    (%r15),%edi
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11f9 <main+0x49>
lea    0xe25(%rip),%rdi
call   1090 <error@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   10a0 <bzero@plt>
mov    (%r15),%eax
mov    %eax,0x18(%rsp)
mov    0x2dc7(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x8(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
test   %rax,%rax
jns    1253 <main+0xa3>
lea    0xdda(%rip),%rdi
call   1090 <error@plt>
movl   $0xc,0xc(%rsp)
lea    0xdce(%rip),%rsi
mov    $0x1,%edi
mov    $0xc8,%edx
call   1030 <write@plt>
lea    0x30(%rsp),%r14
lea    0x20(%rsp),%r15
lea    0xddd(%rip),%rbp
lea    0xdec(%rip),%r13
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
mov    %r15,%r8
lea    0xc(%rsp),%r9
call   1070 <recvfrom@plt>
mov    %eax,%r12d
test   %eax,%eax
jns    12bc <main+0x10c>
lea    0xd9f(%rip),%rdi
call   1090 <error@plt>
mov    $0x1,%edi
mov    %rbp,%rsi
mov    $0x15,%edx
call   1030 <write@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    %r12d,%edx
call   1030 <write@plt>
mov    0xc(%rsp),%r9d
mov    %ebx,%edi
mov    %r13,%rsi
mov    $0x11,%edx
xor    %ecx,%ecx
mov    %r15,%r8
call   1050 <sendto@plt>
test   %eax,%eax
jns    1290 <main+0xe0>
lea    0xd85(%rip),%rdi
call   1090 <error@plt>
jmp    1290 <main+0xe0>
mov    0x2cb8(%rip),%rax
mov    (%rax),%edi
lea    0xce7(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [25 x i8] c"ERROR, no port provided\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [15 x i8] c"Opening socket\00"
@INADDR_ANY = global i32 0
@.str.2 = [8 x i8] c"binding\00"
@.str.3 = [38 x i8] c"> server ready to accept connections\0A\00"
@.str.4 = [9 x i8] c"recvfrom\00"
@.str.5 = [22 x i8] c"Received a datagram: \00"
@.str.6 = [18 x i8] c"Got your message\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 i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca %struct.sockaddr_in
%12 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %2
%20 = load i32, i32* @AF_INET
%21 = load i32, i32* @SOCK_DGRAM
%22 = call i32 @socket(i32 %20, i32 %21, i32 0)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = call i32 @error(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %19
store i32 12, i32* %7
%28 = load i32, i32* %7
%29 = call i32 @bzero(%struct.sockaddr_in* %10, i32 %28)
%30 = load i32, i32* @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %30, i32* %31
%32 = load i32, i32* @INADDR_ANY
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%34 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %33, i32 0, i32 0
store i32 %32, i32* %34
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32 @atoi(i8* %37)
%39 = call i32 @htons(i32 %38)
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i32 %39, i32* %40
%41 = load i32, i32* %6
%42 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%43 = load i32, i32* %7
%44 = call i64 @bind(i32 %41, %struct.sockaddr* %42, i32 %43)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %27
%47 = call i32 @error(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %48
48: ; preds = %46, %27
store i32 12, i32* %8
%49 = call i32 @write(i32 1, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 200)
br label %50
50: ; preds = %48, %72
%51 = load i32, i32* %6
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%53 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%54 = call i32 @recvfrom(i32 %51, i8* %52, i32 1024, i32 0, %struct.sockaddr* %53, i32* %8)
store i32 %54, i32* %9
%55 = load i32, i32* %9
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %50
%58 = call i32 @error(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %59
59: ; preds = %57, %50
%60 = call i32 @write(i32 1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i32 21)
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%62 = load i32, i32* %9
%63 = call i32 @write(i32 1, i8* %61, i32 %62)
%64 = load i32, i32* %6
%65 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%66 = load i32, i32* %8
%67 = call i32 @sendto(i32 %64, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 17, i32 0, %struct.sockaddr* %65, i32 %66)
store i32 %67, i32* %9
%68 = load i32, i32* %9
%69 = icmp slt i32 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %59
%71 = call i32 @error(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
br label %72
72: ; preds = %70, %59
br label %50
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [25 x i8] c"ERROR, no port provided\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [15 x i8] c"Opening socket\00"
@INADDR_ANY = global i32 0
@.str.2 = [8 x i8] c"binding\00"
@.str.3 = [38 x i8] c"> server ready to accept connections\0A\00"
@.str.4 = [9 x i8] c"recvfrom\00"
@.str.5 = [22 x i8] c"Received a datagram: \00"
@.str.6 = [18 x i8] c"Got your message\0A\00"
@.str.7 = [7 x i8] c"sendto\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca [1024 x i8]
%7 = bitcast i32* %3 to i8*
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = bitcast %struct.sockaddr_in* %5 to i8*
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%11 = icmp slt i32 %0, 2
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 0)
unreachable
16: ; preds = %2
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @SOCK_DGRAM
%19 = tail call i32 @socket(i32 %17, i32 %18, i32 0)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = tail call i32 @error(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %16
%24 = call i32 @bzero(%struct.sockaddr_in* %4, i32 12)
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %25, i32* %26
%27 = load i32, i32* @INADDR_ANY
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %27, i32* %28
%29 = getelementptr inbounds i8*, i8** %1, i64 1
%30 = load i8*, i8** %29
%31 = tail call i32 @atoi(i8* %30)
%32 = tail call i32 @htons(i32 %31)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %32, i32* %33
%34 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%35 = call i64 @bind(i32 %19, %struct.sockaddr* %34, i32 12)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %23
%38 = call i32 @error(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %37, %23
store i32 12, i32* %3
%40 = call i32 @write(i32 1, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 200)
%41 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
br label %42
42: ; preds = %55, %39
%43 = call i32 @recvfrom(i32 %19, i8* %10, i32 1024, i32 0, %struct.sockaddr* %41, i32* %3)
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %42
%46 = call i32 @error(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %47
47: ; preds = %45, %42
%48 = call i32 @write(i32 1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i32 21)
%49 = call i32 @write(i32 1, i8* %10, i32 %43)
%50 = load i32, i32* %3
%51 = call i32 @sendto(i32 %19, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 17, i32 0, %struct.sockaddr* %41, i32 %50)
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %47
%54 = call i32 @error(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
br label %55
55: ; preds = %53, %47
br label %42
}