#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 {
  scalar_t__ tv_nsec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
scalar_t__ labs(scalar_t__);
int /*<<< orphan*/ snprintf(char *, size_t, char *, char, long, long);
void timespec_str(const struct timespec *ts, char *buf, size_t buf_size) {
  char sign = ' ';
  if ((0 > ts->tv_nsec) || (0 > ts->tv_sec)) {
    sign = '-';
  }
  (void)snprintf(buf, buf_size, "%c%ld.%09ld", sign, (long)labs(ts->tv_sec),
                 (long)labs(ts->tv_nsec));
}


x86 assembly (clang, -O0):
<timespec_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movb   $0x20,-0x19(%rbp)
mov    -0x8(%rbp),%rcx
xor    %eax,%eax
cmp    (%rcx),%rax
jg     1157 <timespec_str+0x37>
mov    -0x8(%rbp),%rcx
xor    %eax,%eax
cmp    0x8(%rcx),%rax
jle    115b <timespec_str+0x3b>
movb   $0x2d,-0x19(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x19(%rbp),%al
mov    %al,-0x1a(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <labs@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <labs@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%r8
mov    %rax,%r9
mov    -0x1a(%rbp),%al
lea    0xe59(%rip),%rdx
movsbl %al,%ecx
call   1040 <snprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timespec_str>:
mov    (%rdi),%rax
mov    0x8(%rdi),%rcx
mov    %rcx,%r8
neg    %r8
cmovs  %rcx,%r8
mov    %rax,%r9
neg    %r9
cmovs  %rax,%r9
or     %rcx,%rax
mov    $0x2d,%eax
mov    $0x20,%ecx
cmovs  %eax,%ecx
lea    0xebe(%rip),%rax
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %rax,%rdx
jmp    1030 <snprintf@plt>

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
@.str = [12 x i8] c"%c%ld.%09ld\00"
define void @timespec_str(%struct.timespec* %0, i8* %1, i64 %2) {
%4 = alloca %struct.timespec*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8
store %struct.timespec* %0, %struct.timespec** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i8 32, i8* %7
%8 = load %struct.timespec*, %struct.timespec** %4
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i32 0, i32 0
%10 = load i64, i64* %9
%11 = icmp sgt i64 0, %10
br i1 %11, label %17, label %12
12: ; preds = %3
%13 = load %struct.timespec*, %struct.timespec** %4
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %13, i32 0, i32 1
%15 = load i64, i64* %14
%16 = icmp sgt i64 0, %15
br i1 %16, label %17, label %18
17: ; preds = %12, %3
store i8 45, i8* %7
br label %18
18: ; preds = %17, %12
%19 = load i8*, i8** %5
%20 = load i64, i64* %6
%21 = load i8, i8* %7
%22 = load %struct.timespec*, %struct.timespec** %4
%23 = getelementptr inbounds %struct.timespec, %struct.timespec* %22, i32 0, i32 1
%24 = load i64, i64* %23
%25 = call i64 @labs(i64 %24)
%26 = load %struct.timespec*, %struct.timespec** %4
%27 = getelementptr inbounds %struct.timespec, %struct.timespec* %26, i32 0, i32 0
%28 = load i64, i64* %27
%29 = call i64 @labs(i64 %28)
%30 = call i32 @snprintf(i8* %19, i64 %20, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8 signext %21, i64 %25, i64 %29)
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
@.str = [12 x i8] c"%c%ld.%09ld\00"
define void @timespec_str(%struct.timespec* nocapture %0, i8* %1, i64 %2) {
%4 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%5 = load i64, i64* %4
%6 = icmp slt i64 %5, 0
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%8 = load i64, i64* %7
%9 = icmp slt i64 %8, 0
%10 = select i1 %6, i1 true, i1 %9
%11 = select i1 %10, i8 45, i8 32
%12 = tail call i64 @llvm.abs.i64(i64 %8, i1 true)
%13 = tail call i64 @llvm.abs.i64(i64 %5, i1 true)
%14 = tail call i32 @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8 signext %11, i64 %12, i64 %13)
ret void
}