#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*/ SEEK_CUR;
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
void wfh_writeint(FILE *file1, int data, int len) {
  int i;
  int d;
  d = data;
  for (i = 0; i < len; i++) {
    int w;
    w = d % 256;
    d = d / 256;
    fputc(w, file1);
  }
  fflush(file1);
  fseek(file1, 0, SEEK_CUR);
}


x86 assembly (clang, -O0):
<wfh_writeint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1191 <wfh_writeint+0x61>
mov    -0x18(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1030 <fputc@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114f <wfh_writeint+0x1f>
mov    -0x8(%rbp),%rdi
call   1040 <fflush@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e43(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <fseek@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wfh_writeint>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
test   %edx,%edx
jle    1168 <wfh_writeint+0x38>
mov    %edx,%ebp
nopl   (%rax)
lea    0xff(%rsi),%eax
test   %esi,%esi
cmovns %esi,%eax
mov    %eax,%ebx
sar    $0x8,%ebx
and    $0xffffff00,%eax
sub    %eax,%esi
mov    %esi,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    %ebx,%esi
add    $0xffffffff,%ebp
jne    1140 <wfh_writeint+0x10>
mov    %r14,%rdi
call   1040 <fflush@plt>
mov    0x2e71(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <fseek@plt>

LLVM IR (-O0):
@SEEK_CUR = global i32 0
define void @wfh_writeint(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32, i32* %5
store i32 %10, i32* %8
store i32 0, i32* %7
br label %11
11: ; preds = %23, %3
%12 = load i32, i32* %7
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %26
15: ; preds = %11
%16 = load i32, i32* %8
%17 = srem i32 %16, 256
store i32 %17, i32* %9
%18 = load i32, i32* %8
%19 = sdiv i32 %18, 256
store i32 %19, i32* %8
%20 = load i32, i32* %9
%21 = load i32*, i32** %4
%22 = call i32 @fputc(i32 %20, i32* %21)
br label %23
23: ; preds = %15
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
br label %11
26: ; preds = %11
%27 = load i32*, i32** %4
%28 = call i32 @fflush(i32* %27)
%29 = load i32*, i32** %4
%30 = load i32, i32* @SEEK_CUR
%31 = call i32 @fseek(i32* %29, i32 0, i32 %30)
ret void
}

LLVM IR (-O2):
@SEEK_CUR = global i32 0
define void @wfh_writeint(i32* nocapture %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %13
5: ; preds = %3, %5
%6 = phi i32 [ %11, %5 ], [ 0, %3 ]
%7 = phi i32 [ %9, %5 ], [ %1, %3 ]
%8 = srem i32 %7, 256
%9 = sdiv i32 %7, 256
%10 = tail call i32 @fputc(i32 %8, i32* %0)
%11 = add nuw nsw i32 %6, 1
%12 = icmp eq i32 %11, %2
br i1 %12, label %13, label %5
13: ; preds = %5, %3
%14 = tail call i32 @fflush(i32* %0)
%15 = load i32, i32* @SEEK_CUR
%16 = tail call i32 @fseek(i32* %0, i32 0, i32 %15)
ret void
}