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

/* Variables and functions */
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *,
                            int /*<<< orphan*/, int /*<<< orphan*/);
const char *posix_timestamp(clockid_t clk_id, const char *s) {
  static char lbuf[100] = {'\0', '\0'};
  struct timespec tp;
  if (!clock_gettime(clk_id, &tp)) {
    snprintf(lbuf, sizeof(lbuf) - 1, "clock_gettime %s %02li.%09li", s,
             tp.tv_sec, tp.tv_nsec);
  }
  return lbuf;
}


x86 assembly (clang, -O0):
<posix_timestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0x0,%eax
jne    1168 <posix_timestamp+0x48>
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%r8d
mov    -0x18(%rbp),%r9d
lea    0x2ee9(%rip),%rdi
mov    $0x63,%esi
lea    0xe9d(%rip),%rdx
call   1040 <snprintf@plt>
lea    0x2ed1(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<posix_timestamp>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0x8(%rsp),%rsi
call   1030 <clock_gettime@plt>
test   %eax,%eax
jne    115b <posix_timestamp+0x3b>
mov    0x8(%rsp),%r9d
mov    0xc(%rsp),%r8d
lea    0x2ef9(%rip),%rdi
lea    0xeb2(%rip),%rdx
mov    $0x63,%esi
mov    %rbx,%rcx
call   1040 <snprintf@plt>
lea    0x2ede(%rip),%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@posix_timestamp.lbuf = internal global [100 x i8] zeroinitializer
@.str = [29 x i8] c"clock_gettime %s %02li.%09li\00"
define i8* @posix_timestamp(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.timespec
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = load i32, i32* %3
%7 = call i32 @clock_gettime(i32 %6, %struct.timespec* %5)
%8 = icmp ne i32 %7, 0
br i1 %8, label %16, label %9
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 1
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
%14 = load i32, i32* %13
%15 = call i32 @snprintf(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @posix_timestamp.lbuf, i64 0, i64 0), i32 99, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %10, i32 %12, i32 %14)
br label %16
16: ; preds = %9, %2
ret i8* getelementptr inbounds ([100 x i8], [100 x i8]* @posix_timestamp.lbuf, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@posix_timestamp.lbuf = internal global [100 x i8] zeroinitializer
@.str = [29 x i8] c"clock_gettime %s %02li.%09li\00"
define i8* @posix_timestamp(i32 %0, i8* %1) {
%3 = alloca %struct.timespec
%4 = bitcast %struct.timespec* %3 to i8*
%5 = call i32 @clock_gettime(i32 %0, %struct.timespec* %3)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %2
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
%9 = load i32, i32* %8
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%11 = load i32, i32* %10
%12 = call i32 @snprintf(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @posix_timestamp.lbuf, i64 0, i64 0), i32 99, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %9, i32 %11)
br label %13
13: ; preds = %7, %2
ret i8* getelementptr inbounds ([100 x i8], [100 x i8]* @posix_timestamp.lbuf, i64 0, i64 0)
}