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

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
scalar_t__ strlen(char *);
scalar_t__ write(int, char *, scalar_t__);
int send_request(int sock, char *request) {
  ssize_t len, written;
  len = 0;
  while (len != strlen(request)) {
    written = write(sock, (request + len), strlen(request) - len);
    if (written == -1) {
      fprintf(stderr, "Write to nodogsplash failed: %s\n", strerror(errno));
      exit(1);
    }
    len += written;
  }
  return ((int)len);
}


x86 assembly (clang, -O0):
<send_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
je     120c <send_request+0xbc>
mov    -0x4(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
sub    -0x18(%rbp),%rdx
call   1030 <write@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0xffffffffffffffff,-0x20(%rbp)
jne    11fb <send_request+0xab>
mov    0x2e14(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%rdx
lea    0xe14(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1167 <send_request+0x17>
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_request>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%r14d
mov    %rsi,%rdi
call   1040 <strlen@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1198 <send_request+0x48>
nopl   0x0(%rax)
lea    (%rbx,%rbp,1),%rsi
sub    %rbp,%rax
mov    %r14d,%edi
mov    %rax,%rdx
call   1030 <write@plt>
cmp    $0xffffffffffffffff,%rax
je     119f <send_request+0x4f>
add    %rax,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    %rbp,%rax
jne    1170 <send_request+0x20>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e3a(%rip),%rax
mov    (%rax),%ebx
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe43(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"Write to nodogsplash failed: %s\0A\00"
@errno = global i32 0
define i32 @send_request(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
store i32 %0, i32* %3
store i8* %1, i8** %4
store i64 0, i64* %5
br label %7
7: ; preds = %30, %2
%8 = load i64, i64* %5
%9 = load i8*, i8** %4
%10 = call i64 @strlen(i8* %9)
%11 = icmp ne i64 %8, %10
br i1 %11, label %12, label %34
12: ; preds = %7
%13 = load i32, i32* %3
%14 = load i8*, i8** %4
%15 = load i64, i64* %5
%16 = getelementptr inbounds i8, i8* %14, i64 %15
%17 = load i8*, i8** %4
%18 = call i64 @strlen(i8* %17)
%19 = load i64, i64* %5
%20 = sub nsw i64 %18, %19
%21 = call i64 @write(i32 %13, i8* %16, i64 %20)
store i64 %21, i64* %6
%22 = load i64, i64* %6
%23 = icmp eq i64 %22, -1
br i1 %23, label %24, label %30
24: ; preds = %12
%25 = load i32, i32* @stderr
%26 = load i32, i32* @errno
%27 = call i8* @strerror(i32 %26)
%28 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %12
%31 = load i64, i64* %6
%32 = load i64, i64* %5
%33 = add nsw i64 %32, %31
store i64 %33, i64* %5
br label %7
34: ; preds = %7
%35 = load i64, i64* %5
%36 = trunc i64 %35 to i32
ret i32 %36
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"Write to nodogsplash failed: %s\0A\00"
@errno = global i32 0
define i32 @send_request(i32 %0, i8* nocapture %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %24, label %8
5: ; preds = %8
%6 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%7 = icmp eq i64 %6, %15
br i1 %7, label %22, label %8
8: ; preds = %2, %5
%9 = phi i64 [ %6, %5 ], [ %3, %2 ]
%10 = phi i64 [ %15, %5 ], [ 0, %2 ]
%11 = getelementptr inbounds i8, i8* %1, i64 %10
%12 = sub nsw i64 %9, %10
%13 = tail call i64 @write(i32 %0, i8* %11, i64 %12)
%14 = icmp eq i64 %13, -1
%15 = add nsw i64 %13, %10
br i1 %14, label %16, label %5
16: ; preds = %8
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = tail call i8* @strerror(i32 %18)
%20 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %5
%23 = trunc i64 %15 to i32
br label %24
24: ; preds = %22, %2
%25 = phi i32 [ 0, %2 ], [ %23, %22 ]
ret i32 %25
}