#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 ssize_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int strlen(char *);
int write(int, char *, int);
int /*<<< orphan*/ write_int(int, int);
unsigned write_string(int socket, char string[]) {
  int length = strlen(string) + 1;
  write_int(socket, length);
  ssize_t rvalue = write(socket, string, length);
  if (rvalue == -1) {
    perror("send_string - Failed to write string");
    exit(EXIT_FAILURE);
  }
  return rvalue;
}


x86 assembly (clang, -O0):
<write_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1050 <write_int@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11af <write_string+0x5f>
lea    0xe64(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_string>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    %rsi,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%ebx
mov    %ebp,%edi
mov    %ebx,%esi
call   1050 <write_int@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     1183 <write_string+0x33>
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe76(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"send_string - Failed to write string\00"
@EXIT_FAILURE = global i32 0
define i32 @write_string(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i32 @strlen(i8* %7)
%9 = add nsw i32 %8, 1
store i32 %9, i32* %5
%10 = load i32, i32* %3
%11 = load i32, i32* %5
%12 = call i32 @write_int(i32 %10, i32 %11)
%13 = load i32, i32* %3
%14 = load i8*, i8** %4
%15 = load i32, i32* %5
%16 = call i32 @write(i32 %13, i8* %14, i32 %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %23
19: ; preds = %2
%20 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %2
%24 = load i32, i32* %6
ret i32 %24
}

LLVM IR (-O2):
@.str = [37 x i8] c"send_string - Failed to write string\00"
@EXIT_FAILURE = global i32 0
define i32 @write_string(i32 %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = add nsw i32 %3, 1
%5 = tail call i32 @write_int(i32 %0, i32 %4)
%6 = tail call i32 @write(i32 %0, i8* %1, i32 %4)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
ret i32 %6
}