#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int rm_so;
};
typedef TYPE_1__ regmatch_t;
typedef int /*<<< orphan*/ regex_t;
typedef int /*<<< orphan*/ errbuf;

/* Variables and functions */
int /*<<< orphan*/ REG_EXTENDED;
int REG_NOMATCH;
scalar_t__ atol(char const *);
int /*<<< orphan*/ err(char *, char const *, char const *, ...);
int regcomp(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ regerror(int, int /*<<< orphan*/ *, char *, int);
int regexec(int /*<<< orphan*/ *, char const *, int, TYPE_1__ *,
            int /*<<< orphan*/);
int parse_timespan(const char *str, int *r) {
  regex_t ex;
  int e;
  static const char *pattern = "^[[:space:]]*([0-9]+)([dhms]?)[[:space:]]*$";
  if ((e = regcomp(&ex, pattern, REG_EXTENDED)) != 0) {
    char errbuf[128];
    regerror(e, &ex, errbuf, sizeof(errbuf) - 1);
    errbuf[sizeof(errbuf) - 1] = '\0';
    err("regcomp(%s): %s\n", pattern, errbuf);
    return -1;
  }
  regmatch_t matches[3];
  if ((e = regexec(&ex, str, 3, matches, 0)) != 0) {
    char errbuf[128];
    regerror(e, &ex, errbuf, sizeof(errbuf) - 1);
    errbuf[sizeof(errbuf) - 1] = '\0';
    if (e != REG_NOMATCH)
      err("regexec: Couldn't match '%s' in '%s': %s\n", pattern, str, errbuf);
    return -1;
  }
  *r = (int)atol(str + matches[1].rm_so) *
       (matches[2].rm_so == -1             ? 1
        : *(str + matches[2].rm_so) == 'd' ? 86400
        : *(str + matches[2].rm_so) == 'h' ? 3600
        : *(str + matches[2].rm_so) == 'm' ? 60
                                           : 1);
  return 0;
}


x86 assembly (clang, -O0):
<parse_timespan>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2ede(%rip),%rsi
mov    0x2e67(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rdi
call   1030 <regcomp@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
je     11cc <parse_timespan+0x7c>
mov    -0x20(%rbp),%edi
lea    -0xa0(%rbp),%rdx
lea    -0x1c(%rbp),%rsi
mov    $0x7f,%ecx
call   1040 <regerror@plt>
movb   $0x0,-0x21(%rbp)
mov    0x2e9d(%rip),%rsi
lea    -0xa0(%rbp),%rdx
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1050 <err@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1330 <parse_timespan+0x1e0>
mov    -0x10(%rbp),%rsi
lea    -0xb0(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
mov    $0x3,%edx
xor    %r8d,%r8d
call   1060 <regexec@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
je     1251 <parse_timespan+0x101>
mov    -0x20(%rbp),%edi
lea    -0x130(%rbp),%rdx
lea    -0x1c(%rbp),%rsi
mov    $0x7f,%ecx
call   1040 <regerror@plt>
movb   $0x0,-0xb1(%rbp)
mov    -0x20(%rbp),%eax
mov    0x2dcb(%rip),%rcx
cmp    (%rcx),%eax
je     1245 <parse_timespan+0xf5>
mov    0x2e1c(%rip),%rsi
mov    -0x10(%rbp),%rdx
lea    -0x130(%rbp),%rcx
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1050 <err@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1330 <parse_timespan+0x1e0>
mov    -0x10(%rbp),%rdi
movslq -0xac(%rbp),%rax
add    %rax,%rdi
call   1070 <atol@plt>
mov    %eax,-0x134(%rbp)
cmpl   $0xffffffff,-0xa8(%rbp)
jne    1287 <parse_timespan+0x137>
mov    $0x1,%eax
mov    %eax,-0x138(%rbp)
jmp    1314 <parse_timespan+0x1c4>
mov    -0x10(%rbp),%rax
movslq -0xa8(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x64,%eax
jne    12af <parse_timespan+0x15f>
mov    $0x15180,%eax
mov    %eax,-0x13c(%rbp)
jmp    1308 <parse_timespan+0x1b8>
mov    -0x10(%rbp),%rax
movslq -0xa8(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x68,%eax
jne    12d7 <parse_timespan+0x187>
mov    $0xe10,%eax
mov    %eax,-0x140(%rbp)
jmp    12fc <parse_timespan+0x1ac>
mov    -0x10(%rbp),%rax
movslq -0xa8(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
mov    $0x1,%eax
mov    $0x3c,%ecx
cmp    $0x6d,%edx
cmove  %ecx,%eax
mov    %eax,-0x140(%rbp)
mov    -0x140(%rbp),%eax
mov    %eax,-0x13c(%rbp)
mov    -0x13c(%rbp),%eax
mov    %eax,-0x138(%rbp)
mov    -0x134(%rbp),%ecx
mov    -0x138(%rbp),%eax
imul   %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_timespan>:
push   %rbp
push   %r14
push   %rbx
sub    $0xa0,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e70(%rip),%rax
mov    (%rax),%edx
lea    0xe8f(%rip),%rsi
lea    0xc(%rsp),%rdi
call   1030 <regcomp@plt>
test   %eax,%eax
je     11c2 <parse_timespan+0x72>
lea    0xc(%rsp),%rsi
lea    0x20(%rsp),%rbx
mov    %eax,%edi
mov    %rbx,%rdx
mov    $0x7f,%ecx
call   1040 <regerror@plt>
movb   $0x0,0x9f(%rsp)
lea    0xe85(%rip),%rdi
lea    0xe52(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <err@plt>
mov    $0xffffffff,%eax
jmp    1281 <parse_timespan+0x131>
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rcx
mov    %rbx,%rsi
mov    $0x3,%edx
xor    %r8d,%r8d
call   1060 <regexec@plt>
test   %eax,%eax
je     122f <parse_timespan+0xdf>
mov    %eax,%ebp
lea    0xc(%rsp),%rsi
lea    0x20(%rsp),%rdx
mov    %eax,%edi
mov    $0x7f,%ecx
call   1040 <regerror@plt>
movb   $0x0,0x9f(%rsp)
mov    0x2de1(%rip),%rax
cmp    (%rax),%ebp
je     1228 <parse_timespan+0xd8>
lea    0xe2b(%rip),%rdi
lea    0xde7(%rip),%rsi
lea    0x20(%rsp),%rcx
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <err@plt>
mov    $0xffffffff,%eax
jmp    1281 <parse_timespan+0x131>
movslq 0x14(%rsp),%rdi
add    %rbx,%rdi
call   1070 <atol@plt>
movslq 0x18(%rsp),%rcx
cmp    $0xffffffffffffffff,%rcx
je     125b <parse_timespan+0x10b>
mov    (%rbx,%rcx,1),%cl
cmp    $0x64,%cl
je     1262 <parse_timespan+0x112>
cmp    $0x68,%cl
jne    1269 <parse_timespan+0x119>
mov    $0xe10,%ecx
jmp    1279 <parse_timespan+0x129>
mov    $0x1,%ecx
jmp    1279 <parse_timespan+0x129>
mov    $0x15180,%ecx
jmp    1279 <parse_timespan+0x129>
cmp    $0x6d,%cl
mov    $0x3c,%edx
mov    $0x1,%ecx
cmove  %edx,%ecx
imul   %eax,%ecx
mov    %ecx,(%r14)
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32 }
@parse_timespan.pattern = internal global i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i32 0, i32 0)
@.str = [44 x i8] c"^[[:space:]]*([0-9]+)([dhms]?)[[:space:]]*$\00"
@REG_EXTENDED = global i32 0
@.str.1 = [17 x i8] c"regcomp(%s): %s\0A\00"
@REG_NOMATCH = global i32 0
@.str.2 = [42 x i8] c"regexec: Couldn't match '%s' in '%s': %s\0A\00"
define i32 @parse_timespan(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [128 x i8]
%9 = alloca [3 x %struct.TYPE_3__]
%10 = alloca [128 x i8]
store i8* %0, i8** %4
store i32* %1, i32** %5
%11 = load i8*, i8** @parse_timespan.pattern
%12 = load i32, i32* @REG_EXTENDED
%13 = call i32 @regcomp(i32* %6, i8* %11, i32 %12)
store i32 %13, i32* %7
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %2
%16 = load i32, i32* %7
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%18 = call i32 @regerror(i32 %16, i32* %6, i8* %17, i32 127)
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 127
store i8 0, i8* %19
%20 = load i8*, i8** @parse_timespan.pattern
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%22 = call i32 (i8*, i8*, i8*, ...) @err(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %20, i8* %21)
store i32 -1, i32* %3
br label %98
23: ; preds = %2
%24 = load i8*, i8** %4
%25 = getelementptr inbounds [3 x %struct.TYPE_3__], [3 x %struct.TYPE_3__]* %9, i64 0, i64 0
%26 = call i32 @regexec(i32* %6, i8* %24, i32 3, %struct.TYPE_3__* %25, i32 0)
store i32 %26, i32* %7
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %42
28: ; preds = %23
%29 = load i32, i32* %7
%30 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%31 = call i32 @regerror(i32 %29, i32* %6, i8* %30, i32 127)
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 127
store i8 0, i8* %32
%33 = load i32, i32* %7
%34 = load i32, i32* @REG_NOMATCH
%35 = icmp ne i32 %33, %34
br i1 %35, label %36, label %41
36: ; preds = %28
%37 = load i8*, i8** @parse_timespan.pattern
%38 = load i8*, i8** %4
%39 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%40 = call i32 (i8*, i8*, i8*, ...) @err(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %37, i8* %38, i8* %39)
br label %41
41: ; preds = %36, %28
store i32 -1, i32* %3
br label %98
42: ; preds = %23
%43 = load i8*, i8** %4
%44 = getelementptr inbounds [3 x %struct.TYPE_3__], [3 x %struct.TYPE_3__]* %9, i64 0, i64 1
%45 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %44, i32 0, i32 0
%46 = load i32, i32* %45
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %43, i64 %47
%49 = call i64 @atol(i8* %48)
%50 = trunc i64 %49 to i32
%51 = getelementptr inbounds [3 x %struct.TYPE_3__], [3 x %struct.TYPE_3__]* %9, i64 0, i64 2
%52 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %51, i32 0, i32 0
%53 = load i32, i32* %52
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %56
55: ; preds = %42
br label %94
56: ; preds = %42
%57 = load i8*, i8** %4
%58 = getelementptr inbounds [3 x %struct.TYPE_3__], [3 x %struct.TYPE_3__]* %9, i64 0, i64 2
%59 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %58, i32 0, i32 0
%60 = load i32, i32* %59
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %57, i64 %61
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = icmp eq i32 %64, 100
br i1 %65, label %66, label %67
66: ; preds = %56
br label %92
67: ; preds = %56
%68 = load i8*, i8** %4
%69 = getelementptr inbounds [3 x %struct.TYPE_3__], [3 x %struct.TYPE_3__]* %9, i64 0, i64 2
%70 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %69, i32 0, i32 0
%71 = load i32, i32* %70
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8, i8* %68, i64 %72
%74 = load i8, i8* %73
%75 = sext i8 %74 to i32
%76 = icmp eq i32 %75, 104
br i1 %76, label %77, label %78
77: ; preds = %67
br label %90
78: ; preds = %67
%79 = load i8*, i8** %4
%80 = getelementptr inbounds [3 x %struct.TYPE_3__], [3 x %struct.TYPE_3__]* %9, i64 0, i64 2
%81 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %80, i32 0, i32 0
%82 = load i32, i32* %81
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i8, i8* %79, i64 %83
%85 = load i8, i8* %84
%86 = sext i8 %85 to i32
%87 = icmp eq i32 %86, 109
%88 = zext i1 %87 to i64
%89 = select i1 %87, i32 60, i32 1
br label %90
90: ; preds = %78, %77
%91 = phi i32 [ 3600, %77 ], [ %89, %78 ]
br label %92
92: ; preds = %90, %66
%93 = phi i32 [ 86400, %66 ], [ %91, %90 ]
br label %94
94: ; preds = %92, %55
%95 = phi i32 [ 1, %55 ], [ %93, %92 ]
%96 = mul nsw i32 %50, %95
%97 = load i32*, i32** %5
store i32 %96, i32* %97
store i32 0, i32* %3
br label %98
98: ; preds = %94, %41, %15
%99 = load i32, i32* %3
ret i32 %99
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32 }
@.str = [44 x i8] c"^[[:space:]]*([0-9]+)([dhms]?)[[:space:]]*$\00"
@REG_EXTENDED = global i32 0
@.str.1 = [17 x i8] c"regcomp(%s): %s\0A\00"
@REG_NOMATCH = global i32 0
@.str.2 = [42 x i8] c"regexec: Couldn't match '%s' in '%s': %s\0A\00"
define i32 @parse_timespan(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i32
%4 = alloca [128 x i8]
%5 = alloca [3 x %struct.TYPE_3__]
%6 = alloca [128 x i8]
%7 = bitcast i32* %3 to i8*
%8 = load i32, i32* @REG_EXTENDED
%9 = call i32 @regcomp(i32* %3, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %2
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%13 = call i32 @regerror(i32 %9, i32* %3, i8* %12, i32 127)
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 127
store i8 0, i8* %14
%15 = call i32 (i8*, i8*, i8*, ...) @err(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %53
16: ; preds = %2
%17 = bitcast [3 x %struct.TYPE_3__]* %5 to i8*
%18 = getelementptr inbounds [3 x %struct.TYPE_3__], [3 x %struct.TYPE_3__]* %5, i64 0, i64 0
%19 = call i32 @regexec(i32* %3, i8* %0, i32 3, %struct.TYPE_3__* %18, i32 0)
%20 = icmp eq i32 %19, 0
br i1 %20, label %30, label %21
21: ; preds = %16
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%23 = call i32 @regerror(i32 %19, i32* %3, i8* %22, i32 127)
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 127
store i8 0, i8* %24
%25 = load i32, i32* @REG_NOMATCH
%26 = icmp eq i32 %19, %25
br i1 %26, label %29, label %27
27: ; preds = %21
%28 = call i32 (i8*, i8*, i8*, ...) @err(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %22)
br label %29
29: ; preds = %27, %21
br label %51
30: ; preds = %16
%31 = getelementptr inbounds [3 x %struct.TYPE_3__], [3 x %struct.TYPE_3__]* %5, i64 0, i64 1, i32 0
%32 = load i32, i32* %31
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %0, i64 %33
%35 = call i64 @atol(i8* %34)
%36 = trunc i64 %35 to i32
%37 = getelementptr inbounds [3 x %struct.TYPE_3__], [3 x %struct.TYPE_3__]* %5, i64 0, i64 2, i32 0
%38 = load i32, i32* %37
%39 = icmp eq i32 %38, -1
br i1 %39, label %48, label %40
40: ; preds = %30
%41 = sext i32 %38 to i64
%42 = getelementptr inbounds i8, i8* %0, i64 %41
%43 = load i8, i8* %42
switch i8 %43, label %44 [
i8 100, label %48
i8 104, label %47
]
44: ; preds = %40
%45 = icmp eq i8 %43, 109
%46 = select i1 %45, i32 60, i32 1
br label %48
47: ; preds = %40
br label %48
48: ; preds = %40, %47, %44, %30
%49 = phi i32 [ 1, %30 ], [ 86400, %40 ], [ %46, %44 ], [ 3600, %47 ]
%50 = mul nsw i32 %49, %36
store i32 %50, i32* %1
br label %51
51: ; preds = %48, %29
%52 = phi i32 [ -1, %29 ], [ 0, %48 ]
br label %53
53: ; preds = %51, %11
%54 = phi i32 [ -1, %11 ], [ %52, %51 ]
ret i32 %54
}