#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 */
scalar_t__ get_current_time_millis();
int rand();
int /*<<< orphan*/ srand(int);
int /*<<< orphan*/ usleep(int);
long slow_down(int prob, int max_delay_ms) {
  if (rand() % prob == 0) {
    srand((int)get_current_time_millis());
    long millis = 1 + (rand() % max_delay_ms);
    usleep(1000 * millis);
    return millis;
  }
  return 0;
}


x86 assembly (clang, -O0):
<slow_down>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    11a1 <slow_down+0x61>
mov    $0x0,%al
call   1040 <get_current_time_millis@plt>
mov    %eax,%edi
call   1030 <srand@plt>
mov    $0x0,%al
call   1050 <rand@plt>
cltd
idivl  -0x10(%rbp)
add    $0x1,%edx
movslq %edx,%rax
mov    %rax,-0x18(%rbp)
imul   $0x3e8,-0x18(%rbp),%rax
mov    %eax,%edi
call   1060 <usleep@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a9 <slow_down+0x69>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<slow_down>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebp
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <rand@plt>
cltd
idiv   %ebp
test   %edx,%edx
jne    1183 <slow_down+0x43>
xor    %eax,%eax
call   1040 <get_current_time_millis@plt>
mov    %eax,%edi
call   1030 <srand@plt>
xor    %eax,%eax
call   1050 <rand@plt>
cltd
idiv   %r14d
add    $0x1,%edx
movslq %edx,%rbx
imul   $0x3e8,%ebx,%edi
call   1060 <usleep@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i64 @slow_down(i32 %0, i32 %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = call i32 (...) @rand()
%8 = load i32, i32* %4
%9 = srem i32 %7, %8
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %25
11: ; preds = %2
%12 = call i64 (...) @get_current_time_millis()
%13 = trunc i64 %12 to i32
%14 = call i32 @srand(i32 %13)
%15 = call i32 (...) @rand()
%16 = load i32, i32* %5
%17 = srem i32 %15, %16
%18 = add nsw i32 1, %17
%19 = sext i32 %18 to i64
store i64 %19, i64* %6
%20 = load i64, i64* %6
%21 = mul nsw i64 1000, %20
%22 = trunc i64 %21 to i32
%23 = call i32 @usleep(i32 %22)
%24 = load i64, i64* %6
store i64 %24, i64* %3
br label %26
25: ; preds = %2
store i64 0, i64* %3
br label %26
26: ; preds = %25, %11
%27 = load i64, i64* %3
ret i64 %27
}

LLVM IR (-O2):
define i64 @slow_down(i32 %0, i32 %1) {
%3 = tail call i32 (...) @rand()
%4 = srem i32 %3, %0
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %16
6: ; preds = %2
%7 = tail call i64 (...) @get_current_time_millis()
%8 = trunc i64 %7 to i32
%9 = tail call i32 @srand(i32 %8)
%10 = tail call i32 (...) @rand()
%11 = srem i32 %10, %1
%12 = add nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = mul i32 %12, 1000
%15 = tail call i32 @usleep(i32 %14)
br label %16
16: ; preds = %2, %6
%17 = phi i64 [ %13, %6 ], [ 0, %2 ]
ret i64 %17
}