#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 {
  unsigned long tv_nsec;
  int tv_sec;
};
typedef int clockid_t;

/* Variables and functions */
#define CLOCK_MONOTONIC 129
#define CLOCK_REALTIME 128
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ errno;
int clock_getres(clockid_t clk_id, struct timespec *res) {
  switch (clk_id) {
  case CLOCK_REALTIME:
    res->tv_nsec = 0;
    res->tv_sec = 1;
    return 0;
  case CLOCK_MONOTONIC:
    res->tv_nsec = 100000000UL;
    res->tv_sec = 0;
    return 0;
  default:
    errno = EINVAL;
  }
  return -1;
}


x86 assembly (clang, -O0):
<clock_getres>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x80,%eax
je     1134 <clock_getres+0x34>
jmp    1121 <clock_getres+0x21>
mov    -0x14(%rbp),%eax
sub    $0x81,%eax
je     1156 <clock_getres+0x56>
jmp    1178 <clock_getres+0x78>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x1,0x8(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1191 <clock_getres+0x91>
mov    -0x10(%rbp),%rax
movq   $0x5f5e100,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,0x8(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1191 <clock_getres+0x91>
mov    0x2e59(%rip),%rax
mov    (%rax),%ecx
mov    0x2e58(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<clock_getres>:
cmp    $0x81,%edi
je     1121 <clock_getres+0x21>
cmp    $0x80,%edi
jne    1132 <clock_getres+0x32>
movq   $0x0,(%rsi)
movl   $0x1,0x8(%rsi)
xor    %eax,%eax
ret
movq   $0x5f5e100,(%rsi)
movl   $0x0,0x8(%rsi)
xor    %eax,%eax
ret
mov    0x2e9f(%rip),%rax
mov    (%rax),%eax
mov    0x2e9e(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i32 }
@EINVAL = global i32 0
@errno = global i32 0
define i32 @clock_getres(i32 %0, %struct.timespec* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.timespec*
store i32 %0, i32* %4
store %struct.timespec* %1, %struct.timespec** %5
%6 = load i32, i32* %4
switch i32 %6, label %17 [
i32 128, label %7
i32 129, label %12
]
7: ; preds = %2
%8 = load %struct.timespec*, %struct.timespec** %5
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i32 0, i32 0
store i64 0, i64* %9
%10 = load %struct.timespec*, %struct.timespec** %5
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %10, i32 0, i32 1
store i32 1, i32* %11
store i32 0, i32* %3
br label %20
12: ; preds = %2
%13 = load %struct.timespec*, %struct.timespec** %5
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %13, i32 0, i32 0
store i64 100000000, i64* %14
%15 = load %struct.timespec*, %struct.timespec** %5
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %15, i32 0, i32 1
store i32 0, i32* %16
store i32 0, i32* %3
br label %20
17: ; preds = %2
%18 = load i32, i32* @EINVAL
store i32 %18, i32* @errno
br label %19
19: ; preds = %17
store i32 -1, i32* %3
br label %20
20: ; preds = %19, %12, %7
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
%struct.timespec = type { i64, i32 }
@EINVAL = global i32 0
@errno = global i32 0
define i32 @clock_getres(i32 %0, %struct.timespec* nocapture writeonly %1) {
switch i32 %0, label %9 [
i32 128, label %3
i32 129, label %6
]
3: ; preds = %2
%4 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
store i64 0, i64* %4
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
store i32 1, i32* %5
br label %11
6: ; preds = %2
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
store i64 100000000, i64* %7
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
store i32 0, i32* %8
br label %11
9: ; preds = %2
%10 = load i32, i32* @EINVAL
store i32 %10, i32* @errno
br label %11
11: ; preds = %9, %6, %3
%12 = phi i32 [ -1, %9 ], [ 0, %6 ], [ 0, %3 ]
ret i32 %12
}