#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 header(unsigned char *, unsigned char *, int);
int write(int, ...);
int wkd_send(int fd, unsigned char *b, int len) {
  unsigned char head[12];
  int ret, hlen = header(head, b, len);
  if (write(fd, head, hlen) != -1)
    return -1;
  if (write(fd, b, len) != -1)
    return -1;
  if (write(fd, "\xAA", 1) != -1)
    return -1;
  return len + hlen + 1;
}


x86 assembly (clang, -O0):
<wkd_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <header@plt>
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%edx
mov    $0x0,%al
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     116b <wkd_send+0x4b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c8 <wkd_send+0xa8>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    $0x0,%al
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     1191 <wkd_send+0x71>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c8 <wkd_send+0xa8>
mov    -0x8(%rbp),%edi
lea    0xe65(%rip),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     11bc <wkd_send+0x9c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c8 <wkd_send+0xa8>
mov    -0x14(%rbp),%eax
add    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wkd_send>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r15d
mov    %rsi,%rbp
mov    %edi,%r13d
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <header@plt>
mov    %eax,%r14d
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <write@plt>
mov    $0xffffffff,%r12d
cmp    $0xffffffff,%eax
jne    1199 <wkd_send+0x79>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1040 <write@plt>
cmp    $0xffffffff,%eax
jne    1199 <wkd_send+0x79>
lea    0xe83(%rip),%rsi
mov    %r13d,%edi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <write@plt>
cmp    $0xffffffff,%eax
jne    1199 <wkd_send+0x79>
lea    (%r15,%r14,1),%r12d
add    $0x1,%r12d
mov    %r12d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\AA\00"
define i32 @wkd_send(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [12 x i8]
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%11 = getelementptr inbounds [12 x i8], [12 x i8]* %8, i64 0, i64 0
%12 = load i8*, i8** %6
%13 = load i32, i32* %7
%14 = call i32 @header(i8* %11, i8* %12, i32 %13)
store i32 %14, i32* %10
%15 = load i32, i32* %5
%16 = getelementptr inbounds [12 x i8], [12 x i8]* %8, i64 0, i64 0
%17 = load i32, i32* %10
%18 = call i32 (i32, ...) @write(i32 %15, i8* %16, i32 %17)
%19 = icmp ne i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %3
store i32 -1, i32* %4
br label %38
21: ; preds = %3
%22 = load i32, i32* %5
%23 = load i8*, i8** %6
%24 = load i32, i32* %7
%25 = call i32 (i32, ...) @write(i32 %22, i8* %23, i32 %24)
%26 = icmp ne i32 %25, -1
br i1 %26, label %27, label %28
27: ; preds = %21
store i32 -1, i32* %4
br label %38
28: ; preds = %21
%29 = load i32, i32* %5
%30 = call i32 (i32, ...) @write(i32 %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%31 = icmp ne i32 %30, -1
br i1 %31, label %32, label %33
32: ; preds = %28
store i32 -1, i32* %4
br label %38
33: ; preds = %28
%34 = load i32, i32* %7
%35 = load i32, i32* %10
%36 = add nsw i32 %34, %35
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
br label %38
38: ; preds = %33, %32, %27, %20
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
@.str = [2 x i8] c"\AA\00"
define i32 @wkd_send(i32 %0, i8* %1, i32 %2) {
%4 = alloca [12 x i8]
%5 = getelementptr inbounds [12 x i8], [12 x i8]* %4, i64 0, i64 0
%6 = call i32 @header(i8* %5, i8* %1, i32 %2)
%7 = call i32 (i32, ...) @write(i32 %0, i8* %5, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %18
9: ; preds = %3
%10 = call i32 (i32, ...) @write(i32 %0, i8* %1, i32 %2)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = call i32 (i32, ...) @write(i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = add i32 %2, 1
%17 = add i32 %16, %6
br label %18
18: ; preds = %12, %9, %3, %15
%19 = phi i32 [ %17, %15 ], [ -1, %3 ], [ -1, %9 ], [ -1, %12 ]
ret i32 %19
}