#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 */
struct client {
  int dummy;
};
typedef int /*<<< orphan*/ chunk;

/* Variables and functions */
int snprintf(char *, int, char *, int);
int strlen(char const *);
scalar_t__ uh_tcp_send(struct client *, char const *, int);
int uh_http_sendc(struct client *cl, const char *data, int len) {
  char chunk[8];
  int clen;
  if (len == -1)
    len = strlen(data);
  if (len > 0) {
    clen = snprintf(chunk, sizeof(chunk), "%X\r\n", len);
    do {
      if (uh_tcp_send(cl, chunk, clen) < 0)
        return -1;
    } while (0);
    do {
      if (uh_tcp_send(cl, data, len) < 0)
        return -1;
    } while (0);
    do {
      if (uh_tcp_send(cl, "\r\n", 2) < 0)
        return -1;
    } while (0);
  } else {
    do {
      if (uh_tcp_send(cl, "0\r\n\r\n", 5) < 0)
        return -1;
    } while (0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<uh_http_sendc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1159 <uh_http_sendc+0x29>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    1213 <uh_http_sendc+0xe3>
lea    -0x24(%rbp),%rdi
mov    -0x1c(%rbp),%ecx
mov    $0x8,%esi
lea    0xe8a(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x24(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1050 <uh_tcp_send@plt>
cmp    $0x0,%rax
jge    11a4 <uh_http_sendc+0x74>
movl   $0xffffffff,-0x4(%rbp)
jmp    1254 <uh_http_sendc+0x124>
jmp    11a9 <uh_http_sendc+0x79>
jmp    11ae <uh_http_sendc+0x7e>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <uh_tcp_send@plt>
cmp    $0x0,%rax
jge    11d4 <uh_http_sendc+0xa4>
movl   $0xffffffff,-0x4(%rbp)
jmp    1254 <uh_http_sendc+0x124>
jmp    11d9 <uh_http_sendc+0xa9>
jmp    11de <uh_http_sendc+0xae>
mov    -0x10(%rbp),%rdi
lea    0xe1f(%rip),%rsi
mov    $0x2,%edx
call   1050 <uh_tcp_send@plt>
cmp    $0x0,%rax
jge    1209 <uh_http_sendc+0xd9>
movl   $0xffffffff,-0x4(%rbp)
jmp    1254 <uh_http_sendc+0x124>
jmp    120e <uh_http_sendc+0xde>
jmp    124d <uh_http_sendc+0x11d>
jmp    1218 <uh_http_sendc+0xe8>
mov    -0x10(%rbp),%rdi
lea    0xde2(%rip),%rsi
mov    $0x5,%edx
call   1050 <uh_tcp_send@plt>
cmp    $0x0,%rax
jge    1243 <uh_http_sendc+0x113>
movl   $0xffffffff,-0x4(%rbp)
jmp    1254 <uh_http_sendc+0x124>
jmp    1248 <uh_http_sendc+0x118>
jmp    124d <uh_http_sendc+0x11d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uh_http_sendc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
cmp    $0xffffffff,%edx
je     11a5 <uh_http_sendc+0x75>
test   %ebp,%ebp
jle    11b3 <uh_http_sendc+0x83>
lea    0xeb1(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x8,%esi
mov    %ebp,%ecx
call   1040 <snprintf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <uh_tcp_send@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
js     11d5 <uh_http_sendc+0xa5>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1050 <uh_tcp_send@plt>
test   %rax,%rax
js     11d5 <uh_http_sendc+0xa5>
lea    0xe77(%rip),%rsi
mov    %r15,%rdi
mov    $0x2,%edx
call   1050 <uh_tcp_send@plt>
test   %rax,%rax
jns    11cc <uh_http_sendc+0x9c>
jmp    11d5 <uh_http_sendc+0xa5>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
test   %ebp,%ebp
jg     1148 <uh_http_sendc+0x18>
lea    0xe4b(%rip),%rsi
mov    %r15,%rdi
mov    $0x5,%edx
call   1050 <uh_tcp_send@plt>
test   %rax,%rax
js     11d0 <uh_http_sendc+0xa0>
xor    %ebx,%ebx
jmp    11d5 <uh_http_sendc+0xa5>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.client = type { i32 }
@.str = [5 x i8] c"%X\0D\0A\00"
@.str.1 = [3 x i8] c"\0D\0A\00"
@.str.2 = [6 x i8] c"0\0D\0A\0D\0A\00"
define i32 @uh_http_sendc(%struct.client* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.client*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [8 x i8]
%9 = alloca i32
store %struct.client* %0, %struct.client** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i32, i32* %7
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %3
%13 = load i8*, i8** %6
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %7
br label %15
15: ; preds = %12, %3
%16 = load i32, i32* %7
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %47
18: ; preds = %15
%19 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%20 = load i32, i32* %7
%21 = call i32 @snprintf(i8* %19, i32 8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %20)
store i32 %21, i32* %9
br label %22
22: ; preds = %18
%23 = load %struct.client*, %struct.client** %5
%24 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%25 = load i32, i32* %9
%26 = call i64 @uh_tcp_send(%struct.client* %23, i8* %24, i32 %25)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %22
store i32 -1, i32* %4
br label %56
29: ; preds = %22
br label %30
30: ; preds = %29
br label %31
31: ; preds = %30
%32 = load %struct.client*, %struct.client** %5
%33 = load i8*, i8** %6
%34 = load i32, i32* %7
%35 = call i64 @uh_tcp_send(%struct.client* %32, i8* %33, i32 %34)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %31
store i32 -1, i32* %4
br label %56
38: ; preds = %31
br label %39
39: ; preds = %38
br label %40
40: ; preds = %39
%41 = load %struct.client*, %struct.client** %5
%42 = call i64 @uh_tcp_send(%struct.client* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %40
store i32 -1, i32* %4
br label %56
45: ; preds = %40
br label %46
46: ; preds = %45
br label %55
47: ; preds = %15
br label %48
48: ; preds = %47
%49 = load %struct.client*, %struct.client** %5
%50 = call i64 @uh_tcp_send(%struct.client* %49, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %48
store i32 -1, i32* %4
br label %56
53: ; preds = %48
br label %54
54: ; preds = %53
br label %55
55: ; preds = %54, %46
store i32 0, i32* %4
br label %56
56: ; preds = %55, %52, %44, %37, %28
%57 = load i32, i32* %4
ret i32 %57
}

LLVM IR (-O2):
%struct.client = type { i32 }
@.str = [5 x i8] c"%X\0D\0A\00"
@.str.1 = [3 x i8] c"\0D\0A\00"
@.str.2 = [6 x i8] c"0\0D\0A\0D\0A\00"
define i32 @uh_http_sendc(%struct.client* %0, i8* %1, i32 %2) {
%4 = alloca [8 x i8]
%5 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%6 = icmp eq i32 %2, -1
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @strlen(i8* %1)
br label %9
9: ; preds = %7, %3
%10 = phi i32 [ %8, %7 ], [ %2, %3 ]
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %22
12: ; preds = %9
%13 = call i32 @snprintf(i8* %5, i32 8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %10)
%14 = call i64 @uh_tcp_send(%struct.client* %0, i8* %5, i32 %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %26, label %16
16: ; preds = %12
%17 = call i64 @uh_tcp_send(%struct.client* %0, i8* %1, i32 %10)
%18 = icmp slt i64 %17, 0
br i1 %18, label %26, label %19
19: ; preds = %16
%20 = call i64 @uh_tcp_send(%struct.client* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%21 = icmp slt i64 %20, 0
br i1 %21, label %26, label %25
22: ; preds = %9
%23 = tail call i64 @uh_tcp_send(%struct.client* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%24 = icmp slt i64 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %22, %19
br label %26
26: ; preds = %22, %19, %16, %12, %25
%27 = phi i32 [ 0, %25 ], [ -1, %12 ], [ -1, %16 ], [ -1, %19 ], [ -1, %22 ]
ret i32 %27
}