#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 sscanf(char *, char *, int *, char *, char *);
int /*<<< orphan*/ zchar_tolower(char);
int zstr_to_second(char *s) {
  char unit, junk;
  int intval;
  switch (sscanf(s, "%d%c%c", &intval, &unit, &junk)) {
  case 1:
    unit = 's';
  case 2:
    if (intval < 0)
      return 0;
    switch (zchar_tolower(unit)) {
    case 'w':
      return (intval * (7 * 24 * 3600));
    case 'd':
      return (intval * (24 * 3600));
    case 'h':
      return (intval * 3600);
    case 'm':
      return (intval * 60);
    case 's':
    default:
      return (intval);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<zstr_to_second>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xf19(%rip),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x11(%rbp),%rcx
lea    -0x12(%rbp),%r8
call   1040 <sscanf@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
sub    $0x1,%eax
je     116c <zstr_to_second+0x4c>
jmp    115b <zstr_to_second+0x3b>
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
je     1170 <zstr_to_second+0x50>
jmp    11fe <zstr_to_second+0xde>
movb   $0x73,-0x11(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1186 <zstr_to_second+0x66>
movl   $0x0,-0x4(%rbp)
jmp    1205 <zstr_to_second+0xe5>
movsbl -0x11(%rbp),%edi
call   1030 <zchar_tolower@plt>
add    $0xffffff9c,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x13,%eax
ja     11f3 <zstr_to_second+0xd3>
mov    -0x28(%rbp),%rax
lea    0xe54(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
imul   $0x93a80,-0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1205 <zstr_to_second+0xe5>
imul   $0x15180,-0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1205 <zstr_to_second+0xe5>
imul   $0xe10,-0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1205 <zstr_to_second+0xe5>
imul   $0x3c,-0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1205 <zstr_to_second+0xe5>
jmp    11f3 <zstr_to_second+0xd3>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1205 <zstr_to_second+0xe5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zstr_to_second>:
sub    $0x18,%rsp
lea    0xf25(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0xf(%rsp),%rcx
lea    0x17(%rsp),%r8
call   1040 <sscanf@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x2,%ecx
je     1152 <zstr_to_second+0x32>
cmp    $0x1,%ecx
jne    118c <zstr_to_second+0x6c>
movb   $0x73,0xf(%rsp)
cmpl   $0x0,0x10(%rsp)
js     118c <zstr_to_second+0x6c>
movsbl 0xf(%rsp),%edi
call   1030 <zchar_tolower@plt>
add    $0xffffff9c,%eax
cmp    $0x13,%eax
ja     1188 <zstr_to_second+0x68>
lea    0xe8e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
imul   $0x15180,0x10(%rsp),%eax
add    $0x18,%rsp
ret
mov    0x10(%rsp),%eax
add    $0x18,%rsp
ret
imul   $0xe10,0x10(%rsp),%eax
add    $0x18,%rsp
ret
imul   $0x3c,0x10(%rsp),%eax
add    $0x18,%rsp
ret
imul   $0x93a80,0x10(%rsp),%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%d%c%c\00"
define i32 @zstr_to_second(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i8
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %6, i8* %4, i8* %5)
switch i32 %8, label %32 [
i32 1, label %9
i32 2, label %10
]
9: ; preds = %1
store i8 115, i8* %4
br label %10
10: ; preds = %1, %9
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %10
store i32 0, i32* %2
br label %33
14: ; preds = %10
%15 = load i8, i8* %4
%16 = call i32 @zchar_tolower(i8 signext %15)
switch i32 %16, label %30 [
i32 119, label %17
i32 100, label %20
i32 104, label %23
i32 109, label %26
i32 115, label %29
]
17: ; preds = %14
%18 = load i32, i32* %6
%19 = mul nsw i32 %18, 604800
store i32 %19, i32* %2
br label %33
20: ; preds = %14
%21 = load i32, i32* %6
%22 = mul nsw i32 %21, 86400
store i32 %22, i32* %2
br label %33
23: ; preds = %14
%24 = load i32, i32* %6
%25 = mul nsw i32 %24, 3600
store i32 %25, i32* %2
br label %33
26: ; preds = %14
%27 = load i32, i32* %6
%28 = mul nsw i32 %27, 60
store i32 %28, i32* %2
br label %33
29: ; preds = %14
br label %30
30: ; preds = %14, %29
%31 = load i32, i32* %6
store i32 %31, i32* %2
br label %33
32: ; preds = %1
store i32 0, i32* %2
br label %33
33: ; preds = %32, %30, %26, %23, %20, %17, %13
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
@.str = [7 x i8] c"%d%c%c\00"
define i32 @zstr_to_second(i8* nocapture %0) {
%2 = alloca i8
%3 = alloca i8
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %4, i8* %2, i8* %3)
switch i32 %6, label %28 [
i32 1, label %7
i32 2, label %8
]
7: ; preds = %1
store i8 115, i8* %2
br label %8
8: ; preds = %1, %7
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %28, label %11
11: ; preds = %8
%12 = load i8, i8* %2
%13 = call i32 @zchar_tolower(i8 signext %12)
switch i32 %13, label %26 [
i32 119, label %14
i32 100, label %17
i32 104, label %20
i32 109, label %23
]
14: ; preds = %11
%15 = load i32, i32* %4
%16 = mul nsw i32 %15, 604800
br label %28
17: ; preds = %11
%18 = load i32, i32* %4
%19 = mul nsw i32 %18, 86400
br label %28
20: ; preds = %11
%21 = load i32, i32* %4
%22 = mul nsw i32 %21, 3600
br label %28
23: ; preds = %11
%24 = load i32, i32* %4
%25 = mul nsw i32 %24, 60
br label %28
26: ; preds = %11
%27 = load i32, i32* %4
br label %28
28: ; preds = %1, %8, %26, %23, %20, %17, %14
%29 = phi i32 [ %27, %26 ], [ %25, %23 ], [ %22, %20 ], [ %19, %17 ], [ %16, %14 ], [ 0, %8 ], [ 0, %1 ]
ret i32 %29
}