#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;
typedef int /*<<< orphan*/ now;

/* Variables and functions */
int connectUDP(char *, char *);
char *ctime(scalar_t__ *);
int /*<<< orphan*/ errexit(char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ ntohl(unsigned long);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char *host = "localhost";
  char *service = "time";
  time_t now;
  int s, n;
  switch (argc) {
  case 1:
    host = "localhost";
    break;
  case 3:
    service = argv[2];
  case 2:
    host = argv[1];
    break;
  default:
    fprintf(stderr, "usage: UDPtime[host[port]]\n");
    exit(1);
  }
  s = connectUDP(host, service);
  (void)write(s, "what time is it?\n", strlen("what time is it?\n"));
  n = read(s, (char *)&now, sizeof(now));
  if (n < 0)
    errexit("read failed: %s\n", strerror(errno));
  now = ntohl((unsigned long)now);
  now -= 2208988800UL;
  printf("%s", ctime(&now));
  exit(0);
}


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    0xe33(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe32(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x1,%eax
je     1212 <main+0x62>
jmp    11f0 <main+0x40>
mov    -0x34(%rbp),%eax
sub    $0x2,%eax
je     122e <main+0x7e>
jmp    1201 <main+0x51>
mov    -0x34(%rbp),%eax
sub    $0x3,%eax
je     1222 <main+0x72>
jmp    123f <main+0x8f>
lea    0xde7(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    125e <main+0xae>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    125e <main+0xae>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
lea    0xdc0(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <connectUDP@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x38(%rbp)
lea    0xdb0(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%edi
mov    %eax,%edx
lea    0xd9f(%rip),%rsi
call   1030 <write@plt>
mov    -0x2c(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x8,%edx
call   1080 <read@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    12cb <main+0x11b>
mov    0x2d22(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    %eax,%esi
lea    0xd77(%rip),%rdi
call   1090 <errexit@plt>
mov    -0x28(%rbp),%rdi
call   10c0 <ntohl@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movabs $0x83aa7e80,%rcx
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
lea    -0x28(%rbp),%rdi
call   1040 <ctime@plt>
mov    %rax,%rsi
lea    0xd4e(%rip),%rdi
call   1060 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rax
lea    0xe4c(%rip),%rsi
cmp    $0x1,%edi
je     11db <main+0x2b>
cmp    $0x2,%edi
je     11d5 <main+0x25>
cmp    $0x3,%edi
jne    126b <main+0xbb>
mov    0x10(%rax),%rsi
mov    0x8(%rax),%rdi
jmp    11e2 <main+0x32>
lea    0xe1e(%rip),%rdi
call   1070 <connectUDP@plt>
mov    %eax,%ebx
lea    0xe3b(%rip),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1080 <read@plt>
test   %eax,%eax
jns    1233 <main+0x83>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xe11(%rip),%rdi
mov    %eax,%esi
call   1090 <errexit@plt>
mov    (%rsp),%rdi
call   10c0 <ntohl@plt>
movabs $0xffffffff7c558180,%rcx
ff ff ff
add    %rax,%rcx
mov    %rcx,(%rsp)
mov    %rsp,%rdi
call   1040 <ctime@plt>
lea    0xdf2(%rip),%rdi
mov    %rax,%rsi
call   1060 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
lea    0xd94(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"localhost\00"
@.str.1 = [5 x i8] c"time\00"
@stderr = global i32 0
@.str.2 = [28 x i8] c"usage: UDPtime[host[port]]\0A\00"
@.str.3 = [18 x i8] c"what time is it?\0A\00"
@.str.4 = [17 x i8] c"read failed: %s\0A\00"
@errno = global i32 0
@.str.5 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %7
%11 = load i32, i32* %4
switch i32 %11, label %21 [
i32 1, label %12
i32 3, label %13
i32 2, label %17
]
12: ; preds = %2
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %6
br label %25
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 2
%16 = load i8*, i8** %15
store i8* %16, i8** %7
br label %17
17: ; preds = %2, %13
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
store i8* %20, i8** %6
br label %25
21: ; preds = %2
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %17, %12
%26 = load i8*, i8** %6
%27 = load i8*, i8** %7
%28 = call i32 @connectUDP(i8* %26, i8* %27)
store i32 %28, i32* %9
%29 = load i32, i32* %9
%30 = call i32 @strlen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 @write(i32 %29, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %9
%33 = bitcast i64* %8 to i8*
%34 = call i32 @read(i32 %32, i8* %33, i32 8)
store i32 %34, i32* %10
%35 = load i32, i32* %10
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %25
%38 = load i32, i32* @errno
%39 = call i32 @strerror(i32 %38)
%40 = call i32 @errexit(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %37, %25
%42 = load i64, i64* %8
%43 = call i64 @ntohl(i64 %42)
store i64 %43, i64* %8
%44 = load i64, i64* %8
%45 = sub i64 %44, 2208988800
store i64 %45, i64* %8
%46 = call i8* @ctime(i64* %8)
%47 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %46)
%48 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [10 x i8] c"localhost\00"
@.str.1 = [5 x i8] c"time\00"
@stderr = global i32 0
@.str.2 = [28 x i8] c"usage: UDPtime[host[port]]\0A\00"
@.str.3 = [18 x i8] c"what time is it?\0A\00"
@.str.4 = [17 x i8] c"read failed: %s\0A\00"
@errno = global i32 0
@.str.5 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
switch i32 %0, label %12 [
i32 1, label %16
i32 3, label %5
i32 2, label %8
]
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 2
%7 = load i8*, i8** %6
br label %8
8: ; preds = %2, %5
%9 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %2 ], [ %7, %5 ]
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
br label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2, %8
%17 = phi i8* [ %9, %8 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %2 ]
%18 = phi i8* [ %11, %8 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %2 ]
%19 = tail call i32 @connectUDP(i8* %18, i8* %17)
%20 = tail call i32 @strlen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%21 = tail call i32 @write(i32 %19, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %20)
%22 = call i32 @read(i32 %19, i8* %4, i32 8)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %16
%25 = load i32, i32* @errno
%26 = tail call i32 @strerror(i32 %25)
%27 = tail call i32 @errexit(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %24, %16
%29 = load i64, i64* %3
%30 = tail call i64 @ntohl(i64 %29)
%31 = add i64 %30, -2208988800
store i64 %31, i64* %3
%32 = call i8* @ctime(i64* %3)
%33 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %32)
%34 = call i32 @exit(i32 0)
unreachable
}