#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 dummy;
};
typedef int /*<<< orphan*/ clockid_t;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ iun_err(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
struct timespec iun_timer(int *err_arg) {
  int err;
  struct timespec ts;
  clockid_t clock_id;
  clock_id = CLOCK_REALTIME;
  err = clock_gettime(clock_id, &ts);
  if (err && NULL == err_arg)
    iun_err("clock_gettime failed with: %s\n", strerror(errno));
  else if (NULL != err_arg)
    *err_arg = err;
  return ts;
}


x86 assembly (clang, -O0):
<iun_timer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e95(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     118e <iun_timer+0x5e>
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    118e <iun_timer+0x5e>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %eax,%esi
lea    0xe7c(%rip),%rdi
call   1040 <iun_err@plt>
jmp    11a8 <iun_timer+0x78>
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     11a3 <iun_timer+0x73>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    11a8 <iun_timer+0x78>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iun_timer>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x2e99(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1030 <clock_gettime@plt>
test   %rbx,%rbx
jne    1172 <iun_timer+0x42>
test   %eax,%eax
je     1172 <iun_timer+0x42>
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe97(%rip),%rdi
mov    %eax,%esi
call   1040 <iun_err@plt>
jmp    1179 <iun_timer+0x49>
test   %rbx,%rbx
je     1179 <iun_timer+0x49>
mov    %eax,(%rbx)
mov    0x8(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
@CLOCK_REALTIME = global i32 0
@.str = [31 x i8] c"clock_gettime failed with: %s\0A\00"
@errno = global i32 0
define i32 @iun_timer(i32* %0) {
%2 = alloca %struct.timespec
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
%6 = load i32, i32* @CLOCK_REALTIME
store i32 %6, i32* %5
%7 = load i32, i32* %5
%8 = call i32 @clock_gettime(i32 %7, %struct.timespec* %2)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %1
%12 = load i32*, i32** %3
%13 = icmp eq i32* null, %12
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i32, i32* @errno
%16 = call i32 @strerror(i32 %15)
%17 = call i32 @iun_err(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %16)
br label %25
18: ; preds = %11, %1
%19 = load i32*, i32** %3
%20 = icmp ne i32* null, %19
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i32, i32* %4
%23 = load i32*, i32** %3
store i32 %22, i32* %23
br label %24
24: ; preds = %21, %18
br label %25
25: ; preds = %24, %14
%26 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%27 = load i32, i32* %26
ret i32 %27
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@CLOCK_REALTIME = global i32 0
@.str = [31 x i8] c"clock_gettime failed with: %s\0A\00"
@errno = global i32 0
define i32 @iun_timer(i32* writeonly %0) {
%2 = alloca %struct.timespec
%3 = load i32, i32* @CLOCK_REALTIME
%4 = call i32 @clock_gettime(i32 %3, %struct.timespec* %2)
%5 = icmp ne i32 %4, 0
%6 = icmp eq i32* %0, null
%7 = and i1 %6, %5
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load i32, i32* @errno
%10 = call i32 @strerror(i32 %9)
%11 = call i32 @iun_err(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %14
12: ; preds = %1
br i1 %6, label %14, label %13
13: ; preds = %12
store i32 %4, i32* %0
br label %14
14: ; preds = %12, %13, %8
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%16 = load i32, i32* %15
ret i32 %16
}