#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 */
typedef int /*<<< orphan*/ time_t;

/* Variables and functions */
int strlen(char *);
int /*<<< orphan*/ strtol(char *, char **, int);
time_t buf2time(char *s) {
  if (s == NULL) {
    return 0;
  }
  if (s[0] == '\0') {
    return 0;
  }
  if (s[strlen(s) - 1] == '\n') {
    s[strlen(s) - 1] = '\0';
  }
  return (time_t)strtol(s, (char **)NULL, 10);
}


x86 assembly (clang, -O0):
<buf2time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1143 <buf2time+0x23>
movl   $0x0,-0x4(%rbp)
jmp    11bf <buf2time+0x9f>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    115f <buf2time+0x3f>
movl   $0x0,-0x4(%rbp)
jmp    11bf <buf2time+0x9f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11aa <buf2time+0x8a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buf2time>:
push   %rbx
test   %rdi,%rdi
je     115e <buf2time+0x3e>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     115e <buf2time+0x3e>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    114e <buf2time+0x2e>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
pop    %rbx
jmp    1040 <strtol@plt>
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @buf2time(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %20, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %20, label %6
6: ; preds = %3
%7 = tail call i32 @strlen(i8* %0)
%8 = add nsw i32 %7, -1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 10
br i1 %12, label %13, label %18
13: ; preds = %6
%14 = tail call i32 @strlen(i8* %0)
%15 = add nsw i32 %14, -1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %0, i64 %16
store i8 0, i8* %17
br label %18
18: ; preds = %13, %6
%19 = tail call i32 @strtol(i8* nocapture %0, i8** null, i32 10)
br label %20
20: ; preds = %3, %1, %18
%21 = phi i32 [ %19, %18 ], [ 0, %1 ], [ 0, %3 ]
ret i32 %21
}