#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;
};
struct tcb {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, unsigned long, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int umove(struct tcb *, long, struct timespec *);
int /*<<< orphan*/ verbose(struct tcb *);
void sprint_timespec(char *buf, struct tcb *tcp, long addr) {
  if (addr == 0)
    strcpy(buf, "NULL");
  else if (!verbose(tcp))
    sprintf(buf, "%#lx", addr);
  else {
    int rc;
    {
      struct timespec ts;
      if ((rc = umove(tcp, addr, &ts)) >= 0)
        sprintf(buf, "{%lu, %lu}", (unsigned long)ts.tv_sec,
                (unsigned long)ts.tv_nsec);
    }
    if (rc < 0)
      strcpy(buf, "{...}");
  }
}


x86 assembly (clang, -O0):
<sprint_timespec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1174 <sprint_timespec+0x34>
mov    -0x8(%rbp),%rdi
lea    0xe96(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11fc <sprint_timespec+0xbc>
mov    -0x10(%rbp),%rdi
call   1050 <verbose@plt>
cmp    $0x0,%eax
jne    11a1 <sprint_timespec+0x61>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe70(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
jmp    11f7 <sprint_timespec+0xb7>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1040 <umove@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jl     11d8 <sprint_timespec+0x98>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
lea    0xe39(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
cmpl   $0x0,-0x1c(%rbp)
jge    11f2 <sprint_timespec+0xb2>
mov    -0x8(%rbp),%rdi
lea    0xe28(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11f7 <sprint_timespec+0xb7>
jmp    11fc <sprint_timespec+0xbc>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sprint_timespec>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
test   %rdx,%rdx
je     1191 <sprint_timespec+0x51>
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rsi,%rdi
call   1050 <verbose@plt>
test   %eax,%eax
je     11a9 <sprint_timespec+0x69>
mov    %rsp,%rdx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <umove@plt>
test   %eax,%eax
js     11c6 <sprint_timespec+0x86>
mov    (%rsp),%rcx
mov    0x8(%rsp),%rdx
lea    0xe85(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <sprintf@plt>
jmp    11d5 <sprint_timespec+0x95>
lea    0xe68(%rip),%rsi
mov    %r14,%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <strcpy@plt>
lea    0xe55(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <sprintf@plt>
lea    0xe48(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tcb = type { i32 }
%struct.timespec = type { i64, i64 }
@.str = [5 x i8] c"NULL\00"
@.str.1 = [5 x i8] c"%#lx\00"
@.str.2 = [11 x i8] c"{%lu, %lu}\00"
@.str.3 = [6 x i8] c"{...}\00"
define void @sprint_timespec(i8* %0, %struct.tcb* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca %struct.tcb*
%6 = alloca i64
%7 = alloca i32
%8 = alloca %struct.timespec
store i8* %0, i8** %4
store %struct.tcb* %1, %struct.tcb** %5
store i64 %2, i64* %6
%9 = load i64, i64* %6
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i8*, i8** %4
%13 = call i32 @strcpy(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %42
14: ; preds = %3
%15 = load %struct.tcb*, %struct.tcb** %5
%16 = call i32 @verbose(%struct.tcb* %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %14
%19 = load i8*, i8** %4
%20 = load i64, i64* %6
%21 = call i32 (i8*, i8*, i64, ...) @sprintf(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %20)
br label %41
22: ; preds = %14
%23 = load %struct.tcb*, %struct.tcb** %5
%24 = load i64, i64* %6
%25 = call i32 @umove(%struct.tcb* %23, i64 %24, %struct.timespec* %8)
store i32 %25, i32* %7
%26 = icmp sge i32 %25, 0
br i1 %26, label %27, label %34
27: ; preds = %22
%28 = load i8*, i8** %4
%29 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i32 0, i32 1
%30 = load i64, i64* %29
%31 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i32 0, i32 0
%32 = load i64, i64* %31
%33 = call i32 (i8*, i8*, i64, ...) @sprintf(i8* %28, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64 %30, i64 %32)
br label %34
34: ; preds = %27, %22
%35 = load i32, i32* %7
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = load i8*, i8** %4
%39 = call i32 @strcpy(i8* %38, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %40
40: ; preds = %37, %34
br label %41
41: ; preds = %40, %18
br label %42
42: ; preds = %41, %11
ret void
}

LLVM IR (-O2):
%struct.tcb = type { i32 }
%struct.timespec = type { i64, i64 }
@.str = [5 x i8] c"NULL\00"
@.str.1 = [5 x i8] c"%#lx\00"
@.str.2 = [11 x i8] c"{%lu, %lu}\00"
@.str.3 = [6 x i8] c"{...}\00"
define void @sprint_timespec(i8* %0, %struct.tcb* %1, i64 %2) {
%4 = alloca %struct.timespec
%5 = icmp eq i64 %2, 0
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %25
8: ; preds = %3
%9 = tail call i32 @verbose(%struct.tcb* %1)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 (i8*, i8*, i64, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %2)
br label %25
13: ; preds = %8
%14 = bitcast %struct.timespec* %4 to i8*
%15 = call i32 @umove(%struct.tcb* %1, i64 %2, %struct.timespec* %4)
%16 = icmp sgt i32 %15, -1
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 1
%19 = load i64, i64* %18
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 0
%21 = load i64, i64* %20
%22 = call i32 (i8*, i8*, i64, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64 %19, i64 %21)
br label %25
23: ; preds = %13
%24 = call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %17, %23, %11, %6
ret void
}