#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 */
int atoi(char *);
int strlen(char *);
int decipher_duration(char *duration) {
  int ret;
  char type;
  if (strlen(duration) < 2)
    return 0;
  type = duration[strlen(duration) - 1];
  if (type >= '0' && type <= '9')
    return atoi(duration);
  duration[strlen(duration) - 1] = '\0';
  ret = atoi(duration);
  if (ret <= 0)
    return 0;
  switch (type) {
  case 'w': {
    ret = (ret <= 250) ? ret * (86400 * 7) : 151200000;
    break;
  }
  case 'd': {
    ret = (ret <= 250 * 7) ? ret * 86400 : 151200000;
    break;
  }
  case 'h': {
    ret = (ret <= 250 * 7 * 3600) ? ret * 3600 : 151200000;
    break;
  }
  case 'm': {
    ret = (ret <= 151200000) ? ret * 60 : 151200000;
    break;
  }
  }
  return ret;
}


x86 assembly (clang, -O0):
<decipher_duration>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x2,%eax
jge    114a <decipher_duration+0x2a>
movl   $0x0,-0x4(%rbp)
jmp    12d3 <decipher_duration+0x1b3>
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
mov    (%rax,%rcx,1),%al
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%eax
cmp    $0x30,%eax
jl     1198 <decipher_duration+0x78>
movsbl -0x15(%rbp),%eax
cmp    $0x39,%eax
jg     1198 <decipher_duration+0x78>
mov    -0x10(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x4(%rbp)
jmp    12d3 <decipher_duration+0x1b3>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     11db <decipher_duration+0xbb>
movl   $0x0,-0x4(%rbp)
jmp    12d3 <decipher_duration+0x1b3>
movsbl -0x15(%rbp),%eax
add    $0xffffff9c,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x13,%eax
ja     12cd <decipher_duration+0x1ad>
mov    -0x30(%rbp),%rax
lea    0xe04(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
cmpl   $0xfa,-0x14(%rbp)
jg     1221 <decipher_duration+0x101>
imul   $0x93a80,-0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    122e <decipher_duration+0x10e>
mov    $0x9032100,%eax
mov    %eax,-0x34(%rbp)
jmp    122e <decipher_duration+0x10e>
mov    -0x34(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    12cd <decipher_duration+0x1ad>
cmpl   $0x6d6,-0x14(%rbp)
jg     1255 <decipher_duration+0x135>
imul   $0x15180,-0x14(%rbp),%eax
mov    %eax,-0x38(%rbp)
jmp    1262 <decipher_duration+0x142>
mov    $0x9032100,%eax
mov    %eax,-0x38(%rbp)
jmp    1262 <decipher_duration+0x142>
mov    -0x38(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    12cd <decipher_duration+0x1ad>
cmpl   $0x602160,-0x14(%rbp)
jg     1289 <decipher_duration+0x169>
imul   $0xe10,-0x14(%rbp),%eax
mov    %eax,-0x3c(%rbp)
jmp    1296 <decipher_duration+0x176>
mov    $0x9032100,%eax
mov    %eax,-0x3c(%rbp)
jmp    1296 <decipher_duration+0x176>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    12cd <decipher_duration+0x1ad>
cmpl   $0x9032100,-0x14(%rbp)
jg     12ba <decipher_duration+0x19a>
imul   $0x3c,-0x14(%rbp),%eax
mov    %eax,-0x40(%rbp)
jmp    12c7 <decipher_duration+0x1a7>
mov    $0x9032100,%eax
mov    %eax,-0x40(%rbp)
jmp    12c7 <decipher_duration+0x1a7>
mov    -0x40(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decipher_duration>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
xor    %r14d,%r14d
cmp    $0x2,%eax
jl     11c9 <decipher_duration+0xa9>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movsbl -0x1(%rax,%rbx,1),%ebp
lea    -0x30(%rbp),%eax
cmp    $0x9,%al
ja     115a <decipher_duration+0x3a>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <atoi@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
call   1040 <atoi@plt>
test   %eax,%eax
jle    11c9 <decipher_duration+0xa9>
mov    %eax,%r14d
add    $0xffffff9c,%ebp
cmp    $0x13,%ebp
ja     11c9 <decipher_duration+0xa9>
lea    0xe79(%rip),%rcx
movslq (%rcx,%rbp,4),%rdx
add    %rcx,%rdx
jmp    *%rdx
imul   $0x15180,%eax,%ecx
cmp    $0x6d7,%eax
jmp    11bf <decipher_duration+0x9f>
imul   $0xe10,%eax,%ecx
cmp    $0x602161,%eax
jmp    11bf <decipher_duration+0x9f>
imul   $0x3c,%eax,%ecx
cmp    $0x9032101,%eax
jmp    11bf <decipher_duration+0x9f>
imul   $0x93a80,%eax,%ecx
cmp    $0xfb,%eax
mov    $0x9032100,%r14d
cmovb  %ecx,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @decipher_duration(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 0, i32* %2
br label %81
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* %5
%18 = load i8, i8* %5
%19 = sext i8 %18 to i32
%20 = icmp sge i32 %19, 48
br i1 %20, label %21, label %28
21: ; preds = %10
%22 = load i8, i8* %5
%23 = sext i8 %22 to i32
%24 = icmp sle i32 %23, 57
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i8*, i8** %3
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %2
br label %81
28: ; preds = %21, %10
%29 = load i8*, i8** %3
%30 = load i8*, i8** %3
%31 = call i32 @strlen(i8* %30)
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %29, i64 %33
store i8 0, i8* %34
%35 = load i8*, i8** %3
%36 = call i32 @atoi(i8* %35)
store i32 %36, i32* %4
%37 = load i32, i32* %4
%38 = icmp sle i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %28
store i32 0, i32* %2
br label %81
40: ; preds = %28
%41 = load i8, i8* %5
%42 = sext i8 %41 to i32
switch i32 %42, label %79 [
i32 119, label %43
i32 100, label %52
i32 104, label %61
i32 109, label %70
]
43: ; preds = %40
%44 = load i32, i32* %4
%45 = icmp sle i32 %44, 250
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = load i32, i32* %4
%48 = mul nsw i32 %47, 604800
br label %50
49: ; preds = %43
br label %50
50: ; preds = %49, %46
%51 = phi i32 [ %48, %46 ], [ 151200000, %49 ]
store i32 %51, i32* %4
br label %79
52: ; preds = %40
%53 = load i32, i32* %4
%54 = icmp sle i32 %53, 1750
br i1 %54, label %55, label %58
55: ; preds = %52
%56 = load i32, i32* %4
%57 = mul nsw i32 %56, 86400
br label %59
58: ; preds = %52
br label %59
59: ; preds = %58, %55
%60 = phi i32 [ %57, %55 ], [ 151200000, %58 ]
store i32 %60, i32* %4
br label %79
61: ; preds = %40
%62 = load i32, i32* %4
%63 = icmp sle i32 %62, 6300000
br i1 %63, label %64, label %67
64: ; preds = %61
%65 = load i32, i32* %4
%66 = mul nsw i32 %65, 3600
br label %68
67: ; preds = %61
br label %68
68: ; preds = %67, %64
%69 = phi i32 [ %66, %64 ], [ 151200000, %67 ]
store i32 %69, i32* %4
br label %79
70: ; preds = %40
%71 = load i32, i32* %4
%72 = icmp sle i32 %71, 151200000
br i1 %72, label %73, label %76
73: ; preds = %70
%74 = load i32, i32* %4
%75 = mul nsw i32 %74, 60
br label %77
76: ; preds = %70
br label %77
77: ; preds = %76, %73
%78 = phi i32 [ %75, %73 ], [ 151200000, %76 ]
store i32 %78, i32* %4
br label %79
79: ; preds = %40, %77, %68, %59, %50
%80 = load i32, i32* %4
store i32 %80, i32* %2
br label %81
81: ; preds = %79, %39, %25, %9
%82 = load i32, i32* %2
ret i32 %82
}

LLVM IR (-O2):
define i32 @decipher_duration(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp slt i32 %2, 2
br i1 %3, label %39, label %4
4: ; preds = %1
%5 = tail call i32 @strlen(i8* %0)
%6 = add nsw i32 %5, -1
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = add i8 %9, -48
%12 = icmp ult i8 %11, 10
br i1 %12, label %13, label %15
13: ; preds = %4
%14 = tail call i32 @atoi(i8* %0)
br label %39
15: ; preds = %4
%16 = tail call i32 @strlen(i8* %0)
%17 = add nsw i32 %16, -1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %0, i64 %18
store i8 0, i8* %19
%20 = tail call i32 @atoi(i8* %0)
%21 = icmp slt i32 %20, 1
br i1 %21, label %39, label %22
22: ; preds = %15
switch i32 %10, label %39 [
i32 119, label %23
i32 100, label %27
i32 104, label %31
i32 109, label %35
]
23: ; preds = %22
%24 = icmp ult i32 %20, 251
%25 = mul nsw i32 %20, 604800
%26 = select i1 %24, i32 %25, i32 151200000
br label %39
27: ; preds = %22
%28 = icmp ult i32 %20, 1751
%29 = mul nsw i32 %20, 86400
%30 = select i1 %28, i32 %29, i32 151200000
br label %39
31: ; preds = %22
%32 = icmp ult i32 %20, 6300001
%33 = mul nsw i32 %20, 3600
%34 = select i1 %32, i32 %33, i32 151200000
br label %39
35: ; preds = %22
%36 = mul nsw i32 %20, 60
%37 = icmp ugt i32 %20, 151200000
%38 = select i1 %37, i32 151200000, i32 %36
br label %39
39: ; preds = %23, %27, %31, %35, %22, %15, %1, %13
%40 = phi i32 [ %14, %13 ], [ 0, %1 ], [ 0, %15 ], [ %20, %22 ], [ %38, %35 ], [ %34, %31 ], [ %30, %27 ], [ %26, %23 ]
ret i32 %40
}