#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 fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int write_int(FILE *out, unsigned int n) {
  unsigned char buffer[4];
  buffer[0] = n;
  buffer[1] = n >> 8;
  buffer[2] = n >> 16;
  buffer[3] = n >> 24;
  if (fwrite(buffer, 1, 4, out) != 4)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<write_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,-0x18(%rbp)
mov    -0x14(%rbp),%eax
shr    $0x8,%eax
mov    %al,-0x17(%rbp)
mov    -0x14(%rbp),%eax
shr    $0x10,%eax
mov    %al,-0x16(%rbp)
mov    -0x14(%rbp),%eax
shr    $0x18,%eax
mov    %al,-0x15(%rbp)
lea    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fwrite@plt>
cmp    $0x4,%eax
je     116c <write_int+0x5c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1173 <write_int+0x63>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_int>:
push   %rax
mov    %rdi,%rcx
mov    %esi,0x4(%rsp)
lea    0x4(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fwrite@plt>
xor    %ecx,%ecx
cmp    $0x4,%eax
setne  %cl
neg    %ecx
mov    %ecx,%eax
pop    %rcx
ret

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

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