#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 /*<<< orphan*/ close(int);
int open_client_socket(char *, int);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
int sendCommand(char *host, int port, char *command, char *response) {
  int sock = open_client_socket(host, port);
  if (sock < 0) {
    return 0;
  }
  write(sock, command, strlen(command));
  write(sock, "\r\n", 2);
  write(1, command, strlen(command));
  write(1, "\r\n", 2);
  int n = 0;
  int len = 0;
  while ((n = read(sock, response + len, (10 * 1024) - len)) > 0) {
    len += n;
  }
  response[len] = 0;
  printf("response:\n%s\n", response);
  close(sock);
  return 1;
}


x86 assembly (clang, -O0):
<sendCommand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1080 <open_client_socket@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    119c <sendCommand+0x3c>
movl   $0x0,-0x4(%rbp)
jmp    127a <sendCommand+0x11a>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x2c(%rbp),%edi
lea    0xe35(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
mov    $0x1,%edi
call   1030 <write@plt>
mov    $0x1,%edi
lea    0xdfe(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
movslq -0x34(%rbp),%rax
add    %rax,%rsi
mov    $0x2800,%edx
sub    -0x34(%rbp),%edx
call   1070 <read@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
jle    124f <sendCommand+0xef>
mov    -0x30(%rbp),%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    121a <sendCommand+0xba>
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rsi
lea    0xd9d(%rip),%rdi
call   1050 <printf@plt>
mov    -0x2c(%rbp),%edi
call   1060 <close@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendCommand>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r15
mov    %rdx,%r14
call   1080 <open_client_socket@plt>
test   %eax,%eax
js     1220 <sendCommand+0xc0>
mov    %eax,%r12d
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %r12d,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    0xe66(%rip),%rbx
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1030 <write@plt>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
movslq %ebp,%rbp
lea    (%r15,%rbp,1),%rbx
mov    $0x2800,%edx
sub    %ebp,%edx
mov    %r12d,%edi
mov    %rbx,%rsi
call   1070 <read@plt>
add    %eax,%ebp
test   %eax,%eax
jg     11e0 <sendCommand+0x80>
movb   $0x0,(%rbx)
lea    0xdfa(%rip),%rdi
mov    %r15,%rsi
call   1050 <printf@plt>
mov    %r12d,%edi
call   1060 <close@plt>
mov    $0x1,%eax
jmp    1222 <sendCommand+0xc2>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\0D\0A\00"
@.str.1 = [14 x i8] c"response:\0A%s\0A\00"
define i32 @sendCommand(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%13 = load i8*, i8** %6
%14 = load i32, i32* %7
%15 = call i32 @open_client_socket(i8* %13, i32 %14)
store i32 %15, i32* %10
%16 = load i32, i32* %10
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %4
store i32 0, i32* %5
br label %55
19: ; preds = %4
%20 = load i32, i32* %10
%21 = load i8*, i8** %8
%22 = load i8*, i8** %8
%23 = call i32 @strlen(i8* %22)
%24 = call i32 @write(i32 %20, i8* %21, i32 %23)
%25 = load i32, i32* %10
%26 = call i32 @write(i32 %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%27 = load i8*, i8** %8
%28 = load i8*, i8** %8
%29 = call i32 @strlen(i8* %28)
%30 = call i32 @write(i32 1, i8* %27, i32 %29)
%31 = call i32 @write(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
store i32 0, i32* %11
store i32 0, i32* %12
br label %32
32: ; preds = %42, %19
%33 = load i32, i32* %10
%34 = load i8*, i8** %9
%35 = load i32, i32* %12
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i32, i32* %12
%39 = sub nsw i32 10240, %38
%40 = call i32 @read(i32 %33, i8* %37, i32 %39)
store i32 %40, i32* %11
%41 = icmp sgt i32 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %32
%43 = load i32, i32* %11
%44 = load i32, i32* %12
%45 = add nsw i32 %44, %43
store i32 %45, i32* %12
br label %32
46: ; preds = %32
%47 = load i8*, i8** %9
%48 = load i32, i32* %12
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
store i8 0, i8* %50
%51 = load i8*, i8** %9
%52 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %51)
%53 = load i32, i32* %10
%54 = call i32 @close(i32 %53)
store i32 1, i32* %5
br label %55
55: ; preds = %46, %18
%56 = load i32, i32* %5
ret i32 %56
}

LLVM IR (-O2):
@.str = [3 x i8] c"\0D\0A\00"
@.str.1 = [14 x i8] c"response:\0A%s\0A\00"
define i32 @sendCommand(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = tail call i32 @open_client_socket(i8* %0, i32 %1)
%6 = icmp slt i32 %5, 0
br i1 %6, label %25, label %7
7: ; preds = %4
%8 = tail call i32 @strlen(i8* %2)
%9 = tail call i32 @write(i32 %5, i8* %2, i32 %8)
%10 = tail call i32 @write(i32 %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%11 = tail call i32 @strlen(i8* %2)
%12 = tail call i32 @write(i32 1, i8* %2, i32 %11)
%13 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
br label %14
14: ; preds = %14, %7
%15 = phi i32 [ 0, %7 ], [ %21, %14 ]
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %3, i64 %16
%18 = sub nsw i32 10240, %15
%19 = tail call i32 @read(i32 %5, i8* %17, i32 %18)
%20 = icmp sgt i32 %19, 0
%21 = add nsw i32 %19, %15
br i1 %20, label %14, label %22
22: ; preds = %14
store i8 0, i8* %17
%23 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%24 = tail call i32 @close(i32 %5)
br label %25
25: ; preds = %4, %22
%26 = phi i32 [ 1, %22 ], [ 0, %4 ]
ret i32 %26
}