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

/* Variables and functions */
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
void fwrite_be_offt(off_t off, FILE *f) {
  int i;
  unsigned char c[8];
  for (i = 7; i >= 0; i--) {
    c[i] = off & 0xff;
    off >>= 8;
  }
  fwrite(c, sizeof(c), 1, f);
}


x86 assembly (clang, -O0):
<fwrite_be_offt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x7,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     1159 <fwrite_be_offt+0x49>
mov    -0x4(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
movslq -0x14(%rbp),%rax
mov    %cl,-0x1c(%rbp,%rax,1)
mov    -0x4(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0x4(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1126 <fwrite_be_offt+0x16>
lea    -0x1c(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x8,%esi
mov    $0x1,%edx
call   1030 <fwrite@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fwrite_be_offt>:
push   %rax
mov    %rsi,%rcx
mov    %edi,%eax
bswap  %eax
mov    %eax,0x4(%rsp)
sar    $0x1f,%edi
movzbl %dil,%eax
imul   $0x1010101,%eax,%eax
mov    %eax,(%rsp)
mov    %rsp,%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1030 <fwrite@plt>
pop    %rax
ret

LLVM IR (-O0):
define void @fwrite_be_offt(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca [8 x i8]
store i32 %0, i32* %3
store i32* %1, i32** %4
store i32 7, i32* %5
br label %7
7: ; preds = %19, %2
%8 = load i32, i32* %5
%9 = icmp sge i32 %8, 0
br i1 %9, label %10, label %22
10: ; preds = %7
%11 = load i32, i32* %3
%12 = and i32 %11, 255
%13 = trunc i32 %12 to i8
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 %15
store i8 %13, i8* %16
%17 = load i32, i32* %3
%18 = ashr i32 %17, 8
store i32 %18, i32* %3
br label %19
19: ; preds = %10
%20 = load i32, i32* %5
%21 = add nsw i32 %20, -1
store i32 %21, i32* %5
br label %7
22: ; preds = %7
%23 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%24 = load i32*, i32** %4
%25 = call i32 @fwrite(i8* %23, i32 8, i32 1, i32* %24)
ret void
}

LLVM IR (-O2):
define void @fwrite_be_offt(i32 %0, i32* nocapture %1) {
%3 = alloca [8 x i8]
%4 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%5 = trunc i32 %0 to i8
%6 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 7
store i8 %5, i8* %6
%7 = lshr i32 %0, 8
%8 = trunc i32 %7 to i8
%9 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 6
store i8 %8, i8* %9
%10 = lshr i32 %0, 16
%11 = trunc i32 %10 to i8
%12 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 5
store i8 %11, i8* %12
%13 = lshr i32 %0, 24
%14 = trunc i32 %13 to i8
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 4
store i8 %14, i8* %15
%16 = ashr i32 %0, 31
%17 = trunc i32 %16 to i8
%18 = call i32 @fwrite(i8* %4, i32 8, i32 1, i32* %1)
ret void
}