#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 strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int strtoul(char *, int /*<<< orphan*/ *, int);
unsigned long int get_seconds(char *code) {
  int length = strlen(code);
  if (length < 2) {
    return 0;
  }
  int multiplier = 0;
  char suffix = code[length - 1];
  switch (suffix) {
  case 's':
    multiplier = 1;
    break;
  case 'm':
    multiplier = 60;
    break;
  case 'h':
    multiplier = 3600;
    break;
  case 'D':
    multiplier = 86400;
    break;
  case 'M':
    multiplier = 2629746;
    break;
  case 'Y':
    multiplier = 31556940;
    break;
  default:
    return 0;
  }
  char value[length + 1];
  strncpy(value, code, length + 1);
  value[length - 1] = '\0';
  return strtoul(value, NULL, 10) * multiplier;
}


x86 assembly (clang, -O0):
<get_seconds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jge    115f <get_seconds+0x2f>
movq   $0x0,-0x8(%rbp)
jmp    125f <get_seconds+0x12f>
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0xffffffff,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
add    $0xffffffbc,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x2f,%eax
ja     11eb <get_seconds+0xbb>
mov    -0x38(%rbp),%rax
lea    0xe66(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0x18(%rbp)
jmp    11f8 <get_seconds+0xc8>
movl   $0x3c,-0x18(%rbp)
jmp    11f8 <get_seconds+0xc8>
movl   $0xe10,-0x18(%rbp)
jmp    11f8 <get_seconds+0xc8>
movl   $0x15180,-0x18(%rbp)
jmp    11f8 <get_seconds+0xc8>
movl   $0x282072,-0x18(%rbp)
jmp    11f8 <get_seconds+0xc8>
movl   $0x1e1854c,-0x18(%rbp)
jmp    11f8 <get_seconds+0xc8>
movq   $0x0,-0x8(%rbp)
jmp    125f <get_seconds+0x12f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,(%rdi,%rax,1)
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtoul@plt>
imul   -0x18(%rbp),%eax
cltq
mov    %rax,-0x8(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_seconds>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
cmp    $0x2,%eax
jge    1152 <get_seconds+0x22>
xor    %ecx,%ecx
jmp    11e9 <get_seconds+0xb9>
lea    -0x1(%rax),%r15d
movsbl (%r14,%r15,1),%edx
xor    %ecx,%ecx
add    $0xffffffbc,%edx
cmp    $0x2f,%edx
ja     11e9 <get_seconds+0xb9>
mov    $0x1,%r12d
lea    0xe8a(%rip),%rsi
movslq (%rsi,%rdx,4),%rdx
add    %rsi,%rdx
jmp    *%rdx
mov    $0x15180,%r12d
jmp    11a5 <get_seconds+0x75>
mov    $0x282072,%r12d
jmp    11a5 <get_seconds+0x75>
mov    $0x1e1854c,%r12d
jmp    11a5 <get_seconds+0x75>
mov    $0xe10,%r12d
jmp    11a5 <get_seconds+0x75>
mov    $0x3c,%r12d
mov    %rsp,%r13
mov    %eax,%ecx
add    $0x1,%eax
mov    %rsp,%rbx
add    $0x10,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%r15,%rbx,1)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtoul@plt>
imul   %r12d,%eax
movslq %eax,%rcx
mov    %r13,%rsp
mov    %rcx,%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i64 @get_seconds(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %14
13: ; preds = %1
store i64 0, i64* %2
br label %49
14: ; preds = %1
store i32 0, i32* %5
%15 = load i8*, i8** %3
%16 = load i32, i32* %4
%17 = sub nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %15, i64 %18
%20 = load i8, i8* %19
store i8 %20, i8* %6
%21 = load i8, i8* %6
%22 = sext i8 %21 to i32
switch i32 %22, label %29 [
i32 115, label %23
i32 109, label %24
i32 104, label %25
i32 68, label %26
i32 77, label %27
i32 89, label %28
]
23: ; preds = %14
store i32 1, i32* %5
br label %30
24: ; preds = %14
store i32 60, i32* %5
br label %30
25: ; preds = %14
store i32 3600, i32* %5
br label %30
26: ; preds = %14
store i32 86400, i32* %5
br label %30
27: ; preds = %14
store i32 2629746, i32* %5
br label %30
28: ; preds = %14
store i32 31556940, i32* %5
br label %30
29: ; preds = %14
store i64 0, i64* %2
br label %49
30: ; preds = %28, %27, %26, %25, %24, %23
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
%33 = zext i32 %32 to i64
%34 = call i8* @llvm.stacksave()
store i8* %34, i8** %7
%35 = alloca i8, i64 %33
store i64 %33, i64* %8
%36 = load i8*, i8** %3
%37 = load i32, i32* %4
%38 = add nsw i32 %37, 1
%39 = call i32 @strncpy(i8* %35, i8* %36, i32 %38)
%40 = load i32, i32* %4
%41 = sub nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %35, i64 %42
store i8 0, i8* %43
%44 = call i32 @strtoul(i8* %35, i32* null, i32 10)
%45 = load i32, i32* %5
%46 = mul nsw i32 %44, %45
%47 = sext i32 %46 to i64
store i64 %47, i64* %2
%48 = load i8*, i8** %7
br label %49
49: ; preds = %30, %29, %13
%50 = load i64, i64* %2
ret i64 %50
}

LLVM IR (-O2):
define i64 @get_seconds(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp slt i32 %2, 2
br i1 %3, label %26, label %4
4: ; preds = %1
%5 = add nsw i32 %2, -1
%6 = zext 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 %26 [
i32 115, label %15
i32 109, label %10
i32 104, label %11
i32 68, label %12
i32 77, label %13
i32 89, label %14
]
10: ; preds = %4
br label %15
11: ; preds = %4
br label %15
12: ; preds = %4
br label %15
13: ; preds = %4
br label %15
14: ; preds = %4
br label %15
15: ; preds = %4, %14, %13, %12, %11, %10
%16 = phi i32 [ 31556940, %14 ], [ 2629746, %13 ], [ 86400, %12 ], [ 3600, %11 ], [ 60, %10 ], [ 1, %4 ]
%17 = add nuw nsw i32 %2, 1
%18 = zext i32 %17 to i64
%19 = tail call i8* @llvm.stacksave()
%20 = alloca i8, i64 %18
%21 = call i32 @strncpy(i8* %20, i8* %0, i32 %17)
%22 = getelementptr inbounds i8, i8* %20, i64 %6
store i8 0, i8* %22
%23 = call i32 @strtoul(i8* nocapture %20, i32* null, i32 10)
%24 = mul nsw i32 %23, %16
%25 = sext i32 %24 to i64
br label %26
26: ; preds = %15, %4, %1
%27 = phi i64 [ 0, %1 ], [ %25, %15 ], [ 0, %4 ]
ret i64 %27
}