#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 */

/* Variables and functions */
long EINVAL;
long ERANGE;
long LONG_MAX;
long my_strtol(char const *, char **, int, int *);
scalar_t__ strcmp(char *, char *);
long strtotime(const char *str) {
  int err;
  char *end;
  long x = my_strtol(str, &end, 10, &err);
  if (err > 0)
    return -err;
  if (x <= 0)
    return -ERANGE;
  long multiplier;
  if (strcmp(end, "s") == 0)
    multiplier = 1000000000;
  else if (strcmp(end, "ms") == 0)
    multiplier = 1000000;
  else if (strcmp(end, "us") == 0)
    multiplier = 1000;
  else if (strcmp(end, "ns") == 0 || strcmp(end, "") == 0)
    multiplier = 1;
  else
    return -EINVAL;
  if (x > LONG_MAX / multiplier)
    return -ERANGE;
  return x * multiplier;
}


x86 assembly (clang, -O0):
<strtotime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
lea    -0x14(%rbp),%rcx
call   1030 <my_strtol@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1160 <strtotime+0x40>
xor    %eax,%eax
sub    -0x14(%rbp),%eax
cltq
mov    %rax,-0x8(%rbp)
jmp    12a4 <strtotime+0x184>
cmpq   $0x0,-0x28(%rbp)
jg     1180 <strtotime+0x60>
xor    %eax,%eax
mov    0x2e74(%rip),%rcx
sub    (%rcx),%rax
mov    %rax,-0x8(%rbp)
jmp    12a4 <strtotime+0x184>
mov    -0x20(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11a7 <strtotime+0x87>
movq   $0x3b9aca00,-0x30(%rbp)
3b
jmp    125a <strtotime+0x13a>
mov    -0x20(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11ce <strtotime+0xae>
movq   $0xf4240,-0x30(%rbp)
jmp    1255 <strtotime+0x135>
mov    -0x20(%rbp),%rdi
lea    0xe2a(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11f5 <strtotime+0xd5>
movq   $0x3e8,-0x30(%rbp)
jmp    1250 <strtotime+0x130>
mov    -0x20(%rbp),%rdi
lea    0xe06(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     1229 <strtotime+0x109>
mov    -0x20(%rbp),%rdi
lea    0xde8(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1236 <strtotime+0x116>
movq   $0x1,-0x30(%rbp)
jmp    124b <strtotime+0x12b>
xor    %eax,%eax
mov    0x2d91(%rip),%rcx
sub    (%rcx),%rax
mov    %rax,-0x8(%rbp)
jmp    12a4 <strtotime+0x184>
jmp    1250 <strtotime+0x130>
jmp    1255 <strtotime+0x135>
jmp    125a <strtotime+0x13a>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2d6f(%rip),%rax
mov    (%rax),%rax
cqto
idivq  -0x30(%rbp)
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
jle    1297 <strtotime+0x177>
xor    %eax,%eax
mov    0x2d5d(%rip),%rcx
sub    (%rcx),%rax
mov    %rax,-0x8(%rbp)
jmp    12a4 <strtotime+0x184>
mov    -0x28(%rbp),%rax
imul   -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtotime>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0x8(%rsp),%rsi
lea    0x14(%rsp),%rcx
mov    $0xa,%edx
call   1030 <my_strtol@plt>
movslq 0x14(%rsp),%rbx
test   %rbx,%rbx
jle    114d <strtotime+0x2d>
neg    %rbx
jmp    1220 <strtotime+0x100>
mov    %rax,%r14
test   %rax,%rax
jle    1205 <strtotime+0xe5>
mov    0x8(%rsp),%rdi
lea    0xe9c(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11d5 <strtotime+0xb5>
mov    0x8(%rsp),%rdi
lea    0xe85(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11dc <strtotime+0xbc>
mov    0x8(%rsp),%rdi
lea    0xe72(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11e3 <strtotime+0xc3>
mov    0x8(%rsp),%rdi
lea    0xe5f(%rip),%rsi
call   1040 <strcmp@plt>
mov    $0x1,%ebx
test   %rax,%rax
je     11e8 <strtotime+0xc8>
mov    0x8(%rsp),%rdi
lea    0xe40(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11e8 <strtotime+0xc8>
mov    0x2dfd(%rip),%rax
jmp    120c <strtotime+0xec>
mov    $0x3b9aca00,%ebx
jmp    11e8 <strtotime+0xc8>
mov    $0xf4240,%ebx
jmp    11e8 <strtotime+0xc8>
mov    $0x3e8,%ebx
mov    0x2de9(%rip),%rax
mov    (%rax),%rax
mov    %rax,%rcx
shr    $0x20,%rcx
je     1213 <strtotime+0xf3>
cqto
idiv   %rbx
cmp    %rax,%r14
jle    121c <strtotime+0xfc>
mov    0x2ddc(%rip),%rax
xor    %ebx,%ebx
sub    (%rax),%rbx
jmp    1220 <strtotime+0x100>
xor    %edx,%edx
div    %ebx
cmp    %rax,%r14
jg     1205 <strtotime+0xe5>
imul   %r14,%rbx
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@ERANGE = global i64 0
@.str = [2 x i8] c"s\00"
@.str.1 = [3 x i8] c"ms\00"
@.str.2 = [3 x i8] c"us\00"
@.str.3 = [3 x i8] c"ns\00"
@.str.4 = [1 x i8] zeroinitializer
@EINVAL = global i64 0
@LONG_MAX = global i64 0
define i64 @strtotime(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i64 @my_strtol(i8* %8, i8** %5, i32 10, i32* %4)
store i64 %9, i64* %6
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %1
%13 = load i32, i32* %4
%14 = sub nsw i32 0, %13
%15 = sext i32 %14 to i64
store i64 %15, i64* %2
br label %65
16: ; preds = %1
%17 = load i64, i64* %6
%18 = icmp sle i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i64, i64* @ERANGE
%21 = sub nsw i64 0, %20
store i64 %21, i64* %2
br label %65
22: ; preds = %16
%23 = load i8*, i8** %5
%24 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %22
store i64 1000000000, i64* %7
br label %52
27: ; preds = %22
%28 = load i8*, i8** %5
%29 = call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %27
store i64 1000000, i64* %7
br label %51
32: ; preds = %27
%33 = load i8*, i8** %5
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %32
store i64 1000, i64* %7
br label %50
37: ; preds = %32
%38 = load i8*, i8** %5
%39 = call i64 @strcmp(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %45, label %41
41: ; preds = %37
%42 = load i8*, i8** %5
%43 = call i64 @strcmp(i8* %42, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %41, %37
store i64 1, i64* %7
br label %49
46: ; preds = %41
%47 = load i64, i64* @EINVAL
%48 = sub nsw i64 0, %47
store i64 %48, i64* %2
br label %65
49: ; preds = %45
br label %50
50: ; preds = %49, %36
br label %51
51: ; preds = %50, %31
br label %52
52: ; preds = %51, %26
%53 = load i64, i64* %6
%54 = load i64, i64* @LONG_MAX
%55 = load i64, i64* %7
%56 = sdiv i64 %54, %55
%57 = icmp sgt i64 %53, %56
br i1 %57, label %58, label %61
58: ; preds = %52
%59 = load i64, i64* @ERANGE
%60 = sub nsw i64 0, %59
store i64 %60, i64* %2
br label %65
61: ; preds = %52
%62 = load i64, i64* %6
%63 = load i64, i64* %7
%64 = mul nsw i64 %62, %63
store i64 %64, i64* %2
br label %65
65: ; preds = %61, %58, %46, %19, %12
%66 = load i64, i64* %2
ret i64 %66
}

LLVM IR (-O2):
@ERANGE = global i64 0
@.str = [2 x i8] c"s\00"
@.str.1 = [3 x i8] c"ms\00"
@.str.2 = [3 x i8] c"us\00"
@.str.3 = [3 x i8] c"ns\00"
@.str.4 = [1 x i8] zeroinitializer
@EINVAL = global i64 0
@LONG_MAX = global i64 0
define i64 @strtotime(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = bitcast i32* %2 to i8*
%5 = bitcast i8** %3 to i8*
%6 = call i64 @my_strtol(i8* %0, i8** %3, i32 10, i32* %2)
%7 = load i32, i32* %2
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = sub nsw i32 0, %7
%11 = sext i32 %10 to i64
br label %50
12: ; preds = %1
%13 = icmp slt i64 %6, 1
br i1 %13, label %14, label %17
14: ; preds = %12
%15 = load i64, i64* @ERANGE
%16 = sub nsw i64 0, %15
br label %50
17: ; preds = %12
%18 = load i8*, i8** %3
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %40, label %21
21: ; preds = %17
%22 = load i8*, i8** %3
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %40, label %25
25: ; preds = %21
%26 = load i8*, i8** %3
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %40, label %29
29: ; preds = %25
%30 = load i8*, i8** %3
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %40, label %33
33: ; preds = %29
%34 = load i8*, i8** %3
%35 = call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %40, label %37
37: ; preds = %33
%38 = load i64, i64* @EINVAL
%39 = sub nsw i64 0, %38
br label %50
40: ; preds = %29, %33, %25, %21, %17
%41 = phi i64 [ 1000000000, %17 ], [ 1000000, %21 ], [ 1000, %25 ], [ 1, %33 ], [ 1, %29 ]
%42 = load i64, i64* @LONG_MAX
%43 = sdiv i64 %42, %41
%44 = icmp sgt i64 %6, %43
br i1 %44, label %45, label %48
45: ; preds = %40
%46 = load i64, i64* @ERANGE
%47 = sub nsw i64 0, %46
br label %50
48: ; preds = %40
%49 = mul nsw i64 %41, %6
br label %50
50: ; preds = %37, %45, %48, %14, %9
%51 = phi i64 [ %11, %9 ], [ %16, %14 ], [ %47, %45 ], [ %49, %48 ], [ %39, %37 ]
ret i64 %51
}