#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 CLOCKS_PER_SEC;
long clock();
long calcDiv(void) {
  long stTim, endTim;
  int i, j;
  int a;
  stTim = clock();
  a = 0;
  for (i = 0; i < 10000; i++) {
    for (j = 1; j < 10001; j++) {
      a /= j;
    }
  }
  endTim = clock();
  endTim -= stTim;
  if (CLOCKS_PER_SEC > 0) {
    int time_dd = 1000 / CLOCKS_PER_SEC;
    if (time_dd > 0)
      endTim *= time_dd;
  }
  return endTim;
}


x86 assembly (clang, -O0):
<calcDiv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x2710,-0x14(%rbp)
jge    117f <calcDiv+0x6f>
movl   $0x1,-0x18(%rbp)
cmpl   $0x2711,-0x18(%rbp)
jge    116c <calcDiv+0x5c>
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1145 <calcDiv+0x35>
jmp    1171 <calcDiv+0x61>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1131 <calcDiv+0x21>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    0x2e48(%rip),%rax
cmpl   $0x0,(%rax)
jle    11d7 <calcDiv+0xc7>
mov    $0x3e8,%eax
mov    0x2e33(%rip),%rcx
cltd
idivl  (%rcx)
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    11d2 <calcDiv+0xc2>
movslq -0x20(%rbp),%rax
imul   -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    11d7 <calcDiv+0xc7>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calcDiv>:
push   %rbx
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%rcx
sub    %rbx,%rcx
mov    0x2eb9(%rip),%rax
mov    (%rax),%esi
test   %esi,%esi
jle    1150 <calcDiv+0x40>
mov    $0x3e8,%eax
xor    %edx,%edx
div    %esi
cmp    $0x3e9,%esi
mov    $0x1,%edx
cmovb  %eax,%edx
imul   %rdx,%rcx
mov    %rcx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@CLOCKS_PER_SEC = global i32 0
define i64 @calcDiv() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = call i64 (...) @clock()
store i64 %7, i64* %1
store i32 0, i32* %5
store i32 0, i32* %3
br label %8
8: ; preds = %23, %0
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 10000
br i1 %10, label %11, label %26
11: ; preds = %8
store i32 1, i32* %4
br label %12
12: ; preds = %19, %11
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 10001
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = load i32, i32* %4
%17 = load i32, i32* %5
%18 = sdiv i32 %17, %16
store i32 %18, i32* %5
br label %19
19: ; preds = %15
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
br label %12
22: ; preds = %12
br label %23
23: ; preds = %22
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
store i32 %25, i32* %3
br label %8
26: ; preds = %8
%27 = call i64 (...) @clock()
store i64 %27, i64* %2
%28 = load i64, i64* %1
%29 = load i64, i64* %2
%30 = sub nsw i64 %29, %28
store i64 %30, i64* %2
%31 = load i32, i32* @CLOCKS_PER_SEC
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %44
33: ; preds = %26
%34 = load i32, i32* @CLOCKS_PER_SEC
%35 = sdiv i32 1000, %34
store i32 %35, i32* %6
%36 = load i32, i32* %6
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %33
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = load i64, i64* %2
%42 = mul nsw i64 %41, %40
store i64 %42, i64* %2
br label %43
43: ; preds = %38, %33
br label %44
44: ; preds = %43, %26
%45 = load i64, i64* %2
ret i64 %45
}

LLVM IR (-O2):
@CLOCKS_PER_SEC = global i32 0
define i64 @calcDiv() {
%1 = tail call i64 (...) @clock()
%2 = tail call i64 (...) @clock()
%3 = sub nsw i64 %2, %1
%4 = load i32, i32* @CLOCKS_PER_SEC
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %0
%7 = udiv i32 1000, %4
%8 = icmp ugt i32 %4, 1000
%9 = select i1 %8, i32 1, i32 %7
%10 = zext i32 %9 to i64
%11 = mul nsw i64 %3, %10
br label %12
12: ; preds = %6, %0
%13 = phi i64 [ %11, %6 ], [ %3, %0 ]
ret i64 %13
}