#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 */
typedef scalar_t__ time_t;

/* Variables and functions */
int mock_calls(char const *);
scalar_t__ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ usleep(int);
int mock_wait_for_call_num_higher_than(const char *fnc, int limit,
                                       int timeout) {
  time_t start, now;
  int called;
  start = now = time(NULL);
  while (start + timeout > now) {
    called = mock_calls(fnc);
    if (called > limit) {
      return called;
    }
    usleep(100);
    now = time(NULL);
  }
  return 0;
}


x86 assembly (clang, -O0):
<mock_wait_for_call_num_higher_than>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %rax,-0x28(%rbp)
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
add    %rcx,%rax
cmp    -0x28(%rbp),%rax
jle    11a7 <mock_wait_for_call_num_higher_than+0x77>
mov    -0x10(%rbp),%rdi
call   1030 <mock_calls@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    118b <mock_wait_for_call_num_higher_than+0x5b>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ae <mock_wait_for_call_num_higher_than+0x7e>
mov    $0x64,%edi
call   1050 <usleep@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %rax,-0x28(%rbp)
jmp    1153 <mock_wait_for_call_num_higher_than+0x23>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mock_wait_for_call_num_higher_than>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r12d
mov    %esi,%r14d
mov    %rdi,%r15
xor    %ebx,%ebx
xor    %edi,%edi
call   1040 <time@plt>
test   %r12d,%r12d
jle    1189 <mock_wait_for_call_num_higher_than+0x59>
mov    %rax,%rbp
movslq %r12d,%rax
add    %rax,%rbp
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1030 <mock_calls@plt>
cmp    %r14d,%eax
jg     1187 <mock_wait_for_call_num_higher_than+0x57>
mov    $0x64,%edi
call   1050 <usleep@plt>
xor    %ebx,%ebx
xor    %edi,%edi
call   1040 <time@plt>
cmp    %rax,%rbp
jg     1160 <mock_wait_for_call_num_higher_than+0x30>
jmp    1189 <mock_wait_for_call_num_higher_than+0x59>
mov    %eax,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @mock_wait_for_call_num_higher_than(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%11 = call i64 @time(i32* null)
store i64 %11, i64* %9
store i64 %11, i64* %8
br label %12
12: ; preds = %27, %3
%13 = load i64, i64* %8
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = add nsw i64 %13, %15
%17 = load i64, i64* %9
%18 = icmp sgt i64 %16, %17
br i1 %18, label %19, label %30
19: ; preds = %12
%20 = load i8*, i8** %5
%21 = call i32 @mock_calls(i8* %20)
store i32 %21, i32* %10
%22 = load i32, i32* %10
%23 = load i32, i32* %6
%24 = icmp sgt i32 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = load i32, i32* %10
store i32 %26, i32* %4
br label %31
27: ; preds = %19
%28 = call i32 @usleep(i32 100)
%29 = call i64 @time(i32* null)
store i64 %29, i64* %9
br label %12
30: ; preds = %12
store i32 0, i32* %4
br label %31
31: ; preds = %30, %25
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
define i32 @mock_wait_for_call_num_higher_than(i8* %0, i32 %1, i32 %2) {
%4 = tail call i64 @time(i32* null)
%5 = sext i32 %2 to i64
%6 = add nsw i64 %4, %5
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %15
8: ; preds = %3, %11
%9 = tail call i32 @mock_calls(i8* %0)
%10 = icmp sgt i32 %9, %1
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = tail call i32 @usleep(i32 100)
%13 = tail call i64 @time(i32* null)
%14 = icmp sgt i64 %6, %13
br i1 %14, label %8, label %15
15: ; preds = %8, %11, %3
%16 = phi i32 [ 0, %3 ], [ 0, %11 ], [ %9, %8 ]
ret i32 %16
}