#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*/ write_byte(int /*<<< orphan*/ *, unsigned int);
void write_delay(FILE *file, unsigned int val) {
  while (val > 0) {
    write_byte(file, 0x00);
    if (val > 255) {
      write_byte(file, 255);
      val -= 255;
    } else {
      write_byte(file, val);
      val = 0;
    }
  }
  return;
}


x86 assembly (clang, -O0):
<write_delay>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jbe    1177 <write_delay+0x67>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1030 <write_byte@plt>
cmpl   $0xff,-0xc(%rbp)
jbe    115f <write_delay+0x4f>
mov    -0x8(%rbp),%rdi
mov    $0xff,%esi
call   1030 <write_byte@plt>
mov    -0xc(%rbp),%eax
sub    $0xff,%eax
mov    %eax,-0xc(%rbp)
jmp    1172 <write_delay+0x62>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <write_byte@plt>
movl   $0x0,-0xc(%rbp)
jmp    111f <write_delay+0xf>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_delay>:
test   %esi,%esi
je     1166 <write_delay+0x56>
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
xor    %esi,%esi
call   1030 <write_byte@plt>
cmp    $0x100,%ebx
jb     1155 <write_delay+0x45>
nopl   0x0(%rax)
mov    %r14,%rdi
mov    $0xff,%esi
call   1030 <write_byte@plt>
add    $0xffffff01,%ebx
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <write_byte@plt>
cmp    $0xff,%ebx
ja     1130 <write_delay+0x20>
mov    %r14,%rdi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <write_byte@plt>
ret

LLVM IR (-O0):
define void @write_delay(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
br label %5
5: ; preds = %22, %2
%6 = load i32, i32* %4
%7 = icmp ugt i32 %6, 0
br i1 %7, label %8, label %23
8: ; preds = %5
%9 = load i32*, i32** %3
%10 = call i32 @write_byte(i32* %9, i32 0)
%11 = load i32, i32* %4
%12 = icmp ugt i32 %11, 255
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = load i32*, i32** %3
%15 = call i32 @write_byte(i32* %14, i32 255)
%16 = load i32, i32* %4
%17 = sub i32 %16, 255
store i32 %17, i32* %4
br label %22
18: ; preds = %8
%19 = load i32*, i32** %3
%20 = load i32, i32* %4
%21 = call i32 @write_byte(i32* %19, i32 %20)
store i32 0, i32* %4
br label %22
22: ; preds = %18, %13
br label %5
23: ; preds = %5
ret void
}

LLVM IR (-O2):
define void @write_delay(i32* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %16, label %4
4: ; preds = %2
%5 = tail call i32 @write_byte(i32* %0, i32 0)
%6 = icmp ugt i32 %1, 255
br i1 %6, label %7, label %13
7: ; preds = %4, %7
%8 = phi i32 [ %10, %7 ], [ %1, %4 ]
%9 = tail call i32 @write_byte(i32* %0, i32 255)
%10 = add i32 %8, -255
%11 = tail call i32 @write_byte(i32* %0, i32 0)
%12 = icmp ugt i32 %10, 255
br i1 %12, label %7, label %13
13: ; preds = %7, %4
%14 = phi i32 [ %1, %4 ], [ %10, %7 ]
%15 = tail call i32 @write_byte(i32* %0, i32 %14)
br label %16
16: ; preds = %13, %2
ret void
}