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

/* Variables and functions */
int disable_interrupt_save(int);
int /*<<< orphan*/ restore_interrupt(int);
int /*<<< orphan*/ udelay(int);
void ipod_set_brightness(int val) {
  int oldlevel;
  int brightness_current = 16;
  if (brightness_current < val) {
    do {
      oldlevel = disable_interrupt_save(0x80);
      do {
        *(&(*(volatile unsigned long *)(0x6000d02c)) + (0x800 / sizeof(long))) =
            0x80 << 8;
      } while (0);
      udelay(10);
      do {
        *(&(*(volatile unsigned long *)(0x6000d02c)) + (0x800 / sizeof(long))) =
            (0x80 << 8) | 0x80;
      } while (0);
      restore_interrupt(oldlevel);
      udelay(10);
    } while (++brightness_current < val);
  } else if (brightness_current > val) {
    do {
      oldlevel = disable_interrupt_save(0x80);
      do {
        *(&(*(volatile unsigned long *)(0x6000d02c)) + (0x800 / sizeof(long))) =
            0x80 << 8;
      } while (0);
      udelay(200);
      do {
        *(&(*(volatile unsigned long *)(0x6000d02c)) + (0x800 / sizeof(long))) =
            (0x80 << 8) | 0x80;
      } while (0);
      restore_interrupt(oldlevel);
      udelay(10);
    } while (--brightness_current > val);
  }
}


x86 assembly (clang, -O0):
<ipod_set_brightness>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x10,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11b3 <ipod_set_brightness+0x83>
jmp    1153 <ipod_set_brightness+0x23>
mov    $0x80,%edi
call   1040 <disable_interrupt_save@plt>
mov    %eax,-0x8(%rbp)
mov    $0x6000d02c,%eax
movq   $0x8000,0x800(%rax)
mov    $0xa,%edi
call   1050 <udelay@plt>
mov    $0x6000d02c,%eax
movq   $0x8080,0x800(%rax)
mov    -0x8(%rbp),%edi
call   1030 <restore_interrupt@plt>
mov    $0xa,%edi
call   1050 <udelay@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmp    -0x4(%rbp),%eax
jl     1153 <ipod_set_brightness+0x23>
jmp    1229 <ipod_set_brightness+0xf9>
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jle    1224 <ipod_set_brightness+0xf4>
jmp    11c4 <ipod_set_brightness+0x94>
mov    $0x80,%edi
call   1040 <disable_interrupt_save@plt>
mov    %eax,-0x8(%rbp)
mov    $0x6000d02c,%eax
movq   $0x8000,0x800(%rax)
mov    $0xc8,%edi
call   1050 <udelay@plt>
mov    $0x6000d02c,%eax
movq   $0x8080,0x800(%rax)
mov    -0x8(%rbp),%edi
call   1030 <restore_interrupt@plt>
mov    $0xa,%edi
call   1050 <udelay@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
cmp    -0x4(%rbp),%eax
jg     11c4 <ipod_set_brightness+0x94>
jmp    1224 <ipod_set_brightness+0xf4>
jmp    1229 <ipod_set_brightness+0xf9>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipod_set_brightness>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
cmp    $0x11,%edi
jl     1186 <ipod_set_brightness+0x56>
add    $0xfffffff0,%ebx
xchg   %ax,%ax
mov    $0x80,%edi
call   1040 <disable_interrupt_save@plt>
mov    %eax,%ebp
movq   $0x8000,0x6000d82c
mov    $0xa,%edi
call   1050 <udelay@plt>
movq   $0x8080,0x6000d82c
mov    %ebp,%edi
call   1030 <restore_interrupt@plt>
mov    $0xa,%edi
call   1050 <udelay@plt>
add    $0xffffffff,%ebx
jne    1140 <ipod_set_brightness+0x10>
jmp    11d8 <ipod_set_brightness+0xa8>
cmp    $0x10,%ebx
je     11d8 <ipod_set_brightness+0xa8>
mov    $0x10,%ebp
mov    $0x80,%edi
call   1040 <disable_interrupt_save@plt>
mov    %eax,%r14d
movq   $0x8000,0x6000d82c
mov    $0xc8,%edi
call   1050 <udelay@plt>
movq   $0x8080,0x6000d82c
mov    %r14d,%edi
call   1030 <restore_interrupt@plt>
mov    $0xa,%edi
call   1050 <udelay@plt>
add    $0xffffffff,%ebp
cmp    %ebx,%ebp
jg     1190 <ipod_set_brightness+0x60>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @ipod_set_brightness(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 16, i32* %4
%5 = load i32, i32* %4
%6 = load i32, i32* %2
%7 = icmp slt i32 %5, %6
br i1 %7, label %8, label %25
8: ; preds = %1
br label %9
9: ; preds = %19, %8
%10 = call i32 @disable_interrupt_save(i32 128)
store i32 %10, i32* %3
br label %11
11: ; preds = %9
store volatile i64 32768, i64* getelementptr inbounds (i64, i64* inttoptr (i64 1610666028 to i64*), i64 256)
br label %12
12: ; preds = %11
%13 = call i32 @udelay(i32 10)
br label %14
14: ; preds = %12
store volatile i64 32896, i64* getelementptr inbounds (i64, i64* inttoptr (i64 1610666028 to i64*), i64 256)
br label %15
15: ; preds = %14
%16 = load i32, i32* %3
%17 = call i32 @restore_interrupt(i32 %16)
%18 = call i32 @udelay(i32 10)
br label %19
19: ; preds = %15
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
%22 = load i32, i32* %2
%23 = icmp slt i32 %21, %22
br i1 %23, label %9, label %24
24: ; preds = %19
br label %47
25: ; preds = %1
%26 = load i32, i32* %4
%27 = load i32, i32* %2
%28 = icmp sgt i32 %26, %27
br i1 %28, label %29, label %46
29: ; preds = %25
br label %30
30: ; preds = %40, %29
%31 = call i32 @disable_interrupt_save(i32 128)
store i32 %31, i32* %3
br label %32
32: ; preds = %30
store volatile i64 32768, i64* getelementptr inbounds (i64, i64* inttoptr (i64 1610666028 to i64*), i64 256)
br label %33
33: ; preds = %32
%34 = call i32 @udelay(i32 200)
br label %35
35: ; preds = %33
store volatile i64 32896, i64* getelementptr inbounds (i64, i64* inttoptr (i64 1610666028 to i64*), i64 256)
br label %36
36: ; preds = %35
%37 = load i32, i32* %3
%38 = call i32 @restore_interrupt(i32 %37)
%39 = call i32 @udelay(i32 10)
br label %40
40: ; preds = %36
%41 = load i32, i32* %4
%42 = add nsw i32 %41, -1
store i32 %42, i32* %4
%43 = load i32, i32* %2
%44 = icmp sgt i32 %42, %43
br i1 %44, label %30, label %45
45: ; preds = %40
br label %46
46: ; preds = %45, %25
br label %47
47: ; preds = %46, %24
ret void
}

LLVM IR (-O2):
define void @ipod_set_brightness(i32 %0) {
%2 = icmp sgt i32 %0, 16
br i1 %2, label %3, label %11
3: ; preds = %1, %3
%4 = phi i32 [ %9, %3 ], [ 16, %1 ]
%5 = tail call i32 @disable_interrupt_save(i32 128)
store volatile i64 32768, i64* inttoptr (i64 1610668076 to i64*)
%6 = tail call i32 @udelay(i32 10)
store volatile i64 32896, i64* inttoptr (i64 1610668076 to i64*)
%7 = tail call i32 @restore_interrupt(i32 %5)
%8 = tail call i32 @udelay(i32 10)
%9 = add nuw nsw i32 %4, 1
%10 = icmp eq i32 %9, %0
br i1 %10, label %21, label %3
11: ; preds = %1
%12 = icmp eq i32 %0, 16
br i1 %12, label %21, label %13
13: ; preds = %11, %13
%14 = phi i32 [ %19, %13 ], [ 16, %11 ]
%15 = tail call i32 @disable_interrupt_save(i32 128)
store volatile i64 32768, i64* inttoptr (i64 1610668076 to i64*)
%16 = tail call i32 @udelay(i32 200)
store volatile i64 32896, i64* inttoptr (i64 1610668076 to i64*)
%17 = tail call i32 @restore_interrupt(i32 %15)
%18 = tail call i32 @udelay(i32 10)
%19 = add nsw i32 %14, -1
%20 = icmp sgt i32 %19, %0
br i1 %20, label %13, label %21
21: ; preds = %13, %3, %11
ret void
}