#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 */
scalar_t__ EINVAL;
int clock_gettime(int, struct timespec *);
scalar_t__ errno;
int /*<<< orphan*/ printf(char *);
int main(void) {
  struct timespec tp;
  if (clock_gettime(9999, &tp) == -1) {
    if (EINVAL == errno) {
      printf("Test PASSED\n");
      return 0;
    } else {
      printf("errno not set to EINVAL\n");
      printf("Test FAILED\n");
      return 1;
    }
  } else {
    printf("clock_gettime() did not return failure\n");
    return 2;
  }
  printf("This code should not be executed.\n");
  return 2;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x270f,%edi
lea    -0x8(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0xffffffff,%eax
jne    119c <main+0x7c>
mov    0x2e8b(%rip),%rax
mov    (%rax),%rax
mov    0x2e89(%rip),%rcx
cmp    (%rcx),%rax
jne    1178 <main+0x58>
lea    0xe99(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11af <main+0x8f>
lea    0xe8e(%rip),%rdi
call   1040 <printf@plt>
lea    0xe9b(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11af <main+0x8f>
lea    0xe90(%rip),%rdi
call   1040 <printf@plt>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rsi
mov    $0x270f,%edi
call   1040 <clock_gettime@plt>
cmp    $0xffffffff,%eax
je     1147 <main+0x27>
mov    $0x2,%ebx
lea    0xebb(%rip),%rdi
jmp    1180 <main+0x60>
mov    0x2e8a(%rip),%rax
mov    (%rax),%rax
mov    0x2e88(%rip),%rcx
cmp    (%rcx),%rax
jne    1168 <main+0x48>
xor    %ebx,%ebx
lea    0xee5(%rip),%rdi
jmp    1180 <main+0x60>
lea    0xeb8(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
lea    0xebf(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
@EINVAL = global i64 0
@errno = global i64 0
@.str = [13 x i8] c"Test PASSED\0A\00"
@.str.1 = [25 x i8] c"errno not set to EINVAL\0A\00"
@.str.2 = [13 x i8] c"Test FAILED\0A\00"
@.str.3 = [40 x i8] c"clock_gettime() did not return failure\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timespec
store i32 0, i32* %1
%3 = call i32 @clock_gettime(i32 9999, %struct.timespec* %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %14
5: ; preds = %0
%6 = load i64, i64* @EINVAL
%7 = load i64, i64* @errno
%8 = icmp eq i64 %6, %7
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %16
11: ; preds = %5
%12 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %16
14: ; preds = %0
%15 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
store i32 2, i32* %1
br label %16
16: ; preds = %14, %11, %9
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@EINVAL = global i64 0
@errno = global i64 0
@str = [39 x i8] c"clock_gettime() did not return failure\00"
@str.4 = [24 x i8] c"errno not set to EINVAL\00"
@str.5 = [12 x i8] c"Test FAILED\00"
@str.6 = [12 x i8] c"Test PASSED\00"
define i32 @main() {
%1 = alloca %struct.timespec
%2 = bitcast %struct.timespec* %1 to i8*
%3 = call i32 @clock_gettime(i32 9999, %struct.timespec* %1)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %11
5: ; preds = %0
%6 = load i64, i64* @EINVAL
%7 = load i64, i64* @errno
%8 = icmp eq i64 %6, %7
br i1 %8, label %11, label %9
9: ; preds = %5
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.4, i64 0, i64 0))
br label %11
11: ; preds = %0, %5, %9
%12 = phi i8* [ getelementptr inbounds ([12 x i8], [12 x i8]* @str.5, i64 0, i64 0), %9 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @str.6, i64 0, i64 0), %5 ], [ getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0), %0 ]
%13 = phi i32 [ 1, %9 ], [ 0, %5 ], [ 2, %0 ]
%14 = call i32 @puts(i8* dereferenceable(1) %12)
ret i32 %13
}