#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 */
typedef int time_t;
struct timespec {
  int tv_sec;
  long tv_nsec;
};

/* Variables and functions */
int clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ interface_fatal(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
time_t rounded_time() {
  struct timespec exact_time;
  time_t curr_time;
  if (clock_gettime(0, &exact_time) == -1)
    interface_fatal("clock_gettime() failed: %s", strerror(errno));
  curr_time = exact_time.tv_sec;
  if (exact_time.tv_nsec > 500000000L)
    curr_time += 1;
  return curr_time;
}


x86 assembly (clang, -O0):
<rounded_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
xor    %edi,%edi
lea    -0x10(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0xffffffff,%eax
jne    1168 <rounded_time+0x38>
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %eax,%esi
lea    0xe9d(%rip),%rdi
call   1040 <interface_fatal@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpq   $0x1dcd6500,-0x8(%rbp)
1d
jle    1185 <rounded_time+0x55>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rounded_time>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rsi
xor    %edi,%edi
call   1030 <clock_gettime@plt>
cmp    $0xffffffff,%eax
jne    1161 <rounded_time+0x31>
mov    0x2e94(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xea6(%rip),%rdi
mov    %eax,%esi
call   1040 <interface_fatal@plt>
xor    %eax,%eax
cmpq   $0x1dcd6501,0x10(%rsp)
cd 1d
setge  %al
add    0x8(%rsp),%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@.str = [27 x i8] c"clock_gettime() failed: %s\00"
@errno = global i32 0
define i32 @rounded_time() {
%1 = alloca %struct.timespec
%2 = alloca i32
%3 = call i32 @clock_gettime(i32 0, %struct.timespec* %1)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = load i32, i32* @errno
%7 = call i32 @strerror(i32 %6)
%8 = call i32 @interface_fatal(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %9
9: ; preds = %5, %0
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 0
%11 = load i32, i32* %10
store i32 %11, i32* %2
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 1
%13 = load i64, i64* %12
%14 = icmp sgt i64 %13, 500000000
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = load i32, i32* %2
%17 = add nsw i32 %16, 1
store i32 %17, i32* %2
br label %18
18: ; preds = %15, %9
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
@.str = [27 x i8] c"clock_gettime() failed: %s\00"
@errno = global i32 0
define i32 @rounded_time() {
%1 = alloca %struct.timespec
%2 = bitcast %struct.timespec* %1 to i8*
%3 = call i32 @clock_gettime(i32 0, %struct.timespec* %1)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = load i32, i32* @errno
%7 = call i32 @strerror(i32 %6)
%8 = call i32 @interface_fatal(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %9
9: ; preds = %5, %0
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%13 = load i64, i64* %12
%14 = icmp sgt i64 %13, 500000000
%15 = zext i1 %14 to i32
%16 = add nsw i32 %11, %15
ret i32 %16
}