#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;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
scalar_t__ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ perror(char *);
int getBeforeTime(struct timespec *tpget) {
  if (clock_gettime(CLOCK_REALTIME, tpget) != 0) {
    perror("clock_gettime() did not return success\n");
    perror("clock may not be reset properly\n");
    return 2;
  }
  return 0;
}


x86 assembly (clang, -O0):
<getBeforeTime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2ead(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0x0,%rax
je     116c <getBeforeTime+0x4c>
lea    0xeb1(%rip),%rdi
call   1040 <perror@plt>
lea    0xecd(%rip),%rdi
call   1040 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1173 <getBeforeTime+0x53>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getBeforeTime>:
push   %rax
mov    %rdi,%rsi
mov    0x2eb5(%rip),%rax
mov    (%rax),%edi
call   1030 <clock_gettime@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    113e <getBeforeTime+0x1e>
pop    %rcx
ret
lea    0xebb(%rip),%rdi
call   1040 <perror@plt>
lea    0xed7(%rip),%rdi
call   1040 <perror@plt>
mov    $0x2,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
@CLOCK_REALTIME = global i32 0
@.str = [40 x i8] c"clock_gettime() did not return success\0A\00"
@.str.1 = [33 x i8] c"clock may not be reset properly\0A\00"
define i32 @getBeforeTime(%struct.timespec* %0) {
%2 = alloca i32
%3 = alloca %struct.timespec*
store %struct.timespec* %0, %struct.timespec** %3
%4 = load i32, i32* @CLOCK_REALTIME
%5 = load %struct.timespec*, %struct.timespec** %3
%6 = call i64 @clock_gettime(i32 %4, %struct.timespec* %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %2
br label %12
11: ; preds = %1
store i32 0, i32* %2
br label %12
12: ; preds = %11, %8
%13 = load i32, i32* %2
ret i32 %13
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@CLOCK_REALTIME = global i32 0
@.str = [40 x i8] c"clock_gettime() did not return success\0A\00"
@.str.1 = [33 x i8] c"clock may not be reset properly\0A\00"
define i32 @getBeforeTime(%struct.timespec* %0) {
%2 = load i32, i32* @CLOCK_REALTIME
%3 = tail call i64 @clock_gettime(i32 %2, %struct.timespec* %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = tail call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %1, %5
%9 = phi i32 [ 2, %5 ], [ 0, %1 ]
ret i32 %9
}