#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 */
struct timezone {
  int dummy;
};
struct timeval {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, struct timezone *);
scalar_t__ malloc(int);
double msdelay(double howmuch) {
  struct timeval *tp;
  static int i, j, k;
  double cs, cus;
  static double cas1, cas2, oldcas2, rozdil_c12, cinit, xd;
  tp = (struct timeval *)(malloc(sizeof(struct timeval)));
  gettimeofday(tp, (struct timezone *)0);
  cs = (double)tp->tv_sec;
  cus = (double)tp->tv_usec;
  cas1 = cs + cus / 1000000.0;
  cas2 = cas1;
  oldcas2 = cas2;
  rozdil_c12 = 0.0;
  i = 0;
  while (howmuch > rozdil_c12) {
    gettimeofday(tp, (struct timezone *)0);
    cs = (double)tp->tv_sec;
    cus = (double)tp->tv_usec;
    cas2 = cs + cus / 1000000.0;
    rozdil_c12 = (cas2 - cas1) * 1000.0;
    for (j = 0; j < 1000; j++) {
      for (k = 0; k < 10; k++) {
        xd = 3 * k / (j + 1);
      }
    }
    oldcas2 = cas2;
    i++;
  }
  return rozdil_c12;
}


x86 assembly (clang, -O0):
<msdelay>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x10(%rbp),%rax
cvtsi2sdq 0x8(%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cvtsi2sdq (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  0xe89(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,0x2ec1(%rip)
movsd  0x2eb9(%rip),%xmm0
movsd  %xmm0,0x2eb9(%rip)
movsd  0x2eb1(%rip),%xmm0
movsd  %xmm0,0x2eb1(%rip)
xorps  %xmm0,%xmm0
movsd  %xmm0,0x2eae(%rip)
movl   $0x0,0x2e7c(%rip)
movsd  -0x8(%rbp),%xmm0
ucomisd 0x2e97(%rip),%xmm0
jbe    12e0 <msdelay+0x1c0>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x10(%rbp),%rax
cvtsi2sdq 0x8(%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cvtsi2sdq (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  0xdf5(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,0x2e35(%rip)
movsd  0x2e2d(%rip),%xmm0
subsd  0x2e1d(%rip),%xmm0
movsd  0xdd5(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x2e21(%rip)
movl   $0x0,0x2df3(%rip)
cmpl   $0x3e8,0x2de9(%rip)
jge    12bc <msdelay+0x19c>
movl   $0x0,0x2ddd(%rip)
cmpl   $0xa,0x2dd6(%rip)
jge    12a3 <msdelay+0x183>
imul   $0x3,0x2dc9(%rip),%eax
mov    0x2dbf(%rip),%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x2de1(%rip)
mov    0x2dab(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2da2(%rip)
jmp    1263 <msdelay+0x143>
jmp    12a8 <msdelay+0x188>
mov    0x2d8e(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2d85(%rip)
jmp    1249 <msdelay+0x129>
movsd  0x2d8c(%rip),%xmm0
movsd  %xmm0,0x2d8c(%rip)
mov    0x2d66(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2d5d(%rip)
jmp    11bc <msdelay+0x9c>
movsd  0x2d78(%rip),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msdelay>:
push   %rbx
sub    $0x10,%rsp
movsd  %xmm0,0x8(%rsp)
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
xorps  %xmm0,%xmm0
cvtsi2sdq 0x8(%rbx),%xmm0
cvtsi2sdq (%rbx),%xmm1
divsd  0xea8(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x2edc(%rip)
movsd  0x8(%rsp),%xmm1
movl   $0x0,0x2ec4(%rip)
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jbe    11ca <msdelay+0xaa>
xchg   %ax,%ax
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
xorps  %xmm1,%xmm1
cvtsi2sdq 0x8(%rbx),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sdq (%rbx),%xmm0
divsd  0xe5d(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  0x8(%rsp),%xmm1
subsd  0x2e8b(%rip),%xmm0
addl   $0x1,0x2e7c(%rip)
mulsd  0xe44(%rip),%xmm0
ucomisd %xmm0,%xmm1
ja     1180 <msdelay+0x60>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
%struct.timezone = type { i32 }
@msdelay.i = internal global i32 0
@msdelay.j = internal global i32 0
@msdelay.k = internal global i32 0
@msdelay.cas1 = internal global double 0.000000e+00
@msdelay.cas2 = internal global double 0.000000e+00
@msdelay.oldcas2 = internal global double 0.000000e+00
@msdelay.rozdil_c12 = internal global double 0.000000e+00
@msdelay.cinit = internal global double 0.000000e+00
@msdelay.xd = internal global double 0.000000e+00
define double @msdelay(double %0) {
%2 = alloca double
%3 = alloca %struct.timeval*
%4 = alloca double
%5 = alloca double
store double %0, double* %2
%6 = call i64 @malloc(i32 16)
%7 = inttoptr i64 %6 to %struct.timeval*
store %struct.timeval* %7, %struct.timeval** %3
%8 = load %struct.timeval*, %struct.timeval** %3
%9 = call i32 @gettimeofday(%struct.timeval* %8, %struct.timezone* null)
%10 = load %struct.timeval*, %struct.timeval** %3
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 1
%12 = load i64, i64* %11
%13 = sitofp i64 %12 to double
store double %13, double* %4
%14 = load %struct.timeval*, %struct.timeval** %3
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
%16 = load i64, i64* %15
%17 = sitofp i64 %16 to double
store double %17, double* %5
%18 = load double, double* %4
%19 = load double, double* %5
%20 = fdiv double %19, 1.000000e+06
%21 = fadd double %18, %20
store double %21, double* @msdelay.cas1
%22 = load double, double* @msdelay.cas1
store double %22, double* @msdelay.cas2
%23 = load double, double* @msdelay.cas2
store double %23, double* @msdelay.oldcas2
store double 0.000000e+00, double* @msdelay.rozdil_c12
store i32 0, i32* @msdelay.i
br label %24
24: ; preds = %68, %1
%25 = load double, double* %2
%26 = load double, double* @msdelay.rozdil_c12
%27 = fcmp ogt double %25, %26
br i1 %27, label %28, label %72
28: ; preds = %24
%29 = load %struct.timeval*, %struct.timeval** %3
%30 = call i32 @gettimeofday(%struct.timeval* %29, %struct.timezone* null)
%31 = load %struct.timeval*, %struct.timeval** %3
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %31, i32 0, i32 1
%33 = load i64, i64* %32
%34 = sitofp i64 %33 to double
store double %34, double* %4
%35 = load %struct.timeval*, %struct.timeval** %3
%36 = getelementptr inbounds %struct.timeval, %struct.timeval* %35, i32 0, i32 0
%37 = load i64, i64* %36
%38 = sitofp i64 %37 to double
store double %38, double* %5
%39 = load double, double* %4
%40 = load double, double* %5
%41 = fdiv double %40, 1.000000e+06
%42 = fadd double %39, %41
store double %42, double* @msdelay.cas2
%43 = load double, double* @msdelay.cas2
%44 = load double, double* @msdelay.cas1
%45 = fsub double %43, %44
%46 = fmul double %45, 1.000000e+03
store double %46, double* @msdelay.rozdil_c12
store i32 0, i32* @msdelay.j
br label %47
47: ; preds = %65, %28
%48 = load i32, i32* @msdelay.j
%49 = icmp slt i32 %48, 1000
br i1 %49, label %50, label %68
50: ; preds = %47
store i32 0, i32* @msdelay.k
br label %51
51: ; preds = %61, %50
%52 = load i32, i32* @msdelay.k
%53 = icmp slt i32 %52, 10
br i1 %53, label %54, label %64
54: ; preds = %51
%55 = load i32, i32* @msdelay.k
%56 = mul nsw i32 3, %55
%57 = load i32, i32* @msdelay.j
%58 = add nsw i32 %57, 1
%59 = sdiv i32 %56, %58
%60 = sitofp i32 %59 to double
store double %60, double* @msdelay.xd
br label %61
61: ; preds = %54
%62 = load i32, i32* @msdelay.k
%63 = add nsw i32 %62, 1
store i32 %63, i32* @msdelay.k
br label %51
64: ; preds = %51
br label %65
65: ; preds = %64
%66 = load i32, i32* @msdelay.j
%67 = add nsw i32 %66, 1
store i32 %67, i32* @msdelay.j
br label %47
68: ; preds = %47
%69 = load double, double* @msdelay.cas2
store double %69, double* @msdelay.oldcas2
%70 = load i32, i32* @msdelay.i
%71 = add nsw i32 %70, 1
store i32 %71, i32* @msdelay.i
br label %24
72: ; preds = %24
%73 = load double, double* @msdelay.rozdil_c12
ret double %73
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
%struct.timezone = type { i32 }
@msdelay.i = internal unnamed_addr global i32 0
@msdelay.cas1 = internal unnamed_addr global double 0.000000e+00
define double @msdelay(double %0) {
%2 = tail call i64 @malloc(i32 16)
%3 = inttoptr i64 %2 to %struct.timeval*
%4 = tail call i32 @gettimeofday(%struct.timeval* %3, %struct.timezone* null)
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%6 = load i64, i64* %5
%7 = sitofp i64 %6 to double
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%9 = load i64, i64* %8
%10 = sitofp i64 %9 to double
%11 = fdiv double %10, 1.000000e+06
%12 = fadd double %11, %7
store double %12, double* @msdelay.cas1
store i32 0, i32* @msdelay.i
%13 = fcmp ogt double %0, 0.000000e+00
br i1 %13, label %14, label %28
14: ; preds = %1, %14
%15 = tail call i32 @gettimeofday(%struct.timeval* %3, %struct.timezone* null)
%16 = load i64, i64* %5
%17 = sitofp i64 %16 to double
%18 = load i64, i64* %8
%19 = sitofp i64 %18 to double
%20 = fdiv double %19, 1.000000e+06
%21 = fadd double %20, %17
%22 = load double, double* @msdelay.cas1
%23 = fsub double %21, %22
%24 = fmul double %23, 1.000000e+03
%25 = load i32, i32* @msdelay.i
%26 = add nsw i32 %25, 1
store i32 %26, i32* @msdelay.i
%27 = fcmp olt double %24, %0
br i1 %27, label %14, label %28
28: ; preds = %14, %1
%29 = phi double [ 0.000000e+00, %1 ], [ %24, %14 ]
ret double %29
}