#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 */
typedef scalar_t__ time_t;
struct sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ now;
typedef int /*<<< orphan*/ fsin;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ errexit(char *, ...);
int /*<<< orphan*/ errno;
scalar_t__ htonl(unsigned long);
int passiveUDP(char *);
scalar_t__ recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *,
                    unsigned int *);
int /*<<< orphan*/ sendto(int, char *, int, int /*<<< orphan*/,
                          struct sockaddr *, int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ time(scalar_t__ *);
int main(int argc, char *argv[]) {
  char *service = "time";
  struct sockaddr_in fsin;
  char buf[1];
  int sock;
  time_t now;
  unsigned int alen;
  switch (argc) {
  case 1:
    break;
  case 2:
    service = argv[1];
    break;
  default:
    errexit("usage: UDPtimed [port]\n");
  }
  sock = passiveUDP(service);
  while (1) {
    alen = sizeof(fsin);
    if (recvfrom(sock, buf, sizeof(buf), 0, (struct sockaddr *)&fsin, &alen) <
        0)
      errexit("recvfrom: %s\n", strerror(errno));
    (void)time(&now);
    now = htonl((unsigned long)(now + 2208988800UL));
    (void)sendto(sock, (char *)&now, sizeof(now), 0, (struct sockaddr *)&fsin,
                 sizeof(fsin));
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe73(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x38(%rbp)
sub    $0x1,%eax
je     11b6 <main+0x46>
jmp    11a5 <main+0x35>
mov    -0x38(%rbp),%eax
sub    $0x2,%eax
je     11bb <main+0x4b>
jmp    11cc <main+0x5c>
jmp    11da <main+0x6a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    11da <main+0x6a>
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1050 <errexit@plt>
mov    -0x18(%rbp),%rdi
call   1080 <passiveUDP@plt>
mov    %eax,-0x28(%rbp)
movl   $0x4,-0x34(%rbp)
mov    -0x28(%rbp),%edi
lea    -0x21(%rbp),%rsi
lea    -0x20(%rbp),%r8
mov    $0x1,%edx
xor    %ecx,%ecx
lea    -0x34(%rbp),%r9
call   1070 <recvfrom@plt>
cmp    $0x0,%rax
jge    1230 <main+0xc0>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %eax,%esi
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1050 <errexit@plt>
lea    -0x30(%rbp),%rdi
call   1060 <time@plt>
movabs $0x83aa7e80,%rdi
add    -0x30(%rbp),%rdi
call   1030 <htonl@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x20(%rbp),%r8
mov    $0x8,%edx
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1040 <sendto@plt>
jmp    11e6 <main+0x76>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe7b(%rip),%rbx
cmp    $0x1,%edi
je     11a3 <main+0x33>
cmp    $0x2,%edi
jne    1195 <main+0x25>
mov    0x8(%rsi),%rbx
jmp    11a3 <main+0x33>
lea    0xe69(%rip),%rdi
xor    %eax,%eax
call   1050 <errexit@plt>
mov    %rbx,%rdi
call   1080 <passiveUDP@plt>
mov    %eax,%ebx
lea    0x3(%rsp),%r14
lea    0x10(%rsp),%r15
lea    0x4(%rsp),%r12
lea    0x8(%rsp),%rbp
mov    $0x83aa7e80,%r13d
jmp    1204 <main+0x94>
nopl   0x0(%rax)
mov    %rbp,%rdi
call   1060 <time@plt>
mov    0x8(%rsp),%rdi
add    %r13,%rdi
call   1030 <htonl@plt>
mov    %rax,0x8(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x8,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    $0x4,%r9d
call   1040 <sendto@plt>
movl   $0x4,0x4(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r12,%r9
call   1070 <recvfrom@plt>
test   %rax,%rax
jns    11d0 <main+0x60>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xde0(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <errexit@plt>
jmp    11d0 <main+0x60>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [5 x i8] c"time\00"
@.str.1 = [24 x i8] c"usage: UDPtimed [port]\0A\00"
@.str.2 = [14 x i8] c"recvfrom: %s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca %struct.sockaddr_in
%8 = alloca [1 x i8]
%9 = alloca i32
%10 = alloca i64
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %6
%12 = load i32, i32* %4
switch i32 %12, label %18 [
i32 1, label %13
i32 2, label %14
]
13: ; preds = %2
br label %20
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
store i8* %17, i8** %6
br label %20
18: ; preds = %2
%19 = call i32 (i8*, ...) @errexit(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %14, %13
%21 = load i8*, i8** %6
%22 = call i32 @passiveUDP(i8* %21)
store i32 %22, i32* %9
br label %23
23: ; preds = %20, %33
store i32 4, i32* %11
%24 = load i32, i32* %9
%25 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
%26 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%27 = call i64 @recvfrom(i32 %24, i8* %25, i32 1, i32 0, %struct.sockaddr* %26, i32* %11)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %23
%30 = load i32, i32* @errno
%31 = call i32 @strerror(i32 %30)
%32 = call i32 (i8*, ...) @errexit(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %29, %23
%34 = call i32 @time(i64* %10)
%35 = load i64, i64* %10
%36 = add i64 %35, 2208988800
%37 = call i64 @htonl(i64 %36)
store i64 %37, i64* %10
%38 = load i32, i32* %9
%39 = bitcast i64* %10 to i8*
%40 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%41 = call i32 @sendto(i32 %38, i8* %39, i32 8, i32 0, %struct.sockaddr* %40, i32 4)
br label %23
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [5 x i8] c"time\00"
@.str.1 = [24 x i8] c"usage: UDPtimed [port]\0A\00"
@.str.2 = [14 x i8] c"recvfrom: %s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [1 x i8]
%5 = alloca i64
%6 = alloca i32
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = getelementptr inbounds [1 x i8], [1 x i8]* %4, i64 0, i64 0
%9 = bitcast i64* %5 to i8*
%10 = bitcast i32* %6 to i8*
switch i32 %0, label %14 [
i32 1, label %16
i32 2, label %11
]
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
br label %16
14: ; preds = %2
%15 = tail call i32 (i8*, ...) @errexit(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %11, %2
%17 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %14 ], [ %13, %11 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %2 ]
%18 = tail call i32 @passiveUDP(i8* %17)
%19 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %20
20: ; preds = %27, %16
store i32 4, i32* %6
%21 = call i64 @recvfrom(i32 %18, i8* %8, i32 1, i32 0, %struct.sockaddr* %19, i32* %6)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i32, i32* @errno
%25 = call i32 @strerror(i32 %24)
%26 = call i32 (i8*, ...) @errexit(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %23, %20
%28 = call i32 @time(i64* %5)
%29 = load i64, i64* %5
%30 = add i64 %29, 2208988800
%31 = call i64 @htonl(i64 %30)
store i64 %31, i64* %5
%32 = call i32 @sendto(i32 %18, i8* %9, i32 8, i32 0, %struct.sockaddr* %19, i32 4)
br label %20
}