#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 /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
void intio_write(FILE *f, int v) {
  unsigned char b;
  int i;
  for (i = 0; i < 3; i++) {
    b = v & 0xff;
    fwrite(&b, 1, 1, f);
    v >>= 8;
  }
  b = v > 0 ? v : v + 256;
  fwrite(&b, 1, 1, f);
}


x86 assembly (clang, -O0):
<intio_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    1166 <intio_write+0x56>
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %al,-0xd(%rbp)
mov    -0x8(%rbp),%rcx
lea    -0xd(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fwrite@plt>
mov    -0xc(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1126 <intio_write+0x16>
cmpl   $0x0,-0xc(%rbp)
jle    117b <intio_write+0x6b>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1186 <intio_write+0x76>
mov    -0xc(%rbp),%eax
add    $0x100,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %al,-0xd(%rbp)
mov    -0x8(%rbp),%rcx
lea    -0xd(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fwrite@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<intio_write>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
movsbl %bl,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    %ebx,%eax
shr    $0x8,%eax
movsbl %al,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    %ebx,%eax
shr    $0x10,%eax
movsbl %al,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
sar    $0x18,%ebx
mov    %ebx,%edi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fputc@plt>

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

LLVM IR (-O2):
define void @intio_write(i32* nocapture %0, i32 %1) {
%3 = shl i32 %1, 24
%4 = ashr exact i32 %3, 24
%5 = tail call i32 @fputc(i32 %4, i32* %0)
%6 = shl i32 %1, 16
%7 = ashr i32 %6, 24
%8 = tail call i32 @fputc(i32 %7, i32* %0)
%9 = shl i32 %1, 8
%10 = ashr i32 %9, 24
%11 = tail call i32 @fputc(i32 %10, i32* %0)
%12 = ashr i32 %1, 24
%13 = tail call i32 @fputc(i32 %12, i32* %0)
ret void
}