#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 connectTCP(char const *, char const *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ stdout;
TCPdaytime(const char *host, const char *service) {
  char buf[128 + 1];
  int s, n;
  s = connectTCP(host, service);
  while ((n = read(s, buf, 128)) > 0) {
    buf[n] = '\0';
    (void)fputs(buf, stdout);
  }
}


x86 assembly (clang, -O0):
<TCPdaytime>:
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   1050 <connectTCP@plt>
mov    %eax,-0xa4(%rbp)
mov    -0xa4(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x80,%edx
call   1040 <read@plt>
mov    %eax,-0xa8(%rbp)
cmp    $0x0,%eax
jle    11a5 <TCPdaytime+0x75>
movslq -0xa8(%rbp),%rax
movb   $0x0,-0xa0(%rbp,%rax,1)
lea    -0xa0(%rbp),%rdi
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
call   1030 <fputs@plt>
jmp    1156 <TCPdaytime+0x26>
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TCPdaytime>:
push   %rbp
push   %r14
push   %rbx
sub    $0x90,%rsp
call   1050 <connectTCP@plt>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x80,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    1184 <TCPdaytime+0x54>
mov    0x2e84(%rip),%r14
mov    %rsp,%rbx
nop
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
mov    (%r14),%esi
mov    %rbx,%rdi
call   1030 <fputs@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1040 <read@plt>
test   %eax,%eax
jg     1160 <TCPdaytime+0x30>
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
define i32 @TCPdaytime(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 @connectTCP(i8* %9, i8* %10)
store i32 %11, i32* %7
br label %12
12: ; preds = %17, %2
%13 = load i32, i32* %7
%14 = getelementptr inbounds [129 x i8], [129 x i8]* %6, i64 0, i64 0
%15 = call i32 @read(i32 %13, i8* %14, i32 128)
store i32 %15, i32* %8
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %12
%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)
br label %12
24: ; preds = %12
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@stdout = global i32 0
define i32 @TCPdaytime(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 @connectTCP(i8* %0, i8* %1)
%6 = call i32 @read(i32 %5, i8* %4, i32 128)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %2, %8
%9 = phi i32 [ %14, %8 ], [ %6, %2 ]
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds [129 x i8], [129 x i8]* %3, i64 0, i64 %10
store i8 0, i8* %11
%12 = load i32, i32* @stdout
%13 = call i32 @fputs(i8* %4, i32 %12)
%14 = call i32 @read(i32 %5, i8* %4, i32 128)
%15 = icmp sgt i32 %14, 0
br i1 %15, label %8, label %16
16: ; preds = %8, %2
ret i32 undef
}