#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*/ errAbort(char *, int);
int strlen(char *);
int /*<<< orphan*/ warn(char *);
scalar_t__ write(int, ...);
int netSendString(int sd, char *s) {
  int length = strlen(s);
  unsigned char len;
  if (length > 255)
    errAbort("Trying to send a string longer than 255 bytes (%d bytes)",
             length);
  len = length;
  if (write(sd, &len, 1) < 0) {
    warn("Couldn't send string to socket");
    return 0;
  }
  if (write(sd, s, length) < 0) {
    warn("Couldn't send string to socket");
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<netSendString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xff,-0x14(%rbp)
jle    1177 <netSendString+0x37>
mov    -0x14(%rbp),%esi
lea    0xe8e(%rip),%rdi
call   1060 <errAbort@plt>
mov    -0x14(%rbp),%eax
mov    %al,-0x15(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x15(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1040 <write@plt>
cmp    $0x0,%rax
jge    11b2 <netSendString+0x72>
lea    0xe98(%rip),%rdi
call   1030 <warn@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ec <netSendString+0xac>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    $0x0,%al
call   1040 <write@plt>
cmp    $0x0,%rax
jge    11e5 <netSendString+0xa5>
lea    0xe65(%rip),%rdi
call   1030 <warn@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ec <netSendString+0xac>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<netSendString>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
cmp    $0x100,%eax
jl     116c <netSendString+0x2c>
lea    0xe9b(%rip),%rdi
mov    %ebx,%esi
call   1060 <errAbort@plt>
mov    %bl,0x7(%rsp)
lea    0x7(%rsp),%rsi
mov    $0x1,%ebp
mov    %r15d,%edi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <write@plt>
test   %rax,%rax
js     11a2 <netSendString+0x62>
mov    %r15d,%edi
mov    %r14,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <write@plt>
test   %rax,%rax
jns    11b0 <netSendString+0x70>
lea    0xe90(%rip),%rdi
call   1030 <warn@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [57 x i8] c"Trying to send a string longer than 255 bytes (%d bytes)\00"
@.str.1 = [31 x i8] c"Couldn't send string to socket\00"
define i32 @netSendString(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8
store i32 %0, i32* %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp sgt i32 %10, 255
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* %6
%14 = call i32 @errAbort(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %12, %2
%16 = load i32, i32* %6
%17 = trunc i32 %16 to i8
store i8 %17, i8* %7
%18 = load i32, i32* %4
%19 = call i64 (i32, ...) @write(i32 %18, i8* %7, i32 1)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = call i32 @warn(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %32
23: ; preds = %15
%24 = load i32, i32* %4
%25 = load i8*, i8** %5
%26 = load i32, i32* %6
%27 = call i64 (i32, ...) @write(i32 %24, i8* %25, i32 %26)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %23
%30 = call i32 @warn(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %32
31: ; preds = %23
store i32 1, i32* %3
br label %32
32: ; preds = %31, %29, %21
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@.str = [57 x i8] c"Trying to send a string longer than 255 bytes (%d bytes)\00"
@.str.1 = [31 x i8] c"Couldn't send string to socket\00"
define i32 @netSendString(i32 %0, i8* %1) {
%3 = alloca i8
%4 = tail call i32 @strlen(i8* %1)
%5 = icmp sgt i32 %4, 255
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @errAbort(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %4)
br label %8
8: ; preds = %6, %2
%9 = trunc i32 %4 to i8
store i8 %9, i8* %3
%10 = call i64 (i32, ...) @write(i32 %0, i8* %3, i32 1)
%11 = icmp slt i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %8
%13 = call i64 (i32, ...) @write(i32 %0, i8* %1, i32 %4)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12, %8
%16 = call i32 @warn(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
%18 = phi i32 [ 1, %12 ], [ 0, %15 ]
ret i32 %18
}