#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 timeb {
  scalar_t__ millitm;
};

/* Variables and functions */
int /*<<< orphan*/ ftime(struct timeb *);
void msleep(int ms) {
  volatile struct timeb t0, t1;
  do {
    ftime((struct timeb *)&t0);
    do {
      ftime((struct timeb *)&t1);
    } while (t1.millitm == t0.millitm);
  } while (ms-- > 0);
}


x86 assembly (clang, -O0):
<msleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x10(%rbp),%rdi
call   1030 <ftime@plt>
lea    -0x18(%rbp),%rdi
call   1030 <ftime@plt>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    %rcx,%rax
je     1124 <msleep+0x14>
jmp    1143 <msleep+0x33>
mov    -0x4(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x4(%rbp)
cmp    $0x0,%eax
jg     111b <msleep+0xb>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msleep>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r15d
lea    0x8(%rsp),%r14
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
call   1030 <ftime@plt>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <ftime@plt>
mov    (%rsp),%rax
cmp    0x8(%rsp),%rax
je     1140 <msleep+0x30>
lea    -0x1(%r15),%eax
test   %r15d,%r15d
mov    %eax,%r15d
jg     1130 <msleep+0x20>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeb = type { i64 }
define void @msleep(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timeb
%4 = alloca %struct.timeb
store i32 %0, i32* %2
br label %5
5: ; preds = %16, %1
%6 = call i32 @ftime(%struct.timeb* %3)
br label %7
7: ; preds = %9, %5
%8 = call i32 @ftime(%struct.timeb* %4)
br label %9
9: ; preds = %7
%10 = getelementptr inbounds %struct.timeb, %struct.timeb* %4, i32 0, i32 0
%11 = load volatile i64, i64* %10
%12 = getelementptr inbounds %struct.timeb, %struct.timeb* %3, i32 0, i32 0
%13 = load volatile i64, i64* %12
%14 = icmp eq i64 %11, %13
br i1 %14, label %7, label %15
15: ; preds = %9
br label %16
16: ; preds = %15
%17 = load i32, i32* %2
%18 = add nsw i32 %17, -1
store i32 %18, i32* %2
%19 = icmp sgt i32 %17, 0
br i1 %19, label %5, label %20
20: ; preds = %16
ret void
}

LLVM IR (-O2):
%struct.timeb = type { i64 }
define void @msleep(i32 %0) {
%2 = alloca %struct.timeb
%3 = alloca %struct.timeb
%4 = bitcast %struct.timeb* %2 to i8*
%5 = bitcast %struct.timeb* %3 to i8*
%6 = getelementptr inbounds %struct.timeb, %struct.timeb* %3, i64 0, i32 0
%7 = getelementptr inbounds %struct.timeb, %struct.timeb* %2, i64 0, i32 0
br label %8
8: ; preds = %16, %1
%9 = phi i32 [ %0, %1 ], [ %17, %16 ]
%10 = call i32 @ftime(%struct.timeb* %2)
br label %11
11: ; preds = %11, %8
%12 = call i32 @ftime(%struct.timeb* %3)
%13 = load volatile i64, i64* %6
%14 = load volatile i64, i64* %7
%15 = icmp eq i64 %13, %14
br i1 %15, label %11, label %16
16: ; preds = %11
%17 = add nsw i32 %9, -1
%18 = icmp sgt i32 %9, 0
br i1 %18, label %8, label %19
19: ; preds = %16
ret void
}