#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 timespec {
  int tv_nsec;
};
struct SPDR_Clock {
  int dummy;
};
struct SPDR_Allocator {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
scalar_t__ clock_getres(int /*<<< orphan*/, struct timespec *);
int clock_init_base(struct SPDR_Clock **, struct SPDR_Allocator *, int, int);
extern int clock_init(struct SPDR_Clock **clockp,
                      struct SPDR_Allocator *allocator) {
  struct timespec res;
  if (clock_getres(CLOCK_MONOTONIC, &res) != 0 || res.tv_nsec > 1000) {
    return -1;
  }
  return clock_init_base(clockp, allocator, 1, 1000);
}


x86 assembly (clang, -O0):
<clock_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2eb1(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1040 <clock_getres@plt>
cmp    $0x0,%rax
jne    1159 <clock_init+0x39>
cmpl   $0x3e8,-0x20(%rbp)
jle    1165 <clock_init+0x45>
movl   $0xffffffff,-0x4(%rbp)
jmp    117f <clock_init+0x5f>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x1,%edx
mov    $0x3e8,%ecx
call   1030 <clock_init_base@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clock_init>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2eb7(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1040 <clock_getres@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    1166 <clock_init+0x46>
cmpl   $0x3e8,(%rsp)
jg     1166 <clock_init+0x46>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
mov    $0x3e8,%ecx
call   1030 <clock_init_base@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.SPDR_Clock = type { i32 }
%struct.SPDR_Allocator = type { i32 }
%struct.timespec = type { i32 }
@CLOCK_MONOTONIC = global i32 0
define i32 @clock_init(%struct.SPDR_Clock** %0, %struct.SPDR_Allocator* %1) {
%3 = alloca i32
%4 = alloca %struct.SPDR_Clock**
%5 = alloca %struct.SPDR_Allocator*
%6 = alloca %struct.timespec
store %struct.SPDR_Clock** %0, %struct.SPDR_Clock*** %4
store %struct.SPDR_Allocator* %1, %struct.SPDR_Allocator** %5
%7 = load i32, i32* @CLOCK_MONOTONIC
%8 = call i64 @clock_getres(i32 %7, %struct.timespec* %6)
%9 = icmp ne i64 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
%12 = load i32, i32* %11
%13 = icmp sgt i32 %12, 1000
br i1 %13, label %14, label %15
14: ; preds = %10, %2
store i32 -1, i32* %3
br label %19
15: ; preds = %10
%16 = load %struct.SPDR_Clock**, %struct.SPDR_Clock*** %4
%17 = load %struct.SPDR_Allocator*, %struct.SPDR_Allocator** %5
%18 = call i32 @clock_init_base(%struct.SPDR_Clock** %16, %struct.SPDR_Allocator* %17, i32 1, i32 1000)
store i32 %18, i32* %3
br label %19
19: ; preds = %15, %14
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
%struct.SPDR_Clock = type { i32 }
%struct.SPDR_Allocator = type { i32 }
%struct.timespec = type { i32 }
@CLOCK_MONOTONIC = global i32 0
define i32 @clock_init(%struct.SPDR_Clock** %0, %struct.SPDR_Allocator* %1) {
%3 = alloca %struct.timespec
%4 = bitcast %struct.timespec* %3 to i8*
%5 = load i32, i32* @CLOCK_MONOTONIC
%6 = call i64 @clock_getres(i32 %5, %struct.timespec* %3)
%7 = icmp ne i64 %6, 0
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%9 = load i32, i32* %8
%10 = icmp sgt i32 %9, 1000
%11 = select i1 %7, i1 true, i1 %10
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = call i32 @clock_init_base(%struct.SPDR_Clock** %0, %struct.SPDR_Allocator* %1, i32 1, i32 1000)
br label %14
14: ; preds = %2, %12
%15 = phi i32 [ %13, %12 ], [ -1, %2 ]
ret i32 %15
}