#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 /*<<< orphan*/ delay_1ms(int);
scalar_t__ hwconfig_simulation_p();
int hwconfig_wishbone_divisor();
void mdelay(int ms) {
  static int loop_count = -1;
  if (hwconfig_simulation_p())
    return;
  if (loop_count < 0) {
    static unsigned short lc[8] = {0,
                                   (100000000 / (1) / 10000),
                                   (100000000 / (2) / 10000),
                                   (100000000 / (3) / 10000),
                                   (100000000 / (4) / 10000),
                                   (100000000 / (5) / 10000),
                                   (100000000 / (6) / 10000),
                                   (100000000 / (7) / 10000)};
    loop_count = lc[hwconfig_wishbone_divisor() & 0x7];
  }
  int i;
  for (i = 0; i < ms; i++)
    delay_1ms(loop_count);
}


x86 assembly (clang, -O0):
<mdelay>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1040 <hwconfig_simulation_p@plt>
cmp    $0x0,%rax
je     1151 <mdelay+0x21>
jmp    11a8 <mdelay+0x78>
cmpl   $0x0,0x2ee8(%rip)
jge    117c <mdelay+0x4c>
mov    $0x0,%al
call   1050 <hwconfig_wishbone_divisor@plt>
and    $0x7,%eax
movslq %eax,%rcx
lea    0x2ede(%rip),%rax
movzwl (%rax,%rcx,2),%eax
mov    %eax,0x2ec4(%rip)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11a8 <mdelay+0x78>
mov    0x2eab(%rip),%edi
call   1030 <delay_1ms@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1183 <mdelay+0x53>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mdelay>:
push   %rbx
mov    %edi,%ebx
xor    %eax,%eax
call   1040 <hwconfig_simulation_p@plt>
test   %rax,%rax
je     1141 <mdelay+0x11>
pop    %rbx
ret
mov    0x2ef1(%rip),%edi
test   %edi,%edi
jns    1166 <mdelay+0x36>
xor    %eax,%eax
call   1050 <hwconfig_wishbone_divisor@plt>
and    $0x7,%eax
lea    0xea4(%rip),%rcx
movzwl (%rcx,%rax,2),%edi
mov    %edi,0x2ed2(%rip)
test   %ebx,%ebx
jle    113f <mdelay+0xf>
call   1030 <delay_1ms@plt>
cmp    $0x1,%ebx
je     113f <mdelay+0xf>
add    $0xffffffff,%ebx
nopw   0x0(%rax,%rax,1)
mov    0x2eb2(%rip),%edi
call   1030 <delay_1ms@plt>
add    $0xffffffff,%ebx
jne    1180 <mdelay+0x50>
jmp    113f <mdelay+0xf>

LLVM IR (-O0):
@mdelay.loop_count = internal global i32 -1
@mdelay.lc = internal global [8 x i16] [i16 0, i16 10000, i16 5000, i16 3333, i16 2500, i16 2000, i16 1666, i16 1428]
define void @mdelay(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = call i64 (...) @hwconfig_simulation_p()
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %7
6: ; preds = %1
br label %28
7: ; preds = %1
%8 = load i32, i32* @mdelay.loop_count
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %7
%11 = call i32 (...) @hwconfig_wishbone_divisor()
%12 = and i32 %11, 7
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [8 x i16], [8 x i16]* @mdelay.lc, i64 0, i64 %13
%15 = load i16, i16* %14
%16 = zext i16 %15 to i32
store i32 %16, i32* @mdelay.loop_count
br label %17
17: ; preds = %10, %7
store i32 0, i32* %3
br label %18
18: ; preds = %25, %17
%19 = load i32, i32* %3
%20 = load i32, i32* %2
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %28
22: ; preds = %18
%23 = load i32, i32* @mdelay.loop_count
%24 = call i32 @delay_1ms(i32 %23)
br label %25
25: ; preds = %22
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %3
br label %18
28: ; preds = %6, %18
ret void
}

LLVM IR (-O2):
@mdelay.loop_count = internal unnamed_addr global i32 -1
@mdelay.lc = internal unnamed_addr constant [8 x i16] [i16 0, i16 10000, i16 5000, i16 3333, i16 2500, i16 2000, i16 1666, i16 1428]
define void @mdelay(i32 %0) {
%2 = tail call i64 (...) @hwconfig_simulation_p()
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %26
4: ; preds = %1
%5 = load i32, i32* @mdelay.loop_count
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %14
7: ; preds = %4
%8 = tail call i32 (...) @hwconfig_wishbone_divisor()
%9 = and i32 %8, 7
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds [8 x i16], [8 x i16]* @mdelay.lc, i64 0, i64 %10
%12 = load i16, i16* %11
%13 = zext i16 %12 to i32
store i32 %13, i32* @mdelay.loop_count
br label %14
14: ; preds = %7, %4
%15 = phi i32 [ %13, %7 ], [ %5, %4 ]
%16 = icmp sgt i32 %0, 0
br i1 %16, label %17, label %26
17: ; preds = %14
%18 = tail call i32 @delay_1ms(i32 %15)
%19 = icmp eq i32 %0, 1
br i1 %19, label %26, label %20
20: ; preds = %17, %20
%21 = phi i32 [ %24, %20 ], [ 1, %17 ]
%22 = load i32, i32* @mdelay.loop_count
%23 = tail call i32 @delay_1ms(i32 %22)
%24 = add nuw nsw i32 %21, 1
%25 = icmp eq i32 %24, %0
br i1 %25, label %26, label %20
26: ; preds = %20, %17, %14, %1
ret void
}