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

/* Variables and functions */
int EBT_LIMIT_SCALE;
int atoi(char const *);
char *strchr(char const *, char);
scalar_t__ strlen(char const *);
scalar_t__ strncasecmp(char const *, char *, scalar_t__);
int parse_rate(const char *rate, u_int32_t *val) {
  const char *delim;
  u_int32_t r;
  u_int32_t mult = 1;
  delim = strchr(rate, '/');
  if (delim) {
    if (strlen(delim + 1) == 0)
      return 0;
    if (strncasecmp(delim + 1, "second", strlen(delim + 1)) == 0)
      mult = 1;
    else if (strncasecmp(delim + 1, "minute", strlen(delim + 1)) == 0)
      mult = 60;
    else if (strncasecmp(delim + 1, "hour", strlen(delim + 1)) == 0)
      mult = 60 * 60;
    else if (strncasecmp(delim + 1, "day", strlen(delim + 1)) == 0)
      mult = 24 * 60 * 60;
    else
      return 0;
  }
  r = atoi(rate);
  if (!r)
    return 0;
  if (r / mult > EBT_LIMIT_SCALE)
    return 0;
  *val = EBT_LIMIT_SCALE * mult / r;
  return 1;
}


x86 assembly (clang, -O0):
<parse_rate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     12bf <parse_rate+0x17f>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
jne    1197 <parse_rate+0x57>
movl   $0x0,-0x4(%rbp)
jmp    1323 <parse_rate+0x1e3>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %rax,%rdx
lea    0xe42(%rip),%rsi
call   1050 <strncasecmp@plt>
cmp    $0x0,%rax
jne    11d9 <parse_rate+0x99>
movl   $0x1,-0x28(%rbp)
jmp    12ba <parse_rate+0x17a>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,%rdx
lea    0xe07(%rip),%rsi
call   1050 <strncasecmp@plt>
cmp    $0x0,%rax
jne    121b <parse_rate+0xdb>
movl   $0x3c,-0x28(%rbp)
jmp    12b5 <parse_rate+0x175>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1030 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    %rax,%rdx
lea    0xdcc(%rip),%rsi
call   1050 <strncasecmp@plt>
cmp    $0x0,%rax
jne    125d <parse_rate+0x11d>
movl   $0xe10,-0x28(%rbp)
jmp    12b0 <parse_rate+0x170>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1030 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    %rax,%rdx
lea    0xd8f(%rip),%rsi
call   1050 <strncasecmp@plt>
cmp    $0x0,%rax
jne    129f <parse_rate+0x15f>
movl   $0x15180,-0x28(%rbp)
jmp    12ab <parse_rate+0x16b>
movl   $0x0,-0x4(%rbp)
jmp    1323 <parse_rate+0x1e3>
jmp    12b0 <parse_rate+0x170>
jmp    12b5 <parse_rate+0x175>
jmp    12ba <parse_rate+0x17a>
jmp    12bf <parse_rate+0x17f>
mov    -0x10(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    12e1 <parse_rate+0x1a1>
movl   $0x0,-0x4(%rbp)
jmp    1323 <parse_rate+0x1e3>
mov    -0x24(%rbp),%eax
cltd
idivl  -0x28(%rbp)
mov    0x2cf9(%rip),%rcx
cmp    (%rcx),%eax
jle    1303 <parse_rate+0x1c3>
movl   $0x0,-0x4(%rbp)
jmp    1323 <parse_rate+0x1e3>
mov    0x2cde(%rip),%rax
mov    (%rax),%eax
imul   -0x28(%rbp),%eax
cltd
idivl  -0x24(%rbp)
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_rate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    $0x1,%r13d
test   %rax,%rax
je     11fa <parse_rate+0xba>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
xor    %r12d,%r12d
test   %rax,%rax
je     122e <parse_rate+0xee>
mov    %rax,%rbp
lea    0xe71(%rip),%rsi
mov    %rbx,%rdi
mov    %rax,%rdx
call   1050 <strncasecmp@plt>
test   %rax,%rax
je     11fa <parse_rate+0xba>
lea    0xe61(%rip),%rsi
mov    %rbx,%rdi
mov    %rbp,%rdx
call   1050 <strncasecmp@plt>
test   %rax,%rax
je     11ec <parse_rate+0xac>
lea    0xe51(%rip),%rsi
mov    %rbx,%rdi
mov    %rbp,%rdx
call   1050 <strncasecmp@plt>
test   %rax,%rax
je     11f4 <parse_rate+0xb4>
lea    0xe3f(%rip),%rsi
mov    %rbx,%rdi
mov    %rbp,%rdx
call   1050 <strncasecmp@plt>
test   %rax,%rax
jne    122e <parse_rate+0xee>
mov    $0x15180,%r13d
jmp    11fa <parse_rate+0xba>
mov    $0x3c,%r13d
jmp    11fa <parse_rate+0xba>
mov    $0xe10,%r13d
mov    %r15,%rdi
call   1060 <atoi@plt>
xor    %r12d,%r12d
test   %eax,%eax
je     122e <parse_rate+0xee>
mov    %eax,%ecx
cltd
idiv   %r13d
mov    %eax,%edx
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
cmp    %eax,%edx
jg     122e <parse_rate+0xee>
imul   %r13d,%eax
cltd
idiv   %ecx
mov    %eax,(%r14)
mov    $0x1,%r12d
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"second\00"
@.str.1 = [7 x i8] c"minute\00"
@.str.2 = [5 x i8] c"hour\00"
@.str.3 = [4 x i8] c"day\00"
@EBT_LIMIT_SCALE = global i32 0
define i32 @parse_rate(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 1, i32* %8
%9 = load i8*, i8** %4
%10 = call i8* @strchr(i8* %9, i8 signext 47)
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %60
13: ; preds = %2
%14 = load i8*, i8** %6
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = call i64 @strlen(i8* %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %13
store i32 0, i32* %3
br label %80
19: ; preds = %13
%20 = load i8*, i8** %6
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = load i8*, i8** %6
%23 = getelementptr inbounds i8, i8* %22, i64 1
%24 = call i64 @strlen(i8* %23)
%25 = call i64 @strncasecmp(i8* %21, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %19
store i32 1, i32* %8
br label %59
28: ; preds = %19
%29 = load i8*, i8** %6
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = load i8*, i8** %6
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = call i64 @strlen(i8* %32)
%34 = call i64 @strncasecmp(i8* %30, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %28
store i32 60, i32* %8
br label %58
37: ; preds = %28
%38 = load i8*, i8** %6
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = load i8*, i8** %6
%41 = getelementptr inbounds i8, i8* %40, i64 1
%42 = call i64 @strlen(i8* %41)
%43 = call i64 @strncasecmp(i8* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %42)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %37
store i32 3600, i32* %8
br label %57
46: ; preds = %37
%47 = load i8*, i8** %6
%48 = getelementptr inbounds i8, i8* %47, i64 1
%49 = load i8*, i8** %6
%50 = getelementptr inbounds i8, i8* %49, i64 1
%51 = call i64 @strlen(i8* %50)
%52 = call i64 @strncasecmp(i8* %48, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 %51)
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %46
store i32 86400, i32* %8
br label %56
55: ; preds = %46
store i32 0, i32* %3
br label %80
56: ; preds = %54
br label %57
57: ; preds = %56, %45
br label %58
58: ; preds = %57, %36
br label %59
59: ; preds = %58, %27
br label %60
60: ; preds = %59, %2
%61 = load i8*, i8** %4
%62 = call i32 @atoi(i8* %61)
store i32 %62, i32* %7
%63 = load i32, i32* %7
%64 = icmp ne i32 %63, 0
br i1 %64, label %66, label %65
65: ; preds = %60
store i32 0, i32* %3
br label %80
66: ; preds = %60
%67 = load i32, i32* %7
%68 = load i32, i32* %8
%69 = sdiv i32 %67, %68
%70 = load i32, i32* @EBT_LIMIT_SCALE
%71 = icmp sgt i32 %69, %70
br i1 %71, label %72, label %73
72: ; preds = %66
store i32 0, i32* %3
br label %80
73: ; preds = %66
%74 = load i32, i32* @EBT_LIMIT_SCALE
%75 = load i32, i32* %8
%76 = mul nsw i32 %74, %75
%77 = load i32, i32* %7
%78 = sdiv i32 %76, %77
%79 = load i32*, i32** %5
store i32 %78, i32* %79
store i32 1, i32* %3
br label %80
80: ; preds = %73, %72, %65, %55, %18
%81 = load i32, i32* %3
ret i32 %81
}

LLVM IR (-O2):
@.str = [7 x i8] c"second\00"
@.str.1 = [7 x i8] c"minute\00"
@.str.2 = [5 x i8] c"hour\00"
@.str.3 = [4 x i8] c"day\00"
@EBT_LIMIT_SCALE = global i32 0
define i32 @parse_rate(i8* %0, i32* nocapture writeonly %1) {
%3 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 47)
%4 = icmp eq i8* %3, null
br i1 %4, label %21, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %3, i64 1
%7 = tail call i64 @strlen(i8* %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %32, label %9
9: ; preds = %5
%10 = tail call i64 @strncasecmp(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %7)
%11 = icmp eq i64 %10, 0
br i1 %11, label %21, label %12
12: ; preds = %9
%13 = tail call i64 @strncasecmp(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 %7)
%14 = icmp eq i64 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %12
%16 = tail call i64 @strncasecmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %7)
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = tail call i64 @strncasecmp(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 %7)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %32
21: ; preds = %18, %15, %12, %9, %2
%22 = phi i32 [ 1, %2 ], [ 1, %9 ], [ 60, %12 ], [ 3600, %15 ], [ 86400, %18 ]
%23 = tail call i32 @atoi(i8* %0)
%24 = icmp eq i32 %23, 0
br i1 %24, label %32, label %25
25: ; preds = %21
%26 = sdiv i32 %23, %22
%27 = load i32, i32* @EBT_LIMIT_SCALE
%28 = icmp sgt i32 %26, %27
br i1 %28, label %32, label %29
29: ; preds = %25
%30 = mul nsw i32 %27, %22
%31 = sdiv i32 %30, %23
store i32 %31, i32* %1
br label %32
32: ; preds = %25, %21, %18, %5, %29
%33 = phi i32 [ 1, %29 ], [ 0, %5 ], [ 0, %18 ], [ 0, %21 ], [ 0, %25 ]
ret i32 %33
}