#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int append_24section(unsigned char *section, FILE *output) {
  int i;
  i = ((section) == NULL
           ? 0
           : (int)((section[0] << 16) + (section[1] << 8) + section[2]));
  if (fwrite(section, sizeof(unsigned char), i, output) != i) {
    fprintf(stderr, "error writing output\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<append_24section>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1145 <append_24section+0x25>
xor    %eax,%eax
mov    %eax,-0x20(%rbp)
jmp    1169 <append_24section+0x49>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
shl    $0x10,%eax
mov    -0x10(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
mov    -0x10(%rbp),%rcx
movzbl 0x2(%rcx),%ecx
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fwrite@plt>
cmp    -0x1c(%rbp),%eax
je     11ae <append_24section+0x8e>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
lea    0xe63(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b5 <append_24section+0x95>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_24section>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rcx
xor    %ebx,%ebx
mov    $0x0,%ebp
test   %rdi,%rdi
je     1147 <append_24section+0x27>
movzbl (%rdi),%eax
shl    $0x10,%eax
movzbl 0x1(%rdi),%edx
shl    $0x8,%edx
or     %eax,%edx
movzbl 0x2(%rdi),%ebp
or     %edx,%ebp
mov    $0x1,%esi
mov    %ebp,%edx
call   1040 <fwrite@plt>
cmp    %ebp,%eax
je     1171 <append_24section+0x51>
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
lea    0xe99(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"error writing output\0A\00"
define i32 @append_24section(i8* %0, i32* nocapture %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %17, label %4
4: ; preds = %2
%5 = load i8, i8* %0
%6 = zext i8 %5 to i32
%7 = shl nuw nsw i32 %6, 16
%8 = getelementptr inbounds i8, i8* %0, i64 1
%9 = load i8, i8* %8
%10 = zext i8 %9 to i32
%11 = shl nuw nsw i32 %10, 8
%12 = or i32 %11, %7
%13 = getelementptr inbounds i8, i8* %0, i64 2
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = or i32 %12, %15
br label %17
17: ; preds = %2, %4
%18 = phi i32 [ %16, %4 ], [ 0, %2 ]
%19 = tail call i32 @fwrite(i8* %0, i32 1, i32 %18, i32* %1)
%20 = icmp eq i32 %19, %18
br i1 %20, label %24, label %21
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %17, %21
%25 = phi i32 [ -1, %21 ], [ 0, %17 ]
ret i32 %25
}