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

/* Variables and functions */
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int, int, int);
void write_record(uint32_t load_addr, uint32_t length, uint32_t start_addr,
                  FILE *fp, uint8_t *buffer) {
  printf("** %08x %08x %08x **\n", load_addr, length, start_addr);
  fwrite(&load_addr, 1, 4, fp);
  fwrite(&length, 1, 4, fp);
  fwrite(&start_addr, 1, 4, fp);
  length = (length + 3) & ~3;
  fwrite(buffer, 1, length, fp);
}


x86 assembly (clang, -O0):
<write_record>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xeb7(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rcx
lea    -0x4(%rbp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1040 <fwrite@plt>
mov    -0x18(%rbp),%rcx
lea    -0x8(%rbp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1040 <fwrite@plt>
mov    -0x18(%rbp),%rcx
lea    -0xc(%rbp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1040 <fwrite@plt>
mov    -0x8(%rbp),%eax
add    $0x3,%eax
and    $0xfffffffc,%eax
mov    %eax,-0x8(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fwrite@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_record>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r14
mov    %rcx,%rbx
mov    %edx,%ecx
mov    %esi,%edx
mov    %edi,%esi
mov    %edi,0x14(%rsp)
mov    %edx,0xc(%rsp)
mov    %ecx,0x10(%rsp)
lea    0xeba(%rip),%rdi
call   1030 <printf@plt>
lea    0x14(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rbx,%rcx
call   1040 <fwrite@plt>
lea    0xc(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rbx,%rcx
call   1040 <fwrite@plt>
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rbx,%rcx
call   1040 <fwrite@plt>
mov    0xc(%rsp),%edx
add    $0x3,%edx
and    $0xfffffffc,%edx
mov    %r14,%rdi
mov    $0x1,%esi
mov    %rbx,%rcx
add    $0x18,%rsp
pop    %rbx
pop    %r14
jmp    1040 <fwrite@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"** %08x %08x %08x **\0A\00"
define void @write_record(i32 %0, i32 %1, i32 %2, i32* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32* %3, i32** %9
store i32* %4, i32** %10
%11 = load i32, i32* %6
%12 = load i32, i32* %7
%13 = load i32, i32* %8
%14 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %12, i32 %13)
%15 = load i32*, i32** %9
%16 = call i32 @fwrite(i32* %6, i32 1, i32 4, i32* %15)
%17 = load i32*, i32** %9
%18 = call i32 @fwrite(i32* %7, i32 1, i32 4, i32* %17)
%19 = load i32*, i32** %9
%20 = call i32 @fwrite(i32* %8, i32 1, i32 4, i32* %19)
%21 = load i32, i32* %7
%22 = add nsw i32 %21, 3
%23 = and i32 %22, -4
store i32 %23, i32* %7
%24 = load i32*, i32** %10
%25 = load i32, i32* %7
%26 = load i32*, i32** %9
%27 = call i32 @fwrite(i32* %24, i32 1, i32 %25, i32* %26)
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"** %08x %08x %08x **\0A\00"
define void @write_record(i32 %0, i32 %1, i32 %2, i32* nocapture %3, i32* nocapture %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
%9 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1, i32 %2)
%10 = call i32 @fwrite(i32* %6, i32 1, i32 4, i32* %3)
%11 = call i32 @fwrite(i32* %7, i32 1, i32 4, i32* %3)
%12 = call i32 @fwrite(i32* %8, i32 1, i32 4, i32* %3)
%13 = load i32, i32* %7
%14 = add nsw i32 %13, 3
%15 = and i32 %14, -4
%16 = tail call i32 @fwrite(i32* %4, i32 1, i32 %15, i32* %3)
ret void
}