#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 scalar_t__ uint32_t;

/* Variables and functions */
void rpi2_delay_loop(unsigned int delay_ms) {
  uint32_t tm_start, tm_curr, tm_period, tm_delay;
  volatile uint32_t *tmr;
  if (delay_ms == 0)
    return;
  tmr = (volatile uint32_t *)0x3f003004;
  tm_period = 0;
  tm_delay = (uint32_t)(delay_ms * 1000);
  tm_start = tm_curr = *tmr;
  while (tm_period < tm_delay) {
    tm_curr = *tmr;
    tm_period = (uint32_t)(tm_curr - tm_start);
  }
}


x86 assembly (clang, -O0):
<rpi2_delay_loop>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1116 <rpi2_delay_loop+0x16>
jmp    116d <rpi2_delay_loop+0x6d>
mov    $0x3f003004,%eax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x20(%rbp)
imul   $0x3e8,-0x4(%rbp),%eax
mov    %eax,%eax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jge    116d <rpi2_delay_loop+0x6d>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
sub    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1143 <rpi2_delay_loop+0x43>
pop    %rbp
ret

x86 assembly (clang, -O2):
<rpi2_delay_loop>:
test   %edi,%edi
je     1130 <rpi2_delay_loop+0x30>
imul   $0x3e8,%edi,%eax
mov    0x3f003004,%rcx
3f
test   %eax,%eax
je     1130 <rpi2_delay_loop+0x30>
cs nopw 0x0(%rax,%rax,1)
mov    0x3f003004,%rdx
3f
sub    %rcx,%rdx
cmp    %rax,%rdx
jl     1120 <rpi2_delay_loop+0x20>
ret

LLVM IR (-O0):
define void @rpi2_delay_loop(i32 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64*
store i32 %0, i32* %2
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
br label %27
11: ; preds = %1
store i64* inttoptr (i64 1056976900 to i64*), i64** %7
store i64 0, i64* %5
%12 = load i32, i32* %2
%13 = mul i32 %12, 1000
%14 = zext i32 %13 to i64
store i64 %14, i64* %6
%15 = load i64*, i64** %7
%16 = load volatile i64, i64* %15
store i64 %16, i64* %4
store i64 %16, i64* %3
br label %17
17: ; preds = %21, %11
%18 = load i64, i64* %5
%19 = load i64, i64* %6
%20 = icmp slt i64 %18, %19
br i1 %20, label %21, label %27
21: ; preds = %17
%22 = load i64*, i64** %7
%23 = load volatile i64, i64* %22
store i64 %23, i64* %4
%24 = load i64, i64* %4
%25 = load i64, i64* %3
%26 = sub nsw i64 %24, %25
store i64 %26, i64* %5
br label %17
27: ; preds = %10, %17
ret void
}

LLVM IR (-O2):
define void @rpi2_delay_loop(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %12, label %3
3: ; preds = %1
%4 = mul i32 %0, 1000
%5 = zext i32 %4 to i64
%6 = load volatile i64, i64* inttoptr (i64 1056976900 to i64*)
%7 = icmp eq i32 %4, 0
br i1 %7, label %12, label %8
8: ; preds = %3, %8
%9 = load volatile i64, i64* inttoptr (i64 1056976900 to i64*)
%10 = sub nsw i64 %9, %6
%11 = icmp slt i64 %10, %5
br i1 %11, label %8, label %12
12: ; preds = %8, %3, %1
ret void
}