#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*/ free(char *);
int read_safe(int, char **);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
int strlen(char *);
int write_safe(int, char *, int);
int send_command(int sfd, const char *command) {
  char send[1024], *recv;
  int len;
  sprintf(send, "%s\r\n", command);
  if (write_safe(sfd, send, strlen(send)) == -1) {
    return -1;
  }
  if ((len = read_safe(sfd, &recv)) < 0) {
    return -1;
  }
  write_safe(1, recv, len);
  free(recv);
  return 0;
}


x86 assembly (clang, -O0):
<send_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe8c(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x42c(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x428(%rbp)
lea    -0x410(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x42c(%rbp),%edi
mov    -0x428(%rbp),%rsi
mov    %eax,%edx
call   1070 <write_safe@plt>
cmp    $0xffffffff,%eax
jne    11c5 <send_command+0x75>
movl   $0xffffffff,-0x4(%rbp)
jmp    1219 <send_command+0xc9>
mov    -0x8(%rbp),%edi
lea    -0x418(%rbp),%rsi
call   1030 <read_safe@plt>
mov    %eax,-0x41c(%rbp)
cmp    $0x0,%eax
jge    11ef <send_command+0x9f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1219 <send_command+0xc9>
mov    -0x418(%rbp),%rsi
mov    -0x41c(%rbp),%edx
mov    $0x1,%edi
call   1070 <write_safe@plt>
mov    -0x418(%rbp),%rdi
call   1040 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_command>:
push   %rbp
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%rdx
mov    %edi,%ebx
lea    0xe9b(%rip),%rsi
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1060 <sprintf@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1070 <write_safe@plt>
mov    $0xffffffff,%ebp
cmp    $0xffffffff,%eax
je     11bd <send_command+0x6d>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
call   1030 <read_safe@plt>
test   %eax,%eax
js     11bd <send_command+0x6d>
mov    0x8(%rsp),%rsi
mov    $0x1,%edi
mov    %eax,%edx
call   1070 <write_safe@plt>
mov    0x8(%rsp),%rdi
call   1040 <free@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x418,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s\0D\0A\00"
define i32 @send_command(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [1024 x i8]
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%10 = load i8*, i8** %5
%11 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* %4
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%15 = call i32 @strlen(i8* %14)
%16 = call i32 @write_safe(i32 %12, i8* %13, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %19
18: ; preds = %2
store i32 -1, i32* %3
br label %30
19: ; preds = %2
%20 = load i32, i32* %4
%21 = call i32 @read_safe(i32 %20, i8** %7)
store i32 %21, i32* %8
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %19
store i32 -1, i32* %3
br label %30
24: ; preds = %19
%25 = load i8*, i8** %7
%26 = load i32, i32* %8
%27 = call i32 @write_safe(i32 1, i8* %25, i32 %26)
%28 = load i8*, i8** %7
%29 = call i32 @free(i8* %28)
store i32 0, i32* %3
br label %30
30: ; preds = %24, %23, %18
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s\0D\0A\00"
define i32 @send_command(i32 %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = alloca i8*
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = bitcast i8** %4 to i8*
%7 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %1)
%8 = call i32 @strlen(i8* %5)
%9 = call i32 @write_safe(i32 %0, i8* %5, i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %19, label %11
11: ; preds = %2
%12 = call i32 @read_safe(i32 %0, i8** %4)
%13 = icmp slt i32 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %11
%15 = load i8*, i8** %4
%16 = call i32 @write_safe(i32 1, i8* %15, i32 %12)
%17 = load i8*, i8** %4
%18 = call i32 @free(i8* %17)
br label %19
19: ; preds = %11, %2, %14
%20 = phi i32 [ 0, %14 ], [ -1, %2 ], [ -1, %11 ]
ret i32 %20
}