#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 int /*<<< orphan*/ time_t;
struct tm {
  int tm_gmtoff;
};
struct sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ outstr;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ bzero(char *, int);
int connectUdp(int *, struct sockaddr_in *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ localtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *,
             unsigned int *);
int sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct sockaddr const *, unsigned int);
scalar_t__ stime(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  if (argc < 3) {
    return 0;
  }
  int n, sock;
  struct sockaddr_in server, from;
  n = connectUdp(&sock, &server, argv[1], atoi(argv[2]));
  if (n < 0) {
    printf("error connectudp %d\n", n);
    return 1;
  }
  char buffer[1024];
  bzero(buffer, 1024);
  strcpy(buffer, "CNOPERATION_GET_UTC_TIME");
  unsigned int stlen = sizeof(struct sockaddr);
  n = sendto(sock, buffer, strlen(buffer), 0, (const struct sockaddr *)&server,
             stlen);
  if (n < 0) {
    printf("error send %d\n", n);
    return 1;
  }
  printf("requesting UTC time ....\n");
  n = recvfrom(sock, buffer, sizeof(buffer), 0, (struct sockaddr *)&from,
               &stlen);
  if (n < 0) {
    printf("error recvfrom %d\n", n);
    return 1;
  }
  printf("got respond!\n");
  time_t *t = (void *)buffer;
  struct tm srvt;
  localtime_r(t, &srvt);
  long hour = (srvt.tm_gmtoff / 60) / 60;
  printf("gmt offset %ldh\n", hour);
  char outstr[200];
  strftime(outstr, sizeof(outstr), "%a, %d %b %y %T %z", &srvt);
  printf("%s\n", outstr);
  if (stime(t) < 0) {
    printf("failed to set the time.\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x540,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11df <main+0x2f>
movl   $0x0,-0x4(%rbp)
jmp    13f2 <main+0x242>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x528(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10d0 <atoi@plt>
mov    -0x528(%rbp),%rdx
mov    %eax,%ecx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <connectUdp@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    123b <main+0x8b>
mov    -0x14(%rbp),%esi
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13f2 <main+0x242>
lea    -0x430(%rbp),%rdi
mov    $0x400,%esi
call   10c0 <bzero@plt>
lea    -0x430(%rbp),%rdi
lea    0xdbb(%rip),%rsi
call   1040 <strcpy@plt>
movl   $0x4,-0x434(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x534(%rbp)
lea    -0x430(%rbp),%rax
mov    %rax,-0x530(%rbp)
lea    -0x430(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x534(%rbp),%edi
mov    -0x530(%rbp),%rsi
mov    %eax,%edx
lea    -0x20(%rbp),%r8
mov    -0x434(%rbp),%r9d
xor    %ecx,%ecx
call   1080 <sendto@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12d7 <main+0x127>
mov    -0x14(%rbp),%esi
lea    0xd6a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13f2 <main+0x242>
lea    0xd5f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%edi
lea    -0x430(%rbp),%rsi
lea    -0x28(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0x434(%rbp),%r9
call   10a0 <recvfrom@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1330 <main+0x180>
mov    -0x14(%rbp),%esi
lea    0xd3a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13f2 <main+0x242>
lea    0xd33(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x430(%rbp),%rax
mov    %rax,-0x440(%rbp)
mov    -0x440(%rbp),%rdi
lea    -0x448(%rbp),%rsi
call   1030 <localtime_r@plt>
mov    -0x448(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    $0x3c,%ecx
cltd
idiv   %ecx
cltq
mov    %rax,-0x450(%rbp)
mov    -0x450(%rbp),%rsi
lea    0xcec(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x520(%rbp),%rdi
mov    $0xc8,%esi
lea    0xce3(%rip),%rdx
lea    -0x448(%rbp),%rcx
call   10b0 <strftime@plt>
lea    -0x520(%rbp),%rsi
lea    0xcdc(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x440(%rbp),%rdi
call   1090 <stime@plt>
cmp    $0x0,%rax
jge    13eb <main+0x23b>
lea    0xcbc(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x540,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x4f8,%rsp
xor    %ebx,%ebx
cmp    $0x3,%edi
jl     1349 <main+0x189>
mov    0x8(%rsi),%rbx
mov    0x10(%rsi),%rdi
call   10e0 <atoi@plt>
lea    0x4(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1060 <connectUdp@plt>
test   %eax,%eax
js     1322 <main+0x162>
lea    0xf0(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
call   10d0 <bzero@plt>
lea    0xdf8(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcpy@plt>
movl   $0x4,0x14(%rsp)
mov    0x4(%rsp),%ebp
mov    %rbx,%rdi
call   1070 <strlen@plt>
lea    0x10(%rsp),%r8
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1090 <sendto@plt>
test   %eax,%eax
js     132b <main+0x16b>
lea    0xe13(%rip),%rdi
call   1050 <puts@plt>
mov    0x4(%rsp),%edi
lea    0xf0(%rsp),%rsi
lea    0x18(%rsp),%r8
lea    0x14(%rsp),%r9
mov    $0x400,%edx
xor    %ecx,%ecx
call   10b0 <recvfrom@plt>
test   %eax,%eax
js     1334 <main+0x174>
lea    0xdf6(%rip),%rdi
call   1050 <puts@plt>
lea    0xf0(%rsp),%r14
lea    0x8(%rsp),%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <localtime_r@plt>
movslq 0x8(%rsp),%rax
imul   $0xffffffff91a2b3c5,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%eax
shr    $0x1f,%eax
sar    $0xb,%ecx
add    %eax,%ecx
movslq %ecx,%rsi
lea    0xd76(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xd77(%rip),%rdx
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    $0xc8,%esi
mov    %r15,%rcx
call   10c0 <strftime@plt>
mov    %rbp,%rdi
call   1050 <puts@plt>
mov    %r14,%rdi
call   10a0 <stime@plt>
test   %rax,%rax
jns    1349 <main+0x189>
lea    0xd7f(%rip),%rdi
call   1050 <puts@plt>
jmp    1349 <main+0x189>
lea    0xcd7(%rip),%rdi
jmp    133b <main+0x17b>
lea    0xcfc(%rip),%rdi
jmp    133b <main+0x17b>
lea    0xd02(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x4f8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.tm = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [21 x i8] c"error connectudp %d\0A\00"
@.str.1 = [25 x i8] c"CNOPERATION_GET_UTC_TIME\00"
@.str.2 = [15 x i8] c"error send %d\0A\00"
@.str.3 = [26 x i8] c"requesting UTC time ....\0A\00"
@.str.4 = [19 x i8] c"error recvfrom %d\0A\00"
@.str.5 = [14 x i8] c"got respond!\0A\00"
@.str.6 = [17 x i8] c"gmt offset %ldh\0A\00"
@.str.7 = [19 x i8] c"%a, %d %b %y %T %z\00"
@.str.8 = [4 x i8] c"%s\0A\00"
@.str.9 = [25 x i8] c"failed to set the time.\0A\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 %struct.sockaddr_in
%9 = alloca %struct.sockaddr_in
%10 = alloca [1024 x i8]
%11 = alloca i32
%12 = alloca i32*
%13 = alloca %struct.tm
%14 = alloca i64
%15 = alloca [200 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 3
br i1 %17, label %18, label %19
18: ; preds = %2
store i32 0, i32* %3
br label %84
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
%27 = call i32 @connectUdp(i32* %7, %struct.sockaddr_in* %8, i8* %22, i32 %26)
store i32 %27, i32* %6
%28 = load i32, i32* %6
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %19
%31 = load i32, i32* %6
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %31)
store i32 1, i32* %3
br label %84
33: ; preds = %19
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%35 = call i32 @bzero(i8* %34, i32 1024)
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%37 = call i32 @strcpy(i8* %36, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 4, i32* %11
%38 = load i32, i32* %7
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%41 = call i32 @strlen(i8* %40)
%42 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%43 = load i32, i32* %11
%44 = call i32 @sendto(i32 %38, i8* %39, i32 %41, i32 0, %struct.sockaddr* %42, i32 %43)
store i32 %44, i32* %6
%45 = load i32, i32* %6
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %33
%48 = load i32, i32* %6
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %48)
store i32 1, i32* %3
br label %84
50: ; preds = %33
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%52 = load i32, i32* %7
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%54 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%55 = call i32 @recvfrom(i32 %52, i8* %53, i32 1024, i32 0, %struct.sockaddr* %54, i32* %11)
store i32 %55, i32* %6
%56 = load i32, i32* %6
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %50
%59 = load i32, i32* %6
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %59)
store i32 1, i32* %3
br label %84
61: ; preds = %50
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%63 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%64 = bitcast i8* %63 to i32*
store i32* %64, i32** %12
%65 = load i32*, i32** %12
%66 = call i32 @localtime_r(i32* %65, %struct.tm* %13)
%67 = getelementptr inbounds %struct.tm, %struct.tm* %13, i32 0, i32 0
%68 = load i32, i32* %67
%69 = sdiv i32 %68, 60
%70 = sdiv i32 %69, 60
%71 = sext i32 %70 to i64
store i64 %71, i64* %14
%72 = load i64, i64* %14
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i64 %72)
%74 = getelementptr inbounds [200 x i8], [200 x i8]* %15, i64 0, i64 0
%75 = call i32 @strftime(i8* %74, i32 200, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), %struct.tm* %13)
%76 = getelementptr inbounds [200 x i8], [200 x i8]* %15, i64 0, i64 0
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %76)
%78 = load i32*, i32** %12
%79 = call i64 @stime(i32* %78)
%80 = icmp slt i64 %79, 0
br i1 %80, label %81, label %83
81: ; preds = %61
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0))
br label %83
83: ; preds = %81, %61
store i32 0, i32* %3
br label %84
84: ; preds = %83, %58, %47, %30, %18
%85 = load i32, i32* %3
ret i32 %85
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.tm = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [21 x i8] c"error connectudp %d\0A\00"
@.str.1 = [25 x i8] c"CNOPERATION_GET_UTC_TIME\00"
@.str.2 = [15 x i8] c"error send %d\0A\00"
@.str.4 = [19 x i8] c"error recvfrom %d\0A\00"
@.str.6 = [17 x i8] c"gmt offset %ldh\0A\00"
@.str.7 = [19 x i8] c"%a, %d %b %y %T %z\00"
@str = [25 x i8] c"requesting UTC time ....\00"
@str.10 = [13 x i8] c"got respond!\00"
@str.11 = [24 x i8] c"failed to set the time.\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 = alloca i32
%8 = alloca %struct.tm
%9 = alloca [200 x i8]
%10 = icmp slt i32 %0, 3
br i1 %10, label %66, label %11
11: ; preds = %2
%12 = bitcast i32* %3 to i8*
%13 = bitcast %struct.sockaddr_in* %4 to i8*
%14 = bitcast %struct.sockaddr_in* %5 to i8*
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i32 @atoi(i8* %18)
%20 = call i32 @connectUdp(i32* %3, %struct.sockaddr_in* %4, i8* %16, i32 %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %11
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %20)
br label %64
24: ; preds = %11
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%26 = call i32 @bzero(i8* %25, i32 1024)
%27 = call i32 @strcpy(i8* %25, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%28 = bitcast i32* %7 to i8*
store i32 4, i32* %7
%29 = load i32, i32* %3
%30 = call i32 @strlen(i8* %25)
%31 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%32 = call i32 @sendto(i32 %29, i8* %25, i32 %30, i32 0, %struct.sockaddr* %31, i32 4)
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %24
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %32)
br label %62
36: ; preds = %24
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%38 = load i32, i32* %3
%39 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%40 = call i32 @recvfrom(i32 %38, i8* %25, i32 1024, i32 0, %struct.sockaddr* %39, i32* %7)
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %36
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %40)
br label %62
44: ; preds = %36
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.10, i64 0, i64 0))
%46 = bitcast [1024 x i8]* %6 to i32*
%47 = bitcast %struct.tm* %8 to i8*
%48 = call i32 @localtime_r(i32* %46, %struct.tm* %8)
%49 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 0
%50 = load i32, i32* %49
%51 = sdiv i32 %50, 3600
%52 = sext i32 %51 to i64
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i64 %52)
%54 = getelementptr inbounds [200 x i8], [200 x i8]* %9, i64 0, i64 0
%55 = call i32 @strftime(i8* %54, i32 200, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), %struct.tm* %8)
%56 = call i32 @puts(i8* %54)
%57 = call i64 @stime(i32* %46)
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %44
%60 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.11, i64 0, i64 0))
br label %61
61: ; preds = %59, %44
br label %62
62: ; preds = %61, %42, %34
%63 = phi i32 [ 1, %34 ], [ 1, %42 ], [ 0, %61 ]
br label %64
64: ; preds = %62, %22
%65 = phi i32 [ 1, %22 ], [ %63, %62 ]
br label %66
66: ; preds = %2, %64
%67 = phi i32 [ %65, %64 ], [ 0, %2 ]
ret i32 %67
}