#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*/ perror(char *);
long write(int, ...);
int binary_dump_field(int fd, long code, long len, char *buf) {
  long hdrbuf[3];
  long i;
  hdrbuf[0] = ((long)(0xAB5C155A));
  hdrbuf[1] = code;
  hdrbuf[2] = len;
  i = write(fd, hdrbuf, 3 * sizeof(long));
  if (i != 3 * sizeof(long)) {
    perror("binary_dump_field");
    return 1;
  }
  if (len > 0) {
    i = write(fd, buf, len);
    if (i != len)
      return 2;
  }
  return 0;
}


x86 assembly (clang, -O0):
<binary_dump_field>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    $0xab5c155a,%eax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x18,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x18,-0x48(%rbp)
je     118a <binary_dump_field+0x6a>
lea    0xe87(%rip),%rdi
call   1040 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d1 <binary_dump_field+0xb1>
cmpq   $0x0,-0x18(%rbp)
jle    11ca <binary_dump_field+0xaa>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1030 <write@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     11c5 <binary_dump_field+0xa5>
movl   $0x2,-0x4(%rbp)
jmp    11d1 <binary_dump_field+0xb1>
jmp    11ca <binary_dump_field+0xaa>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binary_dump_field>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %edi,%ebp
mov    $0xab5c155a,%eax
mov    %rax,(%rsp)
mov    %rsi,0x8(%rsp)
mov    %rdx,0x10(%rsp)
mov    %rsp,%rsi
mov    $0x18,%edx
xor    %eax,%eax
call   1030 <write@plt>
cmp    $0x18,%rax
jne    1184 <binary_dump_field+0x64>
test   %rbx,%rbx
jle    1179 <binary_dump_field+0x59>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <write@plt>
mov    %rax,%rcx
mov    $0x2,%eax
cmp    %rbx,%rcx
jne    117b <binary_dump_field+0x5b>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe75(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%eax
jmp    117b <binary_dump_field+0x5b>

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

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