#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 uint32_t;

/* Variables and functions */
int strlen(char const *);
long strtol(char const *, int /*<<< orphan*/ *, int);
uint32_t parse_time(const char *timeval) {
  if (!timeval) {
    return 0;
  }
  char suffix = timeval[strlen(timeval) - 1];
  uint32_t m;
  switch (suffix) {
  case 'y':
    m = (uint32_t)(365.25 * 24 * 60 * 60);
    break;
  case 'M':
    m = 30 * 24 * 60 * 60;
    break;
  case 'w':
    m = 7 * 24 * 60 * 60;
    break;
  case 'd':
    m = 24 * 60 * 60;
    break;
  case 'h':
    m = 60 * 60;
    break;
  case 'm':
    m = 60;
    break;
  case 's':
    m = 1;
    break;
  default:
    m = 60 * 60;
  }
  long result = strtol(timeval, NULL, 10);
  if (result < 0) {
    return 0;
  }
  return (uint32_t)result * m;
}


x86 assembly (clang, -O0):
<parse_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1143 <parse_time+0x23>
movl   $0x0,-0x4(%rbp)
jmp    121f <parse_time+0xff>
mov    -0x10(%rbp),%rdi
mov    %rdi,-0x30(%rbp)
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
add    $0xffffffff,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
add    $0xffffffb3,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x2c,%eax
ja     11e0 <parse_time+0xc0>
mov    -0x28(%rbp),%rax
lea    0xe7d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1e187e0,-0x18(%rbp)
jmp    11e7 <parse_time+0xc7>
movl   $0x278d00,-0x18(%rbp)
jmp    11e7 <parse_time+0xc7>
movl   $0x93a80,-0x18(%rbp)
jmp    11e7 <parse_time+0xc7>
movl   $0x15180,-0x18(%rbp)
jmp    11e7 <parse_time+0xc7>
movl   $0xe10,-0x18(%rbp)
jmp    11e7 <parse_time+0xc7>
movl   $0x3c,-0x18(%rbp)
jmp    11e7 <parse_time+0xc7>
movl   $0x1,-0x18(%rbp)
jmp    11e7 <parse_time+0xc7>
movl   $0xe10,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    1214 <parse_time+0xf4>
movl   $0x0,-0x4(%rbp)
jmp    121f <parse_time+0xff>
mov    -0x20(%rbp),%rax
imul   -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_time>:
test   %rdi,%rdi
je     115c <parse_time+0x3c>
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
movsbl -0x1(%rax,%rbx,1),%eax
add    $0xffffffb3,%eax
cmp    $0x2c,%eax
ja     1155 <parse_time+0x35>
mov    $0x1e187e0,%ebp
lea    0xeb4(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0xe10,%ebp
jmp    1180 <parse_time+0x60>
xor    %eax,%eax
ret
mov    $0x278d00,%ebp
jmp    1180 <parse_time+0x60>
mov    $0x15180,%ebp
jmp    1180 <parse_time+0x60>
mov    $0x3c,%ebp
jmp    1180 <parse_time+0x60>
mov    $0x1,%ebp
jmp    1180 <parse_time+0x60>
mov    $0x93a80,%ebp
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%rcx
imul   %ebp,%eax
test   %rcx,%rcx
cmovs  %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @parse_time(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32
%6 = alloca i64
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %1
store i32 0, i32* %2
br label %39
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = load i8*, i8** %3
%13 = call i32 @strlen(i8* %12)
%14 = sub nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %11, i64 %15
%17 = load i8, i8* %16
store i8 %17, i8* %4
%18 = load i8, i8* %4
%19 = sext i8 %18 to i32
switch i32 %19, label %27 [
i32 121, label %20
i32 77, label %21
i32 119, label %22
i32 100, label %23
i32 104, label %24
i32 109, label %25
i32 115, label %26
]
20: ; preds = %10
store i32 31557600, i32* %5
br label %28
21: ; preds = %10
store i32 2592000, i32* %5
br label %28
22: ; preds = %10
store i32 604800, i32* %5
br label %28
23: ; preds = %10
store i32 86400, i32* %5
br label %28
24: ; preds = %10
store i32 3600, i32* %5
br label %28
25: ; preds = %10
store i32 60, i32* %5
br label %28
26: ; preds = %10
store i32 1, i32* %5
br label %28
27: ; preds = %10
store i32 3600, i32* %5
br label %28
28: ; preds = %27, %26, %25, %24, %23, %22, %21, %20
%29 = load i8*, i8** %3
%30 = call i64 @strtol(i8* %29, i32* null, i32 10)
store i64 %30, i64* %6
%31 = load i64, i64* %6
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %28
store i32 0, i32* %2
br label %39
34: ; preds = %28
%35 = load i64, i64* %6
%36 = trunc i64 %35 to i32
%37 = load i32, i32* %5
%38 = mul nsw i32 %36, %37
store i32 %38, i32* %2
br label %39
39: ; preds = %34, %33, %9
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
define i32 @parse_time(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %24, label %3
3: ; preds = %1
%4 = tail call i32 @strlen(i8* %0)
%5 = add nsw i32 %4, -1
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
switch i32 %9, label %16 [
i32 121, label %17
i32 77, label %10
i32 119, label %11
i32 100, label %12
i32 104, label %13
i32 109, label %14
i32 115, label %15
]
10: ; preds = %3
br label %17
11: ; preds = %3
br label %17
12: ; preds = %3
br label %17
13: ; preds = %3
br label %17
14: ; preds = %3
br label %17
15: ; preds = %3
br label %17
16: ; preds = %3
br label %17
17: ; preds = %3, %16, %15, %14, %13, %12, %11, %10
%18 = phi i32 [ 3600, %16 ], [ 1, %15 ], [ 60, %14 ], [ 3600, %13 ], [ 86400, %12 ], [ 604800, %11 ], [ 2592000, %10 ], [ 31557600, %3 ]
%19 = tail call i64 @strtol(i8* nocapture %0, i32* null, i32 10)
%20 = icmp slt i64 %19, 0
%21 = trunc i64 %19 to i32
%22 = mul nsw i32 %18, %21
%23 = select i1 %20, i32 0, i32 %22
br label %24
24: ; preds = %1, %17
%25 = phi i32 [ %23, %17 ], [ 0, %1 ]
ret i32 %25
}