#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 */

/* Variables and functions */
int connectUDP(char const *, char const *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
UDPdaytime(const char *host, const char *service) {
  char buf[128 + 1];
  int s, n;
  s = connectUDP(host, service);
  (void)write(s, "what time is it?\n", strlen("what time is it?\n"));
  n = read(s, buf, 128);
  buf[n] = '\0';
  (void)fputs(buf, stdout);
}


x86 assembly (clang, -O0):
<UDPdaytime>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <connectUDP@plt>
mov    %eax,-0xa4(%rbp)
mov    -0xa4(%rbp),%eax
mov    %eax,-0xac(%rbp)
lea    0xe77(%rip),%rdi
call   1040 <strlen@plt>
mov    -0xac(%rbp),%edi
mov    %eax,%edx
lea    0xe63(%rip),%rsi
call   1030 <write@plt>
mov    -0xa4(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x80,%edx
call   1070 <read@plt>
mov    %eax,-0xa8(%rbp)
movslq -0xa8(%rbp),%rax
movb   $0x0,-0xa0(%rbp,%rax,1)
lea    -0xa0(%rbp),%rdi
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
call   1050 <fputs@plt>
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UDPdaytime>:
push   %r14
push   %rbx
sub    $0x88,%rsp
call   1060 <connectUDP@plt>
mov    %eax,%ebx
lea    0xe98(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %rsp,%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x80,%edx
call   1070 <read@plt>
cltq
movb   $0x0,(%rsp,%rax,1)
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1050 <fputs@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [18 x i8] c"what time is it?\0A\00"
@stdout = global i32 0
define i32 @UDPdaytime(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [129 x i8]
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = load i8*, i8** %5
%11 = call i32 @connectUDP(i8* %9, i8* %10)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = call i32 @strlen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @write(i32 %12, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %7
%16 = getelementptr inbounds [129 x i8], [129 x i8]* %6, i64 0, i64 0
%17 = call i32 @read(i32 %15, i8* %16, i32 128)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [129 x i8], [129 x i8]* %6, i64 0, i64 %19
store i8 0, i8* %20
%21 = getelementptr inbounds [129 x i8], [129 x i8]* %6, i64 0, i64 0
%22 = load i32, i32* @stdout
%23 = call i32 @fputs(i8* %21, i32 %22)
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@.str = [18 x i8] c"what time is it?\0A\00"
@stdout = global i32 0
define i32 @UDPdaytime(i8* %0, i8* %1) {
%3 = alloca [129 x i8]
%4 = getelementptr inbounds [129 x i8], [129 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @connectUDP(i8* %0, i8* %1)
%6 = tail call i32 @strlen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @write(i32 %5, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = call i32 @read(i32 %5, i8* %4, i32 128)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [129 x i8], [129 x i8]* %3, i64 0, i64 %9
store i8 0, i8* %10
%11 = load i32, i32* @stdout
%12 = call i32 @fputs(i8* %4, i32 %11)
ret i32 undef
}