#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 timeval {
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ pollkey();
void mydelay() {
  static struct timeval prev;
  static struct timeval curr;
  gettimeofday(&prev, NULL);
  while (1) {
    gettimeofday(&curr, NULL);
    if (curr.tv_sec > prev.tv_sec)
      return;
    pollkey();
    prev = curr;
  }
}


x86 assembly (clang, -O0):
<mydelay>:
push   %rbp
mov    %rsp,%rbp
lea    0x2f0d(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
lea    0x2f05(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    0x2ef5(%rip),%rax
cmp    0x2ee6(%rip),%rax
jle    115a <mydelay+0x3a>
pop    %rbp
ret
mov    $0x0,%al
call   1030 <pollkey@plt>
mov    0x2ed8(%rip),%rax
mov    %rax,0x2ec9(%rip)
jmp    1134 <mydelay+0x14>

x86 assembly (clang, -O2):
<mydelay>:
push   %rbx
lea    0x2f10(%rip),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
lea    0x2f0a(%rip),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    0x2efc(%rip),%rax
cmp    0x2eed(%rip),%rax
jg     118f <mydelay+0x6f>
lea    0x2eec(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <pollkey@plt>
mov    0x2ed2(%rip),%rax
mov    %rax,0x2ec3(%rip)
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    0x2eba(%rip),%rax
cmp    0x2eab(%rip),%rax
jle    1160 <mydelay+0x40>
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i64 }
@mydelay.prev = internal global %struct.timeval zeroinitializer
@mydelay.curr = internal global %struct.timeval zeroinitializer
define void @mydelay() {
%1 = call i32 @gettimeofday(%struct.timeval* @mydelay.prev, i32* null)
br label %2
2: ; preds = %0, %8
%3 = call i32 @gettimeofday(%struct.timeval* @mydelay.curr, i32* null)
%4 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @mydelay.curr, i32 0, i32 0)
%5 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @mydelay.prev, i32 0, i32 0)
%6 = icmp sgt i64 %4, %5
br i1 %6, label %7, label %8
7: ; preds = %2
ret void
8: ; preds = %2
%9 = call i32 (...) @pollkey()
br label %2
}

LLVM IR (-O2):
%struct.timeval = type { i64 }
@mydelay.prev = internal global %struct.timeval zeroinitializer
@mydelay.curr = internal global %struct.timeval zeroinitializer
define void @mydelay() {
%1 = tail call i32 @gettimeofday(%struct.timeval* @mydelay.prev, i32* null)
%2 = tail call i32 @gettimeofday(%struct.timeval* @mydelay.curr, i32* null)
%3 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @mydelay.curr, i64 0, i32 0)
%4 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @mydelay.prev, i64 0, i32 0)
%5 = icmp sgt i64 %3, %4
br i1 %5, label %6, label %7
6: ; preds = %7, %0
ret void
7: ; preds = %0, %7
%8 = tail call i32 (...) @pollkey()
%9 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @mydelay.curr, i64 0, i32 0)
store i64 %9, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @mydelay.prev, i64 0, i32 0)
%10 = tail call i32 @gettimeofday(%struct.timeval* @mydelay.curr, i32* null)
%11 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @mydelay.curr, i64 0, i32 0)
%12 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @mydelay.prev, i64 0, i32 0)
%13 = icmp sgt i64 %11, %12
br i1 %13, label %6, label %7
}