#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*/ value;

/* Variables and functions */
int /*<<< orphan*/ text_write_ub(char *, unsigned char);
void text_write_ul(void *addr, unsigned long value) {
  int i;
  for (i = 0; i < sizeof(value); i++) {
    text_write_ub((char *)addr + i, ((unsigned char *)&value)[i]);
  }
}


x86 assembly (clang, -O0):
<text_write_ul>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    $0x8,%rax
jae    115c <text_write_ul+0x4c>
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
movslq -0x14(%rbp),%rax
movzbl -0x10(%rbp,%rax,1),%esi
call   1030 <text_write_ub@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1127 <text_write_ul+0x17>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<text_write_ul>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    %rsi,%r13
shr    $0x20,%r13
mov    %rsi,%r12
shr    $0x28,%r12
mov    %rsi,%r15
shr    $0x30,%r15
mov    %rsi,%r14
shr    $0x38,%r14
movzbl %bl,%esi
call   1030 <text_write_ub@plt>
lea    0x1(%rbp),%rdi
movzbl %bh,%esi
call   1030 <text_write_ub@plt>
lea    0x2(%rbp),%rdi
mov    %ebx,%eax
shr    $0x10,%eax
movzbl %al,%esi
call   1030 <text_write_ub@plt>
lea    0x3(%rbp),%rdi
shr    $0x18,%ebx
mov    %ebx,%esi
call   1030 <text_write_ub@plt>
lea    0x4(%rbp),%rdi
movzbl %r13b,%esi
call   1030 <text_write_ub@plt>
lea    0x5(%rbp),%rdi
movzbl %r12b,%esi
call   1030 <text_write_ub@plt>
lea    0x6(%rbp),%rdi
movzbl %r15b,%esi
call   1030 <text_write_ub@plt>
add    $0x7,%rbp
mov    %rbp,%rdi
mov    %r14d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <text_write_ub@plt>

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

LLVM IR (-O2):
define void @text_write_ul(i8* %0, i64 %1) {
%3 = trunc i64 %1 to i8
%4 = lshr i64 %1, 8
%5 = trunc i64 %4 to i8
%6 = lshr i64 %1, 16
%7 = trunc i64 %6 to i8
%8 = lshr i64 %1, 24
%9 = trunc i64 %8 to i8
%10 = lshr i64 %1, 32
%11 = trunc i64 %10 to i8
%12 = lshr i64 %1, 40
%13 = trunc i64 %12 to i8
%14 = lshr i64 %1, 48
%15 = trunc i64 %14 to i8
%16 = lshr i64 %1, 56
%17 = trunc i64 %16 to i8
%18 = tail call i32 @text_write_ub(i8* %0, i8 zeroext %3)
%19 = getelementptr inbounds i8, i8* %0, i64 1
%20 = tail call i32 @text_write_ub(i8* %19, i8 zeroext %5)
%21 = getelementptr inbounds i8, i8* %0, i64 2
%22 = tail call i32 @text_write_ub(i8* %21, i8 zeroext %7)
%23 = getelementptr inbounds i8, i8* %0, i64 3
%24 = tail call i32 @text_write_ub(i8* %23, i8 zeroext %9)
%25 = getelementptr inbounds i8, i8* %0, i64 4
%26 = tail call i32 @text_write_ub(i8* %25, i8 zeroext %11)
%27 = getelementptr inbounds i8, i8* %0, i64 5
%28 = tail call i32 @text_write_ub(i8* %27, i8 zeroext %13)
%29 = getelementptr inbounds i8, i8* %0, i64 6
%30 = tail call i32 @text_write_ub(i8* %29, i8 zeroext %15)
%31 = getelementptr inbounds i8, i8* %0, i64 7
%32 = tail call i32 @text_write_ub(i8* %31, i8 zeroext %17)
ret void
}