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

/* Variables and functions */
int fwrite(unsigned int *, int, int, int /*<<< orphan*/ *);
int fwrite_le32(uint32_t buf, FILE *fd) {
  size_t count;
  uint8_t tmp[4];
  unsigned int i;
  for (i = 0; i < (sizeof(tmp) / sizeof((tmp)[0])); i++)
    tmp[i] = buf >> (i * 8);
  if (fwrite(tmp, sizeof(tmp), 1, fd) != 1)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<fwrite_le32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    $0x4,%rax
jae    1155 <fwrite_le32+0x45>
mov    -0x8(%rbp),%eax
mov    -0x34(%rbp),%ecx
shl    $0x3,%ecx
shr    %cl,%eax
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
mov    %ecx,-0x30(%rbp,%rax,4)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1126 <fwrite_le32+0x16>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x10,%esi
mov    $0x1,%edx
call   1030 <fwrite@plt>
cmp    $0x1,%eax
je     1181 <fwrite_le32+0x71>
movl   $0xffffffff,-0x4(%rbp)
jmp    1188 <fwrite_le32+0x78>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
define i32 @fwrite_le32(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i64
%7 = alloca [4 x i32]
%8 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32 0, i32* %8
br label %9
9: ; preds = %21, %2
%10 = load i32, i32* %8
%11 = zext i32 %10 to i64
%12 = icmp ult i64 %11, 4
br i1 %12, label %13, label %24
13: ; preds = %9
%14 = load i32, i32* %4
%15 = load i32, i32* %8
%16 = mul i32 %15, 8
%17 = lshr i32 %14, %16
%18 = load i32, i32* %8
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds [4 x i32], [4 x i32]* %7, i64 0, i64 %19
store i32 %17, i32* %20
br label %21
21: ; preds = %13
%22 = load i32, i32* %8
%23 = add i32 %22, 1
store i32 %23, i32* %8
br label %9
24: ; preds = %9
%25 = getelementptr inbounds [4 x i32], [4 x i32]* %7, i64 0, i64 0
%26 = load i32*, i32** %5
%27 = call i32 @fwrite(i32* %25, i32 16, i32 1, i32* %26)
%28 = icmp ne i32 %27, 1
br i1 %28, label %29, label %30
29: ; preds = %24
store i32 -1, i32* %3
br label %31
30: ; preds = %24
store i32 0, i32* %3
br label %31
31: ; preds = %30, %29
%32 = load i32, i32* %3
ret i32 %32
}

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