#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 read(int, char *, int);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncasecmp(char *, char *, int);
int write(int, char *, int /*<<< orphan*/);
int dbd_send_string(int sockfd, char *string) {
  char buffer[4096];
  int len = 0;
  if (string == NULL) {
    return -1;
  }
  len = write(sockfd, string, strlen(string));
  if (len < 0) {
    return len;
  }
  len = read(sockfd, buffer, 4096);
  if (strncasecmp(buffer, "copy", 4) != 0) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<dbd_send_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1014(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1173 <dbd_send_string+0x33>
movl   $0xffffffff,-0x4(%rbp)
jmp    1214 <dbd_send_string+0xd4>
mov    -0x8(%rbp),%eax
mov    %eax,-0x1024(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x1020(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1024(%rbp),%edi
mov    -0x1020(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x1014(%rbp)
cmpl   $0x0,-0x1014(%rbp)
jge    11c5 <dbd_send_string+0x85>
mov    -0x1014(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1214 <dbd_send_string+0xd4>
mov    -0x8(%rbp),%edi
lea    -0x1010(%rbp),%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
mov    %eax,-0x1014(%rbp)
lea    -0x1010(%rbp),%rdi
lea    0xe13(%rip),%rsi
mov    $0x4,%edx
call   1060 <strncasecmp@plt>
cmp    $0x0,%rax
je     120d <dbd_send_string+0xcd>
movl   $0xffffffff,-0x4(%rbp)
jmp    1214 <dbd_send_string+0xd4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dbd_send_string>:
push   %rbp
push   %rbx
sub    $0x1008,%rsp
test   %rsi,%rsi
je     1198 <dbd_send_string+0x58>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %eax,%eax
js     119d <dbd_send_string+0x5d>
mov    %rsp,%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
lea    0xe7c(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1060 <strncasecmp@plt>
neg    %rax
sbb    %eax,%eax
jmp    119d <dbd_send_string+0x5d>
mov    $0xffffffff,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"copy\00"
define i32 @dbd_send_string(i32 %0, i8* %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = icmp eq i8* %1, null
br i1 %5, label %15, label %6
6: ; preds = %2
%7 = tail call i32 @strlen(i8* %1)
%8 = tail call i32 @write(i32 %0, i8* %1, i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %6
%11 = call i32 @read(i32 %0, i8* %4, i32 4096)
%12 = call i64 @strncasecmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%13 = icmp ne i64 %12, 0
%14 = sext i1 %13 to i32
br label %15
15: ; preds = %10, %6, %2
%16 = phi i32 [ -1, %2 ], [ %8, %6 ], [ %14, %10 ]
ret i32 %16
}