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

/* Variables and functions */
int /*<<< orphan*/ fwrite(int const *, int, int, int /*<<< orphan*/ *);
void fwrite_int32(bool swap, const uint32_t i, FILE *file) {
  if (swap) {
    const uint32_t x = ((i & 0xff) << 24) | (((i >> 8) & 0xff) << 16) |
                       (((i >> 16) & 0xff) << 8) | (((i >> 24) & 0xff));
    fwrite(&x, 4, 1, file);
  } else {
    fwrite(&i, 4, 1, file);
  }
}


x86 assembly (clang, -O0):
<fwrite_int32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1186 <fwrite_int32+0x76>
mov    -0x8(%rbp),%eax
and    $0xff,%eax
shl    $0x18,%eax
mov    -0x8(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x8(%rbp),%ecx
sar    $0x10,%ecx
and    $0xff,%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    -0x8(%rbp),%ecx
sar    $0x18,%ecx
and    $0xff,%ecx
or     %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fwrite@plt>
jmp    119d <fwrite_int32+0x8d>
mov    -0x10(%rbp),%rcx
lea    -0x8(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fwrite@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fwrite_int32>:
push   %rax
mov    %rdx,%rcx
mov    %esi,0x4(%rsp)
test   %edi,%edi
je     1126 <fwrite_int32+0x16>
bswap  %esi
mov    %esi,(%rsp)
mov    %rsp,%rdi
jmp    112b <fwrite_int32+0x1b>
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fwrite@plt>
pop    %rax
ret

LLVM IR (-O0):
define void @fwrite_int32(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %30
10: ; preds = %3
%11 = load i32, i32* %5
%12 = and i32 %11, 255
%13 = shl i32 %12, 24
%14 = load i32, i32* %5
%15 = ashr i32 %14, 8
%16 = and i32 %15, 255
%17 = shl i32 %16, 16
%18 = or i32 %13, %17
%19 = load i32, i32* %5
%20 = ashr i32 %19, 16
%21 = and i32 %20, 255
%22 = shl i32 %21, 8
%23 = or i32 %18, %22
%24 = load i32, i32* %5
%25 = ashr i32 %24, 24
%26 = and i32 %25, 255
%27 = or i32 %23, %26
store i32 %27, i32* %7
%28 = load i32*, i32** %6
%29 = call i32 @fwrite(i32* %7, i32 4, i32 1, i32* %28)
br label %33
30: ; preds = %3
%31 = load i32*, i32** %6
%32 = call i32 @fwrite(i32* %5, i32 4, i32 1, i32* %31)
br label %33
33: ; preds = %30, %10
ret void
}

LLVM IR (-O2):
define void @fwrite_int32(i32 %0, i32 %1, i32* nocapture %2) {
%4 = alloca i32
%5 = alloca i32
store i32 %1, i32* %4
%6 = icmp eq i32 %0, 0
br i1 %6, label %11, label %7
7: ; preds = %3
%8 = bitcast i32* %5 to i8*
%9 = tail call i32 @llvm.bswap.i32(i32 %1)
store i32 %9, i32* %5
%10 = call i32 @fwrite(i32* %5, i32 4, i32 1, i32* %2)
br label %13
11: ; preds = %3
%12 = call i32 @fwrite(i32* %4, i32 4, i32 1, i32* %2)
br label %13
13: ; preds = %11, %7
ret void
}