#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_sec;
};

/* Variables and functions */
struct timespec *calloc(int, int);
int /*<<< orphan*/ free(struct timespec *);
scalar_t__ strtol(char const *, char **, int);
struct timespec *parse_seconds(const char *s) {
  if (s == NULL) {
    return NULL;
  } else {
    char *n;
    struct timespec *t = calloc(sizeof *t, 1);
    if (t == NULL)
      return NULL;
    t->tv_sec = strtol(s, &n, 10);
    if (*n != '\0' || t->tv_sec <= 0) {
      free(t);
      t = NULL;
    }
    return t;
  }
}


x86 assembly (clang, -O0):
<parse_seconds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1154 <parse_seconds+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11d2 <parse_seconds+0xa2>
mov    $0x8,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    117f <parse_seconds+0x4f>
movq   $0x0,-0x8(%rbp)
jmp    11d2 <parse_seconds+0xa2>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11b9 <parse_seconds+0x89>
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jg     11ca <parse_seconds+0x9a>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_seconds>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     117c <parse_seconds+0x4c>
mov    %rdi,%rbx
mov    $0x8,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
test   %rax,%rax
je     117c <parse_seconds+0x4c>
mov    %rax,%r14
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,(%r14)
mov    (%rsp),%rcx
cmpb   $0x0,(%rcx)
jne    1174 <parse_seconds+0x44>
test   %rax,%rax
jg     117f <parse_seconds+0x4f>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timespec = type { i64 }
define %struct.timespec* @parse_seconds(i8* %0) {
%2 = alloca %struct.timespec*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.timespec*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
store %struct.timespec* null, %struct.timespec** %2
br label %33
9: ; preds = %1
%10 = call %struct.timespec* @calloc(i32 8, i32 1)
store %struct.timespec* %10, %struct.timespec** %5
%11 = load %struct.timespec*, %struct.timespec** %5
%12 = icmp eq %struct.timespec* %11, null
br i1 %12, label %13, label %14
13: ; preds = %9
store %struct.timespec* null, %struct.timespec** %2
br label %33
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = call i64 @strtol(i8* %15, i8** %4, i32 10)
%17 = load %struct.timespec*, %struct.timespec** %5
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %17, i32 0, i32 0
store i64 %16, i64* %18
%19 = load i8*, i8** %4
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %28, label %23
23: ; preds = %14
%24 = load %struct.timespec*, %struct.timespec** %5
%25 = getelementptr inbounds %struct.timespec, %struct.timespec* %24, i32 0, i32 0
%26 = load i64, i64* %25
%27 = icmp sle i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %23, %14
%29 = load %struct.timespec*, %struct.timespec** %5
%30 = call i32 @free(%struct.timespec* %29)
store %struct.timespec* null, %struct.timespec** %5
br label %31
31: ; preds = %28, %23
%32 = load %struct.timespec*, %struct.timespec** %5
store %struct.timespec* %32, %struct.timespec** %2
br label %33
33: ; preds = %31, %13, %8
%34 = load %struct.timespec*, %struct.timespec** %2
ret %struct.timespec* %34
}

LLVM IR (-O2):
%struct.timespec = type { i64 }
define noalias %struct.timespec* @parse_seconds(i8* %0) {
%2 = alloca i8*
%3 = icmp eq i8* %0, null
br i1 %3, label %20, label %4
4: ; preds = %1
%5 = bitcast i8** %2 to i8*
%6 = tail call %struct.timespec* @calloc(i32 8, i32 1)
%7 = icmp eq %struct.timespec* %6, null
br i1 %7, label %18, label %8
8: ; preds = %4
%9 = call i64 @strtol(i8* %0, i8** %2, i32 10)
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i64 0, i32 0
store i64 %9, i64* %10
%11 = load i8*, i8** %2
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
%14 = icmp slt i64 %9, 1
%15 = select i1 %13, i1 true, i1 %14
br i1 %15, label %16, label %18
16: ; preds = %8
%17 = tail call i32 @free(%struct.timespec* %6)
br label %18
18: ; preds = %16, %8, %4
%19 = phi %struct.timespec* [ null, %4 ], [ null, %16 ], [ %6, %8 ]
br label %20
20: ; preds = %1, %18
%21 = phi %struct.timespec* [ %19, %18 ], [ null, %1 ]
ret %struct.timespec* %21
}