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

/* Variables and functions */
int fwrite(int *, int, int, int /*<<< orphan*/ *);
int write_64bit_word(FILE *dest, uint64_t value) {
  uint8_t buffer[8];
  buffer[0] = value & 0xff;
  buffer[1] = (value >> 8) & 0xff;
  buffer[2] = (value >> 16) & 0xff;
  buffer[3] = (value >> 24) & 0xff;
  buffer[4] = (value >> 32) & 0xff;
  buffer[5] = (value >> 40) & 0xff;
  buffer[6] = (value >> 48) & 0xff;
  buffer[7] = (value >> 56) & 0xff;
  if (fwrite(buffer, 8, 1, dest) != 1)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<write_64bit_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x40(%rbp)
mov    -0x14(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x14(%rbp),%eax
sar    $0x10,%eax
and    $0xff,%eax
mov    %eax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
sar    $0x18,%eax
and    $0xff,%eax
mov    %eax,-0x34(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x20,%ecx
sar    %cl,%eax
and    $0xff,%eax
mov    %eax,-0x30(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x28,%ecx
sar    %cl,%eax
and    $0xff,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x30,%ecx
sar    %cl,%eax
and    $0xff,%eax
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x38,%ecx
sar    %cl,%eax
and    $0xff,%eax
mov    %eax,-0x24(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x8,%esi
mov    $0x1,%edx
call   1030 <fwrite@plt>
cmp    $0x1,%eax
je     11c8 <write_64bit_word+0xb8>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cf <write_64bit_word+0xbf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_64bit_word>:
sub    $0x28,%rsp
mov    %esi,%eax
mov    %rdi,%rcx
movzbl %al,%edx
mov    %edx,(%rsp)
movzbl %ah,%edx
mov    %edx,0x4(%rsp)
mov    %esi,%edx
shr    $0x10,%edx
movzbl %dl,%edx
mov    %edx,0x8(%rsp)
shr    $0x18,%eax
mov    %eax,0xc(%rsp)
mov    %rsp,%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1030 <fwrite@plt>
xor    %ecx,%ecx
cmp    $0x1,%eax
setne  %cl
neg    %ecx
mov    %ecx,%eax
add    $0x28,%rsp
ret

LLVM IR (-O0):
define i32 @write_64bit_word(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca [8 x i32]
store i32* %0, i32** %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = and i32 %7, 255
%9 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 0
store i32 %8, i32* %9
%10 = load i32, i32* %5
%11 = ashr i32 %10, 8
%12 = and i32 %11, 255
%13 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 1
store i32 %12, i32* %13
%14 = load i32, i32* %5
%15 = ashr i32 %14, 16
%16 = and i32 %15, 255
%17 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 2
store i32 %16, i32* %17
%18 = load i32, i32* %5
%19 = ashr i32 %18, 24
%20 = and i32 %19, 255
%21 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 3
store i32 %20, i32* %21
%22 = load i32, i32* %5
%23 = ashr i32 %22, 32
%24 = and i32 %23, 255
%25 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 4
store i32 %24, i32* %25
%26 = load i32, i32* %5
%27 = ashr i32 %26, 40
%28 = and i32 %27, 255
%29 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 5
store i32 %28, i32* %29
%30 = load i32, i32* %5
%31 = ashr i32 %30, 48
%32 = and i32 %31, 255
%33 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 6
store i32 %32, i32* %33
%34 = load i32, i32* %5
%35 = ashr i32 %34, 56
%36 = and i32 %35, 255
%37 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 7
store i32 %36, i32* %37
%38 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 0
%39 = load i32*, i32** %4
%40 = call i32 @fwrite(i32* %38, i32 8, i32 1, i32* %39)
%41 = icmp ne i32 %40, 1
br i1 %41, label %42, label %43
42: ; preds = %2
store i32 -1, i32* %3
br label %44
43: ; preds = %2
store i32 0, i32* %3
br label %44
44: ; preds = %43, %42
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
define i32 @write_64bit_word(i32* nocapture %0, i32 %1) {
%3 = alloca [8 x i32]
%4 = bitcast [8 x i32]* %3 to i8*
%5 = and i32 %1, 255
%6 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
store i32 %5, i32* %6
%7 = lshr i32 %1, 8
%8 = and i32 %7, 255
%9 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 1
store i32 %8, i32* %9
%10 = lshr i32 %1, 16
%11 = and i32 %10, 255
%12 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 2
store i32 %11, i32* %12
%13 = lshr i32 %1, 24
%14 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 3
store i32 %13, i32* %14
%15 = call i32 @fwrite(i32* %6, i32 8, i32 1, i32* %0)
%16 = icmp ne i32 %15, 1
%17 = sext i1 %16 to i32
ret i32 %17
}