#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*/ fputc(int /*<<< orphan*/, int /*<<< orphan*/ *);
unsigned long push_hdr(char *, unsigned long, int /*<<< orphan*/ *);
unsigned long push_rest(char const *, unsigned long, int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int /*<<< orphan*/,
                           int /*<<< orphan*/, long, long, int, long,
                           int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/, unsigned int,
                           int /*<<< orphan*/);
scalar_t__ strlen(char const *);
void write_trailer(unsigned long offset, FILE *output) {
  char s[256];
  const char name[] = "TRAILER!!!";
  sprintf(s,
          "%s%08X%08X%08lX%08lX%08X%08lX"
          "%08X%08X%08X%08X%08X%08X%08X",
          "070701", 0, 0, (long)0, (long)0, 1, (long)0, 0, 0, 0, 0, 0,
          (unsigned)strlen(name) + 1, 0);
  offset = push_hdr(s, offset, output);
  offset = push_rest(name, offset, output);
  while (offset % 512) {
    fputc(0, output);
    offset++;
  }
}


x86 assembly (clang, -O0):
<write_trailer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe96(%rip),%rax
mov    %rax,-0x11b(%rbp)
mov    0xe90(%rip),%ax
mov    %ax,-0x113(%rbp)
mov    0xe85(%rip),%al
mov    %al,-0x111(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x128(%rbp)
lea    -0x11b(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x128(%rbp),%rdi
add    $0x1,%eax
lea    0xe55(%rip),%rsi
lea    0xe88(%rip),%rdx
xor    %r8d,%r8d
xor    %ecx,%ecx
mov    %ecx,%r9d
mov    %r8d,%ecx
movq   $0x0,(%rsp)
movl   $0x1,0x8(%rsp)
movq   $0x0,0x10(%rsp)
movl   $0x0,0x18(%rsp)
movl   $0x0,0x20(%rsp)
movl   $0x0,0x28(%rsp)
movl   $0x0,0x30(%rsp)
movl   $0x0,0x38(%rsp)
mov    %eax,0x40(%rsp)
movl   $0x0,0x48(%rsp)
call   1060 <sprintf@plt>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1050 <push_hdr@plt>
mov    %rax,-0x8(%rbp)
lea    -0x11b(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1070 <push_rest@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
and    $0x1ff,%rax
cmp    $0x0,%rax
je     127a <write_trailer+0x12a>
mov    -0x10(%rbp),%rsi
xor    %edi,%edi
call   1040 <fputc@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    124a <write_trailer+0xfa>
add    $0x180,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_trailer>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x110,%rsp
mov    %rsi,%r13
mov    %rdi,%r15
movabs $0x2152454c49415254,%rax
45 52 21
mov    %rax,(%rsp)
movl   $0x212121,0x7(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
lea    0xe7a(%rip),%rsi
lea    0xead(%rip),%rdx
lea    0x10(%rsp),%r12
mov    %r12,%rdi
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   $0x0
push   %rax
push   $0x0
push   $0x0
push   $0x0
push   $0x0
push   $0x0
push   $0x0
push   $0x1
push   $0x0
call   1060 <sprintf@plt>
add    $0x50,%rsp
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1050 <push_hdr@plt>
mov    %r14,%rdi
mov    %rax,%rsi
mov    %r13,%rdx
call   1070 <push_rest@plt>
mov    %rax,%r14
test   $0x1ff,%r14d
je     121a <write_trailer+0xca>
add    $0x1,%r14
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %edi,%edi
mov    %r13,%rsi
call   1040 <fputc@plt>
add    $0x1,%rbx
test   $0x1ff,%r14d
mov    %rbx,%r14
jne    1200 <write_trailer+0xb0>
add    $0x110,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.write_trailer.name = [11 x i8] c"TRAILER!!!\00"
@.str = [58 x i8] c"%s%08X%08X%08lX%08lX%08X%08lX%08X%08X%08X%08X%08X%08X%08X\00"
@.str.1 = [7 x i8] c"070701\00"
define void @write_trailer(i64 %0, i32* %1) {
%3 = alloca i64
%4 = alloca i32*
%5 = alloca [256 x i8]
%6 = alloca [11 x i8]
store i64 %0, i64* %3
store i32* %1, i32** %4
%7 = bitcast [11 x i8]* %6 to i8*
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [11 x i8], [11 x i8]* %6, i64 0, i64 0
%10 = call i64 @strlen(i8* %9)
%11 = trunc i64 %10 to i32
%12 = add i32 %11, 1
%13 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 0, i64 0, i64 0, i32 1, i64 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 %12, i32 0)
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%15 = load i64, i64* %3
%16 = load i32*, i32** %4
%17 = call i64 @push_hdr(i8* %14, i64 %15, i32* %16)
store i64 %17, i64* %3
%18 = getelementptr inbounds [11 x i8], [11 x i8]* %6, i64 0, i64 0
%19 = load i64, i64* %3
%20 = load i32*, i32** %4
%21 = call i64 @push_rest(i8* %18, i64 %19, i32* %20)
store i64 %21, i64* %3
br label %22
22: ; preds = %26, %2
%23 = load i64, i64* %3
%24 = urem i64 %23, 512
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %22
%27 = load i32*, i32** %4
%28 = call i32 @fputc(i32 0, i32* %27)
%29 = load i64, i64* %3
%30 = add i64 %29, 1
store i64 %30, i64* %3
br label %22
31: ; preds = %22
ret void
}

LLVM IR (-O2):
@__const.write_trailer.name = [11 x i8] c"TRAILER!!!\00"
@.str = [58 x i8] c"%s%08X%08X%08lX%08lX%08X%08lX%08X%08X%08X%08X%08X%08X%08X\00"
@.str.1 = [7 x i8] c"070701\00"
define void @write_trailer(i64 %0, i32* %1) {
%3 = alloca [256 x i8]
%4 = alloca [11 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 0
%7 = call i64 @strlen(i8* %6)
%8 = trunc i64 %7 to i32
%9 = add i32 %8, 1
%10 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 0, i64 0, i64 0, i32 1, i64 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 %9, i32 0)
%11 = call i64 @push_hdr(i8* %5, i64 %0, i32* %1)
%12 = call i64 @push_rest(i8* %6, i64 %11, i32* %1)
%13 = and i64 %12, 511
%14 = icmp eq i64 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %2, %15
%16 = phi i64 [ %18, %15 ], [ %12, %2 ]
%17 = call i32 @fputc(i32 0, i32* %1)
%18 = add i64 %16, 1
%19 = and i64 %18, 511
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %15
21: ; preds = %15, %2
ret void
}