#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 */
unsigned int strtoul(char const *, char **, int);
unsigned parse_duration(const char *s) {
  unsigned sec;
  char *p;
  sec = strtoul(s, &p, 10);
  if (*p == 0 || *p == 'm' || *p == 'M') {
    sec *= 60;
  } else if (*p == 'h' || *p == 'H') {
    sec *= 60 * 60;
  } else if (*p == 'd' || *p == 'D') {
    sec *= 60 * 60 * 24;
  }
  return sec;
}


x86 assembly (clang, -O0):
<parse_duration>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtoul@plt>
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1161 <parse_duration+0x51>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x6d,%eax
je     1161 <parse_duration+0x51>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x4d,%eax
jne    116d <parse_duration+0x5d>
imul   $0x3c,-0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    11d0 <parse_duration+0xc0>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x68,%eax
je     118d <parse_duration+0x7d>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x48,%eax
jne    119c <parse_duration+0x8c>
imul   $0xe10,-0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    11cb <parse_duration+0xbb>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x64,%eax
je     11bc <parse_duration+0xac>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x44,%eax
jne    11c6 <parse_duration+0xb6>
imul   $0x15180,-0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    11cb <parse_duration+0xbb>
jmp    11d0 <parse_duration+0xc0>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_duration>:
push   %rax
mov    %rsp,%rsi
mov    $0xa,%edx
call   1030 <strtoul@plt>
mov    (%rsp),%rcx
mov    (%rcx),%cl
lea    -0x44(%rcx),%edx
cmp    $0x29,%dl
ja     115f <parse_duration+0x4f>
movzbl %dl,%edx
movabs $0x100000001,%rsi
bt     %rdx,%rsi
jb     1168 <parse_duration+0x58>
movabs $0x1000000010,%rsi
bt     %rdx,%rsi
jb     1170 <parse_duration+0x60>
movabs $0x20000000200,%rsi
bt     %rdx,%rsi
jb     1163 <parse_duration+0x53>
test   %cl,%cl
jne    116e <parse_duration+0x5e>
imul   $0x3c,%eax,%eax
pop    %rcx
ret
imul   $0x15180,%eax,%eax
pop    %rcx
ret
imul   $0xe10,%eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @parse_duration(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strtoul(i8* %5, i8** %4, i32 10)
store i32 %6, i32* %3
%7 = load i8*, i8** %4
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 0
br i1 %10, label %21, label %11
11: ; preds = %1
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 109
br i1 %15, label %21, label %16
16: ; preds = %11
%17 = load i8*, i8** %4
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 77
br i1 %20, label %21, label %24
21: ; preds = %16, %11, %1
%22 = load i32, i32* %3
%23 = mul i32 %22, 60
store i32 %23, i32* %3
br label %52
24: ; preds = %16
%25 = load i8*, i8** %4
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 104
br i1 %28, label %34, label %29
29: ; preds = %24
%30 = load i8*, i8** %4
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 72
br i1 %33, label %34, label %37
34: ; preds = %29, %24
%35 = load i32, i32* %3
%36 = mul i32 %35, 3600
store i32 %36, i32* %3
br label %51
37: ; preds = %29
%38 = load i8*, i8** %4
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 100
br i1 %41, label %47, label %42
42: ; preds = %37
%43 = load i8*, i8** %4
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 68
br i1 %46, label %47, label %50
47: ; preds = %42, %37
%48 = load i32, i32* %3
%49 = mul i32 %48, 86400
store i32 %49, i32* %3
br label %50
50: ; preds = %47, %42
br label %51
51: ; preds = %50, %34
br label %52
52: ; preds = %51, %21
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
define i32 @parse_duration(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = call i32 @strtoul(i8* %0, i8** %2, i32 10)
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
switch i8 %6, label %13 [
i8 0, label %7
i8 109, label %7
i8 77, label %7
i8 104, label %9
i8 72, label %9
i8 100, label %11
i8 68, label %11
]
7: ; preds = %1, %1, %1
%8 = mul i32 %4, 60
br label %13
9: ; preds = %1, %1
%10 = mul i32 %4, 3600
br label %13
11: ; preds = %1, %1
%12 = mul i32 %4, 86400
br label %13
13: ; preds = %1, %9, %11, %7
%14 = phi i32 [ %8, %7 ], [ %10, %9 ], [ %12, %11 ], [ %4, %1 ]
ret i32 %14
}