#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 */
unsigned long strlen(char *);
int /*<<< orphan*/ warn(char *);
scalar_t__ write(int, ...);
int netSendHugeString(int sd, char *s) {
  unsigned long length = strlen(s);
  unsigned long l = length;
  unsigned char b[4];
  int i;
  for (i = 3; i >= 0; --i) {
    b[i] = l & 0xff;
    l >>= 8;
  }
  if (write(sd, b, 4) < 0) {
    warn("Couldn't send huge string to socket");
    return 0;
  }
  if (write(sd, s, length) < 0) {
    warn("Couldn't send huge string to socket");
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<netSendHugeString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x3,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jl     1193 <netSendHugeString+0x63>
mov    -0x20(%rbp),%rax
and    $0xff,%rax
mov    %al,%cl
movslq -0x28(%rbp),%rax
mov    %cl,-0x24(%rbp,%rax,1)
mov    -0x20(%rbp),%rax
shr    $0x8,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
jmp    115b <netSendHugeString+0x2b>
mov    -0x8(%rbp),%edi
lea    -0x24(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1040 <write@plt>
cmp    $0x0,%rax
jge    11c8 <netSendHugeString+0x98>
lea    0xe49(%rip),%rdi
call   1030 <warn@plt>
movl   $0x0,-0x4(%rbp)
jmp    1203 <netSendHugeString+0xd3>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1040 <write@plt>
cmp    $0x0,%rax
jge    11fc <netSendHugeString+0xcc>
lea    0xe15(%rip),%rdi
call   1030 <warn@plt>
movl   $0x0,-0x4(%rbp)
jmp    1203 <netSendHugeString+0xd3>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<netSendHugeString>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
bswap  %eax
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
xor    %eax,%eax
call   1040 <write@plt>
test   %rax,%rax
js     1182 <netSendHugeString+0x52>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <write@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jns    1190 <netSendHugeString+0x60>
lea    0xe77(%rip),%rdi
call   1030 <warn@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Couldn't send huge string to socket\00"
define i32 @netSendHugeString(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca [4 x i8]
%9 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%10 = load i8*, i8** %5
%11 = call i64 @strlen(i8* %10)
store i64 %11, i64* %6
%12 = load i64, i64* %6
store i64 %12, i64* %7
store i32 3, i32* %9
br label %13
13: ; preds = %25, %2
%14 = load i32, i32* %9
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %28
16: ; preds = %13
%17 = load i64, i64* %7
%18 = and i64 %17, 255
%19 = trunc i64 %18 to i8
%20 = load i32, i32* %9
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 %21
store i8 %19, i8* %22
%23 = load i64, i64* %7
%24 = lshr i64 %23, 8
store i64 %24, i64* %7
br label %25
25: ; preds = %16
%26 = load i32, i32* %9
%27 = add nsw i32 %26, -1
store i32 %27, i32* %9
br label %13
28: ; preds = %13
%29 = load i32, i32* %4
%30 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%31 = call i64 (i32, ...) @write(i32 %29, i8* %30, i32 4)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = call i32 @warn(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %44
35: ; preds = %28
%36 = load i32, i32* %4
%37 = load i8*, i8** %5
%38 = load i64, i64* %6
%39 = call i64 (i32, ...) @write(i32 %36, i8* %37, i64 %38)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %35
%42 = call i32 @warn(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %44
43: ; preds = %35
store i32 1, i32* %3
br label %44
44: ; preds = %43, %41, %33
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@.str = [36 x i8] c"Couldn't send huge string to socket\00"
define i32 @netSendHugeString(i32 %0, i8* %1) {
%3 = alloca [4 x i8]
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%6 = trunc i64 %4 to i8
%7 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
store i8 %6, i8* %7
%8 = lshr i64 %4, 8
%9 = trunc i64 %8 to i8
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
store i8 %9, i8* %10
%11 = lshr i64 %4, 16
%12 = trunc i64 %11 to i8
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
store i8 %12, i8* %13
%14 = lshr i64 %4, 24
%15 = trunc i64 %14 to i8
store i8 %15, i8* %5
%16 = call i64 (i32, ...) @write(i32 %0, i8* %5, i32 4)
%17 = icmp slt i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %2
%19 = call i64 (i32, ...) @write(i32 %0, i8* %1, i64 %4)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18, %2
%22 = call i32 @warn(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
%24 = phi i32 [ 1, %18 ], [ 0, %21 ]
ret i32 %24
}