#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 */
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  scalar_t__ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  scalar_t__ h_addrtype;
  char **h_addr_list;
};
typedef int /*<<< orphan*/ str;
typedef int /*<<< orphan*/ servaddr;

/* Variables and functions */
scalar_t__ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ dg_snd(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ h_errno;
char *hstrerror(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_ntop(scalar_t__, char *, char *, int);
int /*<<< orphan*/ inet_pton(scalar_t__, char *, int /*<<< orphan*/ *);
int socket(scalar_t__, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc < 2) {
    fprintf(stderr, "./queryTimeServer timeserver1.upenn.edu\n"
                    "or\n"
                    "./queryTimeServer timex.usg.edu\n"
                    "./queryTimeServer ntp.linux.org.ve\n"
                    "./queryTimeServer ntp.pop-pr.rnp.br\n\n");
    exit(1);
  }
  int sockfd;
  struct sockaddr_in servaddr;
  char **pptr;
  char str[50];
  struct hostent *hptr;
  if ((hptr = gethostbyname(argv[1])) == NULL) {
    fprintf(stderr, " gethostbyname error for host: %s: %s", argv[1],
            hstrerror(h_errno));
    exit(1);
  }
  if (hptr->h_addrtype == AF_INET && (pptr = hptr->h_addr_list) != NULL) {
    inet_ntop(hptr->h_addrtype, *pptr, str, sizeof(str));
  } else {
    fprintf(stderr, "Error call inet_ntop \n");
  }
  sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  if (sockfd == -1)
    fprintf(stderr, "Error in socket \n");
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(123);
  inet_pton(AF_INET, str, &servaddr.sin_addr);
  if (connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) == -1)
    fprintf(stderr, "Error in connect \n");
  dg_snd(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
  close(sockfd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1204 <main+0x44>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
lea    0xe0d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,-0x78(%rbp)
cmp    $0x0,%rax
jne    126d <main+0xad>
mov    0x2da2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x84(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x80(%rbp)
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
call   10b0 <hstrerror@plt>
mov    -0x84(%rbp),%edi
mov    -0x80(%rbp),%rdx
mov    %rax,%rcx
lea    0xe38(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x78(%rbp),%rax
mov    (%rax),%rax
mov    0x2d6d(%rip),%rcx
cmp    (%rcx),%rax
jne    12bb <main+0xfb>
mov    -0x78(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     12bb <main+0xfb>
mov    -0x78(%rbp),%rax
mov    (%rax),%rdi
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
lea    -0x70(%rbp),%rdx
mov    $0x32,%ecx
call   1030 <inet_ntop@plt>
jmp    12d2 <main+0x112>
mov    0x2d06(%rip),%rax
mov    (%rax),%edi
lea    0xdef(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d0f(%rip),%rax
mov    (%rax),%rdi
mov    0x2cfd(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1310 <main+0x150>
mov    0x2cc8(%rip),%rax
mov    (%rax),%edi
lea    0xdc8(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
lea    -0x28(%rbp),%rdi
mov    $0x10,%esi
call   10a0 <bzero@plt>
mov    0x2cc3(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    $0x7b,%edi
call   1040 <htons@plt>
mov    %eax,-0x24(%rbp)
mov    0x2ca8(%rip),%rax
mov    (%rax),%rdi
lea    -0x70(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1080 <inet_pton@plt>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x10,%edx
call   10d0 <connect@plt>
cmp    $0xffffffff,%eax
jne    1381 <main+0x1c1>
mov    0x2c57(%rip),%rax
mov    (%rax),%edi
lea    0xd69(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x10,%edx
call   1090 <dg_snd@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
cmp    $0x1,%edi
jg     11ee <main+0x2e>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
lea    0xe23(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1060 <gethostbyname@plt>
test   %rax,%rax
jne    123a <main+0x7a>
mov    0x2dc2(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%rbx),%rbx
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
call   10b0 <hstrerror@plt>
lea    0xe73(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    (%rax),%rdi
mov    0x2da4(%rip),%r14
cmp    (%r14),%rdi
jne    1252 <main+0x92>
mov    0x8(%rax),%rax
test   %rax,%rax
jne    126b <main+0xab>
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    127d <main+0xbd>
mov    (%rax),%rsi
lea    0x10(%rsp),%rdx
mov    $0x32,%ecx
call   1030 <inet_ntop@plt>
mov    (%r14),%rdi
mov    0x2d59(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    12ae <main+0xee>
mov    0x2d2a(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x10,%esi
call   10a0 <bzero@plt>
mov    (%r14),%rax
mov    %rax,0x8(%rsp)
mov    $0x7b,%edi
call   1040 <htons@plt>
mov    %eax,0x4(%rsp)
mov    (%r14),%rdi
lea    0x10(%rsp),%rsi
mov    %rbp,%rdx
call   1080 <inet_pton@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x10,%edx
call   10d0 <connect@plt>
cmp    $0xffffffff,%eax
jne    130f <main+0x14f>
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
lea    0xddb(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x10,%edx
call   1090 <dg_snd@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i64 }
%struct.hostent = type { i64, i8** }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [148 x i8] c"./queryTimeServer timeserver1.upenn.edu\0Aor\0A./queryTimeServer timex.usg.edu\0A./queryTimeServer ntp.linux.org.ve\0A./queryTimeServer ntp.pop-pr.rnp.br\0A\0A\00"
@.str.1 = [38 x i8] c" gethostbyname error for host: %s: %s\00"
@h_errno = global i32 0
@AF_INET = global i64 0
@.str.2 = [23 x i8] c"Error call inet_ntop \0A\00"
@SOCK_DGRAM = global i32 0
@.str.3 = [18 x i8] c"Error in socket \0A\00"
@.str.4 = [19 x i8] c"Error in connect \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca i8**
%9 = alloca [50 x i8]
%10 = alloca %struct.hostent*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call %struct.hostent* @gethostbyname(i8* %20)
store %struct.hostent* %21, %struct.hostent** %10
%22 = icmp eq %struct.hostent* %21, null
br i1 %22, label %23, label %32
23: ; preds = %17
%24 = load i32, i32* @stderr
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = load i32, i32* @h_errno
%29 = call i8* @hstrerror(i32 %28)
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %27, i8* %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %17
%33 = load %struct.hostent*, %struct.hostent** %10
%34 = getelementptr inbounds %struct.hostent, %struct.hostent* %33, i32 0, i32 0
%35 = load i64, i64* %34
%36 = load i64, i64* @AF_INET
%37 = icmp eq i64 %35, %36
br i1 %37, label %38, label %51
38: ; preds = %32
%39 = load %struct.hostent*, %struct.hostent** %10
%40 = getelementptr inbounds %struct.hostent, %struct.hostent* %39, i32 0, i32 1
%41 = load i8**, i8*** %40
store i8** %41, i8*** %8
%42 = icmp ne i8** %41, null
br i1 %42, label %43, label %51
43: ; preds = %38
%44 = load %struct.hostent*, %struct.hostent** %10
%45 = getelementptr inbounds %struct.hostent, %struct.hostent* %44, i32 0, i32 0
%46 = load i64, i64* %45
%47 = load i8**, i8*** %8
%48 = load i8*, i8** %47
%49 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%50 = call i32 @inet_ntop(i64 %46, i8* %48, i8* %49, i32 50)
br label %54
51: ; preds = %38, %32
%52 = load i32, i32* @stderr
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %54
54: ; preds = %51, %43
%55 = load i64, i64* @AF_INET
%56 = load i32, i32* @SOCK_DGRAM
%57 = call i32 @socket(i64 %55, i32 %56, i32 0)
store i32 %57, i32* %6
%58 = load i32, i32* %6
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %63
60: ; preds = %54
%61 = load i32, i32* @stderr
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %63
63: ; preds = %60, %54
%64 = call i32 @bzero(%struct.sockaddr_in* %7, i32 16)
%65 = load i64, i64* @AF_INET
%66 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i64 %65, i64* %66
%67 = call i32 @htons(i32 123)
%68 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %67, i32* %68
%69 = load i64, i64* @AF_INET
%70 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%71 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%72 = call i32 @inet_pton(i64 %69, i8* %70, i32* %71)
%73 = load i32, i32* %6
%74 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%75 = call i32 @connect(i32 %73, %struct.sockaddr* %74, i32 16)
%76 = icmp eq i32 %75, -1
br i1 %76, label %77, label %80
77: ; preds = %63
%78 = load i32, i32* @stderr
%79 = call i32 (i32, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %80
80: ; preds = %77, %63
%81 = load i32, i32* %6
%82 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%83 = call i32 @dg_snd(i32 %81, %struct.sockaddr* %82, i32 16)
%84 = load i32, i32* %6
%85 = call i32 @close(i32 %84)
%86 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i64 }
%struct.hostent = type { i64, i8** }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [148 x i8] c"./queryTimeServer timeserver1.upenn.edu\0Aor\0A./queryTimeServer timex.usg.edu\0A./queryTimeServer ntp.linux.org.ve\0A./queryTimeServer ntp.pop-pr.rnp.br\0A\0A\00"
@.str.1 = [38 x i8] c" gethostbyname error for host: %s: %s\00"
@h_errno = global i32 0
@AF_INET = global i64 0
@.str.2 = [23 x i8] c"Error call inet_ntop \0A\00"
@SOCK_DGRAM = global i32 0
@.str.3 = [18 x i8] c"Error in socket \0A\00"
@.str.4 = [19 x i8] c"Error in connect \0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [50 x i8]
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = bitcast %struct.sockaddr_in* %3 to i8*
%12 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call %struct.hostent* @gethostbyname(i8* %14)
%16 = icmp eq %struct.hostent* %15, null
br i1 %16, label %17, label %24
17: ; preds = %10
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %13
%20 = load i32, i32* @h_errno
%21 = tail call i8* @hstrerror(i32 %20)
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* %21)
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %10
%25 = getelementptr inbounds %struct.hostent, %struct.hostent* %15, i64 0, i32 0
%26 = load i64, i64* %25
%27 = load i64, i64* @AF_INET
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %36
29: ; preds = %24
%30 = getelementptr inbounds %struct.hostent, %struct.hostent* %15, i64 0, i32 1
%31 = load i8**, i8*** %30
%32 = icmp eq i8** %31, null
br i1 %32, label %36, label %33
33: ; preds = %29
%34 = load i8*, i8** %31
%35 = call i32 @inet_ntop(i64 %26, i8* %34, i8* %12, i32 50)
br label %39
36: ; preds = %29, %24
%37 = load i32, i32* @stderr
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %36, %33
%40 = load i64, i64* @AF_INET
%41 = load i32, i32* @SOCK_DGRAM
%42 = call i32 @socket(i64 %40, i32 %41, i32 0)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %47
44: ; preds = %39
%45 = load i32, i32* @stderr
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %47
47: ; preds = %44, %39
%48 = call i32 @bzero(%struct.sockaddr_in* %3, i32 16)
%49 = load i64, i64* @AF_INET
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i64 %49, i64* %50
%51 = call i32 @htons(i32 123)
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %51, i32* %52
%53 = load i64, i64* @AF_INET
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%55 = call i32 @inet_pton(i64 %53, i8* %12, i32* %54)
%56 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%57 = call i32 @connect(i32 %42, %struct.sockaddr* %56, i32 16)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %62
59: ; preds = %47
%60 = load i32, i32* @stderr
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %62
62: ; preds = %59, %47
%63 = call i32 @dg_snd(i32 %42, %struct.sockaddr* %56, i32 16)
%64 = call i32 @close(i32 %42)
%65 = call i32 @exit(i32 0)
unreachable
}