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

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char *, long, long);
void show_duration(char *clock_string, struct timespec start,
                   struct timespec end) {
  long tv_sec = end.tv_sec - start.tv_sec;
  long tv_nsec = end.tv_nsec - start.tv_nsec;
  if (tv_nsec < 0) {
    tv_nsec += 1000000000;
    tv_sec -= 1;
  }
  printf("duration for %s %ld.%09ld seconds\n", clock_string, tv_sec, tv_nsec);
}


x86 assembly (clang, -O0):
<show_duration>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x8(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x18(%rbp)
mov    %rdi,-0x28(%rbp)
mov    -0x20(%rbp),%rax
sub    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
sub    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jge    1169 <show_duration+0x59>
mov    -0x38(%rbp),%rax
add    $0x3b9aca00,%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rcx
lea    0xe84(%rip),%rdi
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_duration>:
mov    %rdi,%r9
sub    %rsi,%rcx
sub    %rdx,%r8
lea    0x3b9aca00(%r8),%rax
mov    %r8,%rdx
sar    $0x3f,%rdx
add    %rcx,%rdx
test   %r8,%r8
cmovns %r8,%rax
lea    0xec8(%rip),%rdi
mov    %r9,%rsi
mov    %rax,%rcx
jmp    1030 <printf@plt>

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
@.str = [35 x i8] c"duration for %s %ld.%09ld seconds\0A\00"
define void @show_duration(i8* %0, i64 %1, i64 %2, i64 %3, i64 %4) {
%6 = alloca %struct.timespec
%7 = alloca %struct.timespec
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = bitcast %struct.timespec* %6 to { i64, i64 }*
%12 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %11, i32 0, i32 0
store i64 %1, i64* %12
%13 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %11, i32 0, i32 1
store i64 %2, i64* %13
%14 = bitcast %struct.timespec* %7 to { i64, i64 }*
%15 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %14, i32 0, i32 0
store i64 %3, i64* %15
%16 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %14, i32 0, i32 1
store i64 %4, i64* %16
store i8* %0, i8** %8
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%18 = load i64, i64* %17
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
%20 = load i64, i64* %19
%21 = sub nsw i64 %18, %20
store i64 %21, i64* %9
%22 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 1
%23 = load i64, i64* %22
%24 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 1
%25 = load i64, i64* %24
%26 = sub nsw i64 %23, %25
store i64 %26, i64* %10
%27 = load i64, i64* %10
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %5
%30 = load i64, i64* %10
%31 = add nsw i64 %30, 1000000000
store i64 %31, i64* %10
%32 = load i64, i64* %9
%33 = sub nsw i64 %32, 1
store i64 %33, i64* %9
br label %34
34: ; preds = %29, %5
%35 = load i8*, i8** %8
%36 = load i64, i64* %9
%37 = load i64, i64* %10
%38 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %35, i64 %36, i64 %37)
ret void
}

LLVM IR (-O2):
@.str = [35 x i8] c"duration for %s %ld.%09ld seconds\0A\00"
define void @show_duration(i8* %0, i64 %1, i64 %2, i64 %3, i64 %4) {
%6 = sub i64 %3, %1
%7 = sub nsw i64 %4, %2
%8 = icmp slt i64 %7, 0
%9 = add nsw i64 %7, 1000000000
%10 = ashr i64 %7, 63
%11 = add nsw i64 %6, %10
%12 = select i1 %8, i64 %9, i64 %7
%13 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %0, i64 %11, i64 %12)
ret void
}