#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 */
size_t strlen(char const *);
long long strtoll(char const *, int /*<<< orphan*/ *, int);
long long string_to_microseconds(const char *str) {
  size_t len = strlen(str);
  long long val = strtoll(str, NULL, 10);
  if (!val)
    return -1;
  switch (str[len - 1]) {
  case 's':
    return 'm' == str[len - 2] ? val * 1000 : val * 1000 * (long long)1000;
  case 'm':
    return val * 60 * 1000 * (long long)1000;
  case 'h':
    return val * 60 * 60 * 1000 * (long long)1000;
  case 'd':
    return val * 24 * 60 * 60 * 1000 * (long long)1000;
  case 'w':
    return val * 7 * 24 * 60 * 60 * 1000 * (long long)1000;
  case 'y':
    return val * 52 * 7 * 24 * 60 * 60 * 1000 * (long long)1000;
  default:
    return val;
  }
}


x86 assembly (clang, -O0):
<string_to_microseconds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtoll@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1167 <string_to_microseconds+0x47>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    12a4 <string_to_microseconds+0x184>
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
movsbl -0x1(%rax,%rcx,1),%eax
add    $0xffffff9c,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x15,%eax
ja     129c <string_to_microseconds+0x17c>
mov    -0x28(%rbp),%rax
lea    0xe6f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x2,%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x6d,%eax
cmp    %ecx,%eax
jne    11c8 <string_to_microseconds+0xa8>
imul   $0x3e8,-0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    11db <string_to_microseconds+0xbb>
imul   $0x3e8,-0x20(%rbp),%rax
imul   $0x3e8,%rax,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12a4 <string_to_microseconds+0x184>
imul   $0x3c,-0x20(%rbp),%rax
imul   $0x3e8,%rax,%rax
imul   $0x3e8,%rax,%rax
mov    %rax,-0x8(%rbp)
jmp    12a4 <string_to_microseconds+0x184>
imul   $0x3c,-0x20(%rbp),%rax
imul   $0x3c,%rax,%rax
imul   $0x3e8,%rax,%rax
imul   $0x3e8,%rax,%rax
mov    %rax,-0x8(%rbp)
jmp    12a4 <string_to_microseconds+0x184>
imul   $0x18,-0x20(%rbp),%rax
imul   $0x3c,%rax,%rax
imul   $0x3c,%rax,%rax
imul   $0x3e8,%rax,%rax
imul   $0x3e8,%rax,%rax
mov    %rax,-0x8(%rbp)
jmp    12a4 <string_to_microseconds+0x184>
imul   $0x7,-0x20(%rbp),%rax
imul   $0x18,%rax,%rax
imul   $0x3c,%rax,%rax
imul   $0x3c,%rax,%rax
imul   $0x3e8,%rax,%rax
imul   $0x3e8,%rax,%rax
mov    %rax,-0x8(%rbp)
jmp    12a4 <string_to_microseconds+0x184>
imul   $0x34,-0x20(%rbp),%rax
imul   $0x7,%rax,%rax
imul   $0x18,%rax,%rax
imul   $0x3c,%rax,%rax
imul   $0x3c,%rax,%rax
imul   $0x3e8,%rax,%rax
imul   $0x3e8,%rax,%rax
mov    %rax,-0x8(%rbp)
jmp    12a4 <string_to_microseconds+0x184>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_to_microseconds>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rax,%r14
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtoll@plt>
test   %rax,%rax
je     116d <string_to_microseconds+0x4d>
movsbl -0x1(%r14,%rbx,1),%ecx
add    $0xffffff9c,%ecx
cmp    $0x15,%ecx
ja     11ba <string_to_microseconds+0x9a>
lea    0xea8(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
movabs $0x141dd76000,%rcx
jmp    11b6 <string_to_microseconds+0x96>
mov    $0xffffffffffffffff,%rax
jmp    11ba <string_to_microseconds+0x9a>
mov    $0xd693a400,%ecx
jmp    11b6 <string_to_microseconds+0x96>
imul   $0x3938700,%rax,%rax
jmp    11ba <string_to_microseconds+0x9a>
cmpb   $0x6d,-0x2(%r14,%rbx,1)
mov    $0x3e8,%ecx
mov    $0xf4240,%edx
cmove  %rcx,%rdx
imul   %rdx,%rax
jmp    11ba <string_to_microseconds+0x9a>
movabs $0x8cd0e3a000,%rcx
jmp    11b6 <string_to_microseconds+0x96>
movabs $0x1c9a6e3c8000,%rcx
imul   %rcx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @string_to_microseconds(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @strlen(i8* %6)
store i64 %7, i64* %4
%8 = load i8*, i8** %3
%9 = call i64 @strtoll(i8* %8, i32* null, i32 10)
store i64 %9, i64* %5
%10 = load i64, i64* %5
%11 = icmp ne i64 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %1
store i64 -1, i64* %2
br label %74
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = load i64, i64* %4
%16 = sub i64 %15, 1
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
switch i32 %19, label %72 [
i32 115, label %20
i32 109, label %37
i32 104, label %42
i32 100, label %48
i32 119, label %55
i32 121, label %63
]
20: ; preds = %13
%21 = load i8*, i8** %3
%22 = load i64, i64* %4
%23 = sub i64 %22, 2
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 109, %26
br i1 %27, label %28, label %31
28: ; preds = %20
%29 = load i64, i64* %5
%30 = mul nsw i64 %29, 1000
br label %35
31: ; preds = %20
%32 = load i64, i64* %5
%33 = mul nsw i64 %32, 1000
%34 = mul nsw i64 %33, 1000
br label %35
35: ; preds = %31, %28
%36 = phi i64 [ %30, %28 ], [ %34, %31 ]
store i64 %36, i64* %2
br label %74
37: ; preds = %13
%38 = load i64, i64* %5
%39 = mul nsw i64 %38, 60
%40 = mul nsw i64 %39, 1000
%41 = mul nsw i64 %40, 1000
store i64 %41, i64* %2
br label %74
42: ; preds = %13
%43 = load i64, i64* %5
%44 = mul nsw i64 %43, 60
%45 = mul nsw i64 %44, 60
%46 = mul nsw i64 %45, 1000
%47 = mul nsw i64 %46, 1000
store i64 %47, i64* %2
br label %74
48: ; preds = %13
%49 = load i64, i64* %5
%50 = mul nsw i64 %49, 24
%51 = mul nsw i64 %50, 60
%52 = mul nsw i64 %51, 60
%53 = mul nsw i64 %52, 1000
%54 = mul nsw i64 %53, 1000
store i64 %54, i64* %2
br label %74
55: ; preds = %13
%56 = load i64, i64* %5
%57 = mul nsw i64 %56, 7
%58 = mul nsw i64 %57, 24
%59 = mul nsw i64 %58, 60
%60 = mul nsw i64 %59, 60
%61 = mul nsw i64 %60, 1000
%62 = mul nsw i64 %61, 1000
store i64 %62, i64* %2
br label %74
63: ; preds = %13
%64 = load i64, i64* %5
%65 = mul nsw i64 %64, 52
%66 = mul nsw i64 %65, 7
%67 = mul nsw i64 %66, 24
%68 = mul nsw i64 %67, 60
%69 = mul nsw i64 %68, 60
%70 = mul nsw i64 %69, 1000
%71 = mul nsw i64 %70, 1000
store i64 %71, i64* %2
br label %74
72: ; preds = %13
%73 = load i64, i64* %5
store i64 %73, i64* %2
br label %74
74: ; preds = %72, %63, %55, %48, %42, %37, %35, %12
%75 = load i64, i64* %2
ret i64 %75
}

LLVM IR (-O2):
define i64 @string_to_microseconds(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = tail call i64 @strtoll(i8* nocapture %0, i32* null, i32 10)
%4 = icmp eq i64 %3, 0
br i1 %4, label %27, label %5
5: ; preds = %1
%6 = add i64 %2, -1
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
switch i32 %9, label %27 [
i32 115, label %10
i32 109, label %17
i32 104, label %19
i32 100, label %21
i32 119, label %23
i32 121, label %25
]
10: ; preds = %5
%11 = add i64 %2, -2
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 109
%15 = select i1 %14, i64 1000, i64 1000000
%16 = mul i64 %15, %3
br label %27
17: ; preds = %5
%18 = mul i64 %3, 60000000
br label %27
19: ; preds = %5
%20 = mul i64 %3, 3600000000
br label %27
21: ; preds = %5
%22 = mul i64 %3, 86400000000
br label %27
23: ; preds = %5
%24 = mul i64 %3, 604800000000
br label %27
25: ; preds = %5
%26 = mul i64 %3, 31449600000000
br label %27
27: ; preds = %5, %1, %25, %23, %21, %19, %17, %10
%28 = phi i64 [ %26, %25 ], [ %24, %23 ], [ %22, %21 ], [ %20, %19 ], [ %18, %17 ], [ %16, %10 ], [ -1, %1 ], [ %3, %5 ]
ret i64 %28
}