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

/* Variables and functions */
char *calloc(size_t, int);
int /*<<< orphan*/ free(char *);
size_t strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
unsigned long strtoul(char const *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int strtotimespec(const char *str, struct timespec *ts_p) {
  size_t len;
  char *sec_str;
  unsigned long sec = 0;
  unsigned long nsec = 0;
  len = strlen(str);
  if (len > 9) {
    sec_str = calloc((len - 9 + 1), sizeof(char));
    strncpy(sec_str, str, len - 9);
    sec = strtoul(sec_str, NULL, 0);
    if (sec > 0x7fffffff)
      return 1;
    free(sec_str);
    nsec = strtoul(str + len - 9, NULL, 0);
  } else {
    nsec = strtoul(str, NULL, 0);
  }
  ts_p->tv_sec = sec;
  ts_p->tv_nsec = nsec;
  return 0;
}


x86 assembly (clang, -O0):
<strtotimespec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x9,-0x20(%rbp)
jbe    120d <strtotimespec+0xbd>
mov    -0x20(%rbp),%rdi
sub    $0x9,%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
sub    $0x9,%rdx
call   1040 <strncpy@plt>
mov    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <strtoul@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x7fffffff,-0x30(%rbp)
7f
jbe    11e4 <strtotimespec+0x94>
movl   $0x1,-0x4(%rbp)
jmp    123e <strtotimespec+0xee>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
add    -0x20(%rbp),%rdi
add    $0xfffffffffffffff7,%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <strtoul@plt>
mov    %rax,-0x38(%rbp)
jmp    1220 <strtotimespec+0xd0>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <strtoul@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtotimespec>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1050 <strlen@plt>
cmp    $0xa,%rax
jb     11c0 <strtotimespec+0x70>
mov    %rax,%rbx
lea    -0x9(%rax),%r12
lea    -0x8(%rax),%rdi
mov    $0x1,%ebp
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <strncpy@plt>
mov    %r13,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <strtoul@plt>
cmp    $0x7fffffff,%rax
ja     11d8 <strtotimespec+0x88>
mov    %rax,%r12
mov    %r13,%rdi
call   1030 <free@plt>
lea    (%r15,%rbx,1),%rdi
add    $0xfffffffffffffff7,%rdi
jmp    11c6 <strtotimespec+0x76>
xor    %r12d,%r12d
mov    %r15,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <strtoul@plt>
mov    %r12,(%r14)
mov    %rax,0x8(%r14)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
define i32 @strtotimespec(i8* %0, %struct.timespec* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.timespec*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
store i8* %0, i8** %4
store %struct.timespec* %1, %struct.timespec** %5
store i64 0, i64* %8
store i64 0, i64* %9
%10 = load i8*, i8** %4
%11 = call i64 @strlen(i8* %10)
store i64 %11, i64* %6
%12 = load i64, i64* %6
%13 = icmp ugt i64 %12, 9
br i1 %13, label %14, label %37
14: ; preds = %2
%15 = load i64, i64* %6
%16 = sub i64 %15, 9
%17 = add i64 %16, 1
%18 = call i8* @calloc(i64 %17, i32 1)
store i8* %18, i8** %7
%19 = load i8*, i8** %7
%20 = load i8*, i8** %4
%21 = load i64, i64* %6
%22 = sub i64 %21, 9
%23 = call i32 @strncpy(i8* %19, i8* %20, i64 %22)
%24 = load i8*, i8** %7
%25 = call i64 @strtoul(i8* %24, i32* null, i32 0)
store i64 %25, i64* %8
%26 = load i64, i64* %8
%27 = icmp ugt i64 %26, 2147483647
br i1 %27, label %28, label %29
28: ; preds = %14
store i32 1, i32* %3
br label %47
29: ; preds = %14
%30 = load i8*, i8** %7
%31 = call i32 @free(i8* %30)
%32 = load i8*, i8** %4
%33 = load i64, i64* %6
%34 = getelementptr inbounds i8, i8* %32, i64 %33
%35 = getelementptr inbounds i8, i8* %34, i64 -9
%36 = call i64 @strtoul(i8* %35, i32* null, i32 0)
store i64 %36, i64* %9
br label %40
37: ; preds = %2
%38 = load i8*, i8** %4
%39 = call i64 @strtoul(i8* %38, i32* null, i32 0)
store i64 %39, i64* %9
br label %40
40: ; preds = %37, %29
%41 = load i64, i64* %8
%42 = load %struct.timespec*, %struct.timespec** %5
%43 = getelementptr inbounds %struct.timespec, %struct.timespec* %42, i32 0, i32 0
store i64 %41, i64* %43
%44 = load i64, i64* %9
%45 = load %struct.timespec*, %struct.timespec** %5
%46 = getelementptr inbounds %struct.timespec, %struct.timespec* %45, i32 0, i32 1
store i64 %44, i64* %46
store i32 0, i32* %3
br label %47
47: ; preds = %40, %28
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
define i32 @strtotimespec(i8* %0, %struct.timespec* nocapture writeonly %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = icmp ugt i64 %3, 9
br i1 %4, label %5, label %17
5: ; preds = %2
%6 = add i64 %3, -9
%7 = add i64 %3, -8
%8 = tail call i8* @calloc(i64 %7, i32 1)
%9 = tail call i32 @strncpy(i8* %8, i8* %0, i64 %6)
%10 = tail call i64 @strtoul(i8* nocapture %8, i32* null, i32 0)
%11 = icmp ugt i64 %10, 2147483647
br i1 %11, label %24, label %12
12: ; preds = %5
%13 = tail call i32 @free(i8* %8)
%14 = getelementptr inbounds i8, i8* %0, i64 %3
%15 = getelementptr inbounds i8, i8* %14, i64 -9
%16 = tail call i64 @strtoul(i8* nocapture %15, i32* null, i32 0)
br label %19
17: ; preds = %2
%18 = tail call i64 @strtoul(i8* nocapture %0, i32* null, i32 0)
br label %19
19: ; preds = %17, %12
%20 = phi i64 [ %10, %12 ], [ 0, %17 ]
%21 = phi i64 [ %16, %12 ], [ %18, %17 ]
%22 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
store i64 %20, i64* %22
%23 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
store i64 %21, i64* %23
br label %24
24: ; preds = %5, %19
%25 = phi i32 [ 0, %19 ], [ 1, %5 ]
ret i32 %25
}