#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*/ socklen_t;
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 *, char *);
int /*<<< orphan*/ get_time(int, char *, int);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *,
             int /*<<< orphan*/ *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int sock, length, fromlen, n;
  struct sockaddr_in server;
  struct sockaddr_in from;
  char buf[2048];
  unsigned char pending_packets = 0;
  if (argc < 2) {
    fprintf(stderr, "Useage:\n %s port\n", argv[0]);
    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);
  while (1) {
    n = recvfrom(sock, buf, 2048, 0, (struct sockaddr *)&from,
                 (socklen_t *)&fromlen);
    if (n < 0)
      error("recvfrom");
    get_time(sock, buf, n);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x850,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x0,-0x841(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11ed <main+0x4d>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe1f(%rip),%rsi
call   1050 <fprintf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    121f <main+0x7f>
lea    0xdf8(%rip),%rdi
call   1080 <error@plt>
movl   $0xc,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    -0x30(%rbp),%rdi
call   1090 <bzero@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,%edi
call   1030 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1070 <bind@plt>
cmp    $0x0,%rax
jge    1286 <main+0xe6>
lea    0xda0(%rip),%rdi
call   1080 <error@plt>
movl   $0xc,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x840(%rbp),%rsi
lea    -0x40(%rbp),%r8
mov    $0x800,%edx
xor    %ecx,%ecx
lea    -0x1c(%rbp),%r9
call   1060 <recvfrom@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    12c4 <main+0x124>
lea    0xd6a(%rip),%rdi
call   1080 <error@plt>
mov    -0x14(%rbp),%edi
lea    -0x840(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1040 <get_time@plt>
jmp    128d <main+0xed>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x838,%rsp
mov    %rsi,%r14
cmp    $0x1,%edi
jle    12a3 <main+0x103>
mov    0x2e24(%rip),%r15
mov    (%r15),%edi
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11e9 <main+0x49>
lea    0xe2e(%rip),%rdi
call   1080 <error@plt>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    (%r15),%eax
mov    %eax,0x18(%rsp)
mov    0x2dd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x8(%r14),%rdi
call   10a0 <atoi@plt>
mov    %eax,%edi
call   1030 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   1070 <bind@plt>
test   %rax,%rax
jns    1243 <main+0xa3>
lea    0xde3(%rip),%rdi
call   1080 <error@plt>
movl   $0xc,0xc(%rsp)
lea    0x30(%rsp),%r14
lea    0x20(%rsp),%r15
lea    0xc(%rsp),%r12
lea    0xdc8(%rip),%r13
jmp    127c <main+0xdc>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%edi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <get_time@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x800,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r12,%r9
call   1060 <recvfrom@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1270 <main+0xd0>
mov    %r13,%rdi
call   1080 <error@plt>
jmp    1270 <main+0xd0>
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd4a(%rip),%rsi
call   1050 <fprintf@plt>
xor    %edi,%edi
call   10b0 <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 = [18 x i8] c"Useage:\0A %s port\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 = [9 x i8] c"recvfrom\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 [2048 x i8]
%13 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8 0, i8* %13
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 2
br i1 %15, label %16, label %23
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 0)
unreachable
23: ; preds = %2
%24 = load i32, i32* @AF_INET
%25 = load i32, i32* @SOCK_DGRAM
%26 = call i32 @socket(i32 %24, i32 %25, i32 0)
store i32 %26, i32* %6
%27 = load i32, i32* %6
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %23
%30 = call i32 @error(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %29, %23
store i32 12, i32* %7
%32 = load i32, i32* %7
%33 = call i32 @bzero(%struct.sockaddr_in* %10, i32 %32)
%34 = load i32, i32* @AF_INET
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %34, i32* %35
%36 = load i32, i32* @INADDR_ANY
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%38 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %37, i32 0, i32 0
store i32 %36, i32* %38
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i32 @atoi(i8* %41)
%43 = call i32 @htons(i32 %42)
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i32 %43, i32* %44
%45 = load i32, i32* %6
%46 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%47 = load i32, i32* %7
%48 = call i64 @bind(i32 %45, %struct.sockaddr* %46, i32 %47)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %31
%51 = call i32 @error(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %52
52: ; preds = %50, %31
store i32 12, i32* %8
br label %53
53: ; preds = %52, %62
%54 = load i32, i32* %6
%55 = getelementptr inbounds [2048 x i8], [2048 x i8]* %12, i64 0, i64 0
%56 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%57 = call i32 @recvfrom(i32 %54, i8* %55, i32 2048, i32 0, %struct.sockaddr* %56, i32* %8)
store i32 %57, i32* %9
%58 = load i32, i32* %9
%59 = icmp slt i32 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %53
%61 = call i32 @error(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %62
62: ; preds = %60, %53
%63 = load i32, i32* %6
%64 = getelementptr inbounds [2048 x i8], [2048 x i8]* %12, i64 0, i64 0
%65 = load i32, i32* %9
%66 = call i32 @get_time(i32 %63, i8* %64, i32 %65)
br label %53
}

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 = [18 x i8] c"Useage:\0A %s port\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 = [9 x i8] c"recvfrom\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca [2048 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 [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%11 = icmp slt i32 %0, 2
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %1
%15 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = tail call i32 @exit(i32 0)
unreachable
17: ; preds = %2
%18 = load i32, i32* @AF_INET
%19 = load i32, i32* @SOCK_DGRAM
%20 = tail call i32 @socket(i32 %18, i32 %19, i32 0)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = tail call i32 @error(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %17
%25 = call i32 @bzero(%struct.sockaddr_in* %4, i32 12)
%26 = load i32, i32* @AF_INET
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %26, i32* %27
%28 = load i32, i32* @INADDR_ANY
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %28, i32* %29
%30 = getelementptr inbounds i8*, i8** %1, i64 1
%31 = load i8*, i8** %30
%32 = tail call i32 @atoi(i8* %31)
%33 = tail call i32 @htons(i32 %32)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %33, i32* %34
%35 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%36 = call i64 @bind(i32 %20, %struct.sockaddr* %35, i32 12)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %24
%39 = call i32 @error(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %40
40: ; preds = %38, %24
store i32 12, i32* %3
%41 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
br label %42
42: ; preds = %47, %40
%43 = call i32 @recvfrom(i32 %20, i8* %10, i32 2048, 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.3, i64 0, i64 0))
br label %47
47: ; preds = %45, %42
%48 = call i32 @get_time(i32 %20, i8* %10, i32 %43)
br label %42
}