#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 */
typedef int /*<<< orphan*/ len;

/* Variables and functions */
int SendData(int, char const *, int const);
int /*<<< orphan*/ assert(int);
int strlen(char const *);
int write(int, int const *, int);
int SendString(int socket, const char *str) {
  const int len = strlen(str);
  int sent, b;
  b = write(socket, &len, sizeof(len));
  if (b <= 0)
    return -1;
  sent = SendData(socket, str, len);
  assert(sent == len);
  return sent;
}


x86 assembly (clang, -O0):
<SendString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     1185 <SendString+0x45>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b0 <SendString+0x70>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <SendData@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SendString>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   1030 <write@plt>
test   %eax,%eax
jle    118d <SendString+0x4d>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1060 <SendData@plt>
mov    %eax,%ebp
xor    %edi,%edi
cmp    %ebx,%eax
sete   %dil
call   1050 <assert@plt>
jmp    1192 <SendString+0x52>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @SendString(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %6
%11 = load i32, i32* %4
%12 = call i32 @write(i32 %11, i32* %6, i32 4)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = icmp sle i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 -1, i32* %3
br label %27
16: ; preds = %2
%17 = load i32, i32* %4
%18 = load i8*, i8** %5
%19 = load i32, i32* %6
%20 = call i32 @SendData(i32 %17, i8* %18, i32 %19)
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = load i32, i32* %6
%23 = icmp eq i32 %21, %22
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = load i32, i32* %7
store i32 %26, i32* %3
br label %27
27: ; preds = %16, %15
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
define i32 @SendString(i32 %0, i8* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @strlen(i8* %1)
store i32 %5, i32* %3
%6 = call i32 @write(i32 %0, i32* %3, i32 4)
%7 = icmp slt i32 %6, 1
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = tail call i32 @SendData(i32 %0, i8* %1, i32 %5)
%10 = icmp eq i32 %9, %5
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
br label %13
13: ; preds = %2, %8
%14 = phi i32 [ %9, %8 ], [ -1, %2 ]
ret i32 %14
}