#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 int time_t;
struct timespec {
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ busywait_until(struct timespec *);
int /*<<< orphan*/ ts_plus(struct timespec *, struct timespec *, int);
int test_offset(time_t (*ask_time_func)(void *), void *ask_time_arg, int M,
                time_t *Tp, struct timespec *tsp) {
  struct timespec dts;
  time_t curT;
  ts_plus(&dts, tsp, M);
  busywait_until(&dts);
  curT = ask_time_func(ask_time_arg);
  tsp->tv_sec++;
  (*Tp)++;
  return curT >= 0 ? curT == *Tp - 1 : -1;
}


x86 assembly (clang, -O0):
<test_offset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    -0x30(%rbp),%rdi
call   1040 <ts_plus@plt>
lea    -0x30(%rbp),%rdi
call   1030 <busywait_until@plt>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rdi
call   *%rax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
cmpl   $0x0,-0x34(%rbp)
jl     119f <test_offset+0x7f>
mov    -0x34(%rbp),%eax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x38(%rbp)
jmp    11ac <test_offset+0x8c>
mov    $0xffffffff,%eax
mov    %eax,-0x38(%rbp)
jmp    11ac <test_offset+0x8c>
mov    -0x38(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_offset>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %r8,%rbx
mov    %rcx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
lea    0x8(%rsp),%r13
mov    %r13,%rdi
mov    %r8,%rsi
call   1040 <ts_plus@plt>
mov    %r13,%rdi
call   1030 <busywait_until@plt>
mov    %r15,%rdi
call   *%r12
addl   $0x1,(%rbx)
mov    (%r14),%ecx
lea    0x1(%rcx),%edx
mov    %edx,(%r14)
xor    %edx,%edx
cmp    %ecx,%eax
sete   %dl
test   %eax,%eax
mov    $0xffffffff,%eax
cmovns %edx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
define i32 @test_offset(i32 (i8*)* %0, i8* %1, i32 %2, i32* %3, %struct.timespec* %4) {
%6 = alloca i32 (i8*)*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca %struct.timespec*
%11 = alloca %struct.timespec
%12 = alloca i32
store i32 (i8*)* %0, i32 (i8*)** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32* %3, i32** %9
store %struct.timespec* %4, %struct.timespec** %10
%13 = load %struct.timespec*, %struct.timespec** %10
%14 = load i32, i32* %8
%15 = call i32 @ts_plus(%struct.timespec* %11, %struct.timespec* %13, i32 %14)
%16 = call i32 @busywait_until(%struct.timespec* %11)
%17 = load i32 (i8*)*, i32 (i8*)** %6
%18 = load i8*, i8** %7
%19 = call i32 %17(i8* %18)
store i32 %19, i32* %12
%20 = load %struct.timespec*, %struct.timespec** %10
%21 = getelementptr inbounds %struct.timespec, %struct.timespec* %20, i32 0, i32 0
%22 = load i32, i32* %21
%23 = add nsw i32 %22, 1
store i32 %23, i32* %21
%24 = load i32*, i32** %9
%25 = load i32, i32* %24
%26 = add nsw i32 %25, 1
store i32 %26, i32* %24
%27 = load i32, i32* %12
%28 = icmp sge i32 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %5
%30 = load i32, i32* %12
%31 = load i32*, i32** %9
%32 = load i32, i32* %31
%33 = sub nsw i32 %32, 1
%34 = icmp eq i32 %30, %33
%35 = zext i1 %34 to i32
br label %37
36: ; preds = %5
br label %37
37: ; preds = %36, %29
%38 = phi i32 [ %35, %29 ], [ -1, %36 ]
ret i32 %38
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
define i32 @test_offset(i32 (i8*)* nocapture %0, i8* %1, i32 %2, i32* nocapture %3, %struct.timespec* %4) {
%6 = alloca %struct.timespec
%7 = bitcast %struct.timespec* %6 to i8*
%8 = call i32 @ts_plus(%struct.timespec* %6, %struct.timespec* %4, i32 %2)
%9 = call i32 @busywait_until(%struct.timespec* %6)
%10 = call i32 %0(i8* %1)
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 0
%12 = load i32, i32* %11
%13 = add nsw i32 %12, 1
store i32 %13, i32* %11
%14 = load i32, i32* %3
%15 = add nsw i32 %14, 1
store i32 %15, i32* %3
%16 = icmp sgt i32 %10, -1
%17 = icmp eq i32 %10, %14
%18 = zext i1 %17 to i32
%19 = select i1 %16, i32 %18, i32 -1
ret i32 %19
}