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

/* Variables and functions */
int /*<<< orphan*/ fputc(unsigned char, int /*<<< orphan*/ *);
void write_uint(FILE *file, uint64_t u, int size) {
  unsigned char *p_first = (char *)&u;
  unsigned char *p_current;
  for (p_current = p_first + (size - 1); p_current >= p_first; p_current--) {
    fputc(*p_current, file);
  }
}


x86 assembly (clang, -O0):
<write_uint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    -0xc(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jb     116f <write_uint+0x5f>
mov    -0x20(%rbp),%rax
mov    (%rax),%al
mov    -0x8(%rbp),%rsi
movzbl %al,%edi
call   1030 <fputc@plt>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    113e <write_uint+0x2e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_uint>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,0xc(%rsp)
movslq %edx,%rax
lea    0xc(%rsp),%r14
lea    (%rax,%r14,1),%rbx
add    $0xffffffffffffffff,%rbx
cmp    %r14,%rbx
jb     1154 <write_uint+0x44>
mov    %rdi,%r15
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%rbx),%edi
mov    %r15,%rsi
call   1030 <fputc@plt>
add    $0xffffffffffffffff,%rbx
cmp    %r14,%rbx
jae    1140 <write_uint+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @write_uint(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = bitcast i32* %5 to i8*
store i8* %9, i8** %7
%10 = load i8*, i8** %7
%11 = load i32, i32* %6
%12 = sub nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %10, i64 %13
store i8* %14, i8** %8
br label %15
15: ; preds = %24, %3
%16 = load i8*, i8** %8
%17 = load i8*, i8** %7
%18 = icmp uge i8* %16, %17
br i1 %18, label %19, label %27
19: ; preds = %15
%20 = load i8*, i8** %8
%21 = load i8, i8* %20
%22 = load i32*, i32** %4
%23 = call i32 @fputc(i8 zeroext %21, i32* %22)
br label %24
24: ; preds = %19
%25 = load i8*, i8** %8
%26 = getelementptr inbounds i8, i8* %25, i32 -1
store i8* %26, i8** %8
br label %15
27: ; preds = %15
ret void
}

LLVM IR (-O2):
define void @write_uint(i32* nocapture %0, i32 %1, i32 %2) {
%4 = alloca i32
store i32 %1, i32* %4
%5 = bitcast i32* %4 to i8*
%6 = add nsw i32 %2, -1
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %5, i64 %7
%9 = icmp ult i8* %8, %5
br i1 %9, label %16, label %10
10: ; preds = %3, %10
%11 = phi i8* [ %14, %10 ], [ %8, %3 ]
%12 = load i8, i8* %11
%13 = call i32 @fputc(i8 zeroext %12, i32* %0)
%14 = getelementptr inbounds i8, i8* %11, i64 -1
%15 = icmp ult i8* %14, %5
br i1 %15, label %16, label %10
16: ; preds = %10, %3
ret void
}