#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ exit_error(char *);
int /*<<< orphan*/ perror(char *);
int send_all(int, char *, size_t);
size_t strlen(char *);
void send_str_fail(int socket, char *s) {
  if (!s) {
    exit_error("attempted to send NULL string");
  }
  size_t len = strlen(s);
  switch (send_all(socket, s, len)) {
  case 1:
    return;
  case 0:
    exit_error("send_all: unexpected connection close while sending");
    break;
  default:
    perror("send_all");
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<send_str_fail>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1176 <send_str_fail+0x26>
lea    0xe8f(%rip),%rdi
call   1040 <exit_error@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1070 <send_all@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
test   %eax,%eax
je     11bb <send_str_fail+0x6b>
jmp    11a5 <send_str_fail+0x55>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
jne    11cc <send_str_fail+0x7c>
jmp    11b6 <send_str_fail+0x66>
jmp    11e6 <send_str_fail+0x96>
lea    0xe5c(%rip),%rdi
call   1040 <exit_error@plt>
jmp    11e6 <send_str_fail+0x96>
lea    0xe7f(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_str_fail>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
test   %rsi,%rsi
jne    1169 <send_str_fail+0x19>
lea    0xe9c(%rip),%rdi
call   1040 <exit_error@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1070 <send_all@plt>
cmp    $0x1,%eax
je     1199 <send_str_fail+0x49>
test   %eax,%eax
jne    11a0 <send_str_fail+0x50>
lea    0xe90(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <exit_error@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xeab(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"attempted to send NULL string\00"
@.str.1 = [52 x i8] c"send_all: unexpected connection close while sending\00"
@.str.2 = [9 x i8] c"send_all\00"
@EXIT_FAILURE = global i32 0
define void @send_str_fail(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = icmp ne i8* %6, null
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = call i32 @exit_error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %2
%11 = load i8*, i8** %4
%12 = call i64 @strlen(i8* %11)
store i64 %12, i64* %5
%13 = load i32, i32* %3
%14 = load i8*, i8** %4
%15 = load i64, i64* %5
%16 = call i32 @send_all(i32 %13, i8* %14, i64 %15)
switch i32 %16, label %20 [
i32 1, label %17
i32 0, label %18
]
17: ; preds = %10
br label %24
18: ; preds = %10
%19 = call i32 @exit_error(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
br label %24
20: ; preds = %10
%21 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %17, %18
ret void
}

LLVM IR (-O2):
@.str = [30 x i8] c"attempted to send NULL string\00"
@.str.1 = [52 x i8] c"send_all: unexpected connection close while sending\00"
@.str.2 = [9 x i8] c"send_all\00"
@EXIT_FAILURE = global i32 0
define void @send_str_fail(i32 %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @exit_error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %4, %2
%7 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%8 = tail call i32 @send_all(i32 %0, i8* %1, i64 %7)
switch i32 %8, label %11 [
i32 1, label %15
i32 0, label %9
]
9: ; preds = %6
%10 = tail call i32 @exit_error(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
br label %15
11: ; preds = %6
%12 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %6, %9
ret void
}