#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 uint32_t;
typedef int int32_t;

/* Variables and functions */
int /*<<< orphan*/ log_error(char *, char);
int /*<<< orphan*/ log_perror(char *);
int sscanf(char const *, char *, int *, char *);
uint32_t parse_time_unit(const char *input) {
  char unit;
  int32_t matched = 0;
  uint32_t seconds = 0;
  if ((matched = sscanf(input, "%u %c", &seconds, &unit)) >= 1) {
    if (matched == 1)
      return seconds;
    switch (unit) {
    case 's':
    case 'S':
      return seconds;
    case 'm':
    case 'M':
      return seconds * 60;
    case 'h':
    case 'H':
      return seconds * 3600;
    default:
      log_error("Invalid time unit specified: %c", unit);
      return 0;
    }
  } else if (matched == -1) {
    log_perror("nyx: sscanf");
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_time_unit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeab(%rip),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x11(%rbp),%rcx
call   1040 <sscanf@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x1,%eax
jl     122f <parse_time_unit+0xff>
cmpl   $0x1,-0x18(%rbp)
jne    1183 <parse_time_unit+0x53>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1251 <parse_time_unit+0x121>
movsbl -0x11(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x48,%eax
je     1204 <parse_time_unit+0xd4>
jmp    1198 <parse_time_unit+0x68>
mov    -0x20(%rbp),%eax
sub    $0x4d,%eax
je     11f8 <parse_time_unit+0xc8>
jmp    11a9 <parse_time_unit+0x79>
mov    -0x20(%rbp),%eax
sub    $0x53,%eax
je     11ed <parse_time_unit+0xbd>
jmp    11ba <parse_time_unit+0x8a>
mov    -0x20(%rbp),%eax
sub    $0x68,%eax
je     1204 <parse_time_unit+0xd4>
jmp    11cb <parse_time_unit+0x9b>
mov    -0x20(%rbp),%eax
sub    $0x6d,%eax
je     11f8 <parse_time_unit+0xc8>
jmp    11dc <parse_time_unit+0xac>
mov    -0x20(%rbp),%eax
sub    $0x73,%eax
jne    1213 <parse_time_unit+0xe3>
jmp    11ed <parse_time_unit+0xbd>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1251 <parse_time_unit+0x121>
imul   $0x3c,-0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1251 <parse_time_unit+0x121>
imul   $0xe10,-0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1251 <parse_time_unit+0x121>
lea    0xdec(%rip),%rdi
movsbl -0x11(%rbp),%esi
call   1030 <log_error@plt>
movl   $0x0,-0x4(%rbp)
jmp    1251 <parse_time_unit+0x121>
cmpl   $0xffffffff,-0x18(%rbp)
jne    1245 <parse_time_unit+0x115>
lea    0xde6(%rip),%rdi
call   1050 <log_perror@plt>
jmp    124a <parse_time_unit+0x11a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_time_unit>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
lea    0xebc(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0xb(%rsp),%rcx
call   1040 <sscanf@plt>
test   %eax,%eax
jle    119f <parse_time_unit+0x6f>
cmp    $0x1,%eax
je     1199 <parse_time_unit+0x69>
movsbl 0xb(%rsp),%eax
lea    -0x48(%rax),%ecx
cmp    $0x2b,%ecx
ja     11c5 <parse_time_unit+0x95>
movabs $0x100000001,%rdx
bt     %rcx,%rdx
jb     11bb <parse_time_unit+0x8b>
movabs $0x2000000020,%rdx
bt     %rcx,%rdx
jb     11b4 <parse_time_unit+0x84>
movabs $0x80000000800,%rdx
bt     %rcx,%rdx
jae    11c5 <parse_time_unit+0x95>
mov    0xc(%rsp),%ebx
jmp    11d6 <parse_time_unit+0xa6>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
jne    11d6 <parse_time_unit+0xa6>
lea    0xe79(%rip),%rdi
call   1050 <log_perror@plt>
jmp    11d6 <parse_time_unit+0xa6>
imul   $0x3c,0xc(%rsp),%ebx
jmp    11d6 <parse_time_unit+0xa6>
imul   $0xe10,0xc(%rsp),%ebx
jmp    11d6 <parse_time_unit+0xa6>
movsbl %al,%esi
lea    0xe37(%rip),%rdi
call   1030 <log_error@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%u %c\00"
@.str.1 = [32 x i8] c"Invalid time unit specified: %c\00"
@.str.2 = [12 x i8] c"nyx: sscanf\00"
define i32 @parse_time_unit(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %5
store i32 0, i32* %6
%7 = load i8*, i8** %3
%8 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %6, i8* %4)
store i32 %8, i32* %5
%9 = icmp sge i32 %8, 1
br i1 %9, label %10, label %29
10: ; preds = %1
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = load i32, i32* %6
store i32 %14, i32* %2
br label %36
15: ; preds = %10
%16 = load i8, i8* %4
%17 = sext i8 %16 to i32
switch i32 %17, label %26 [
i32 115, label %18
i32 83, label %18
i32 109, label %20
i32 77, label %20
i32 104, label %23
i32 72, label %23
]
18: ; preds = %15, %15
%19 = load i32, i32* %6
store i32 %19, i32* %2
br label %36
20: ; preds = %15, %15
%21 = load i32, i32* %6
%22 = mul nsw i32 %21, 60
store i32 %22, i32* %2
br label %36
23: ; preds = %15, %15
%24 = load i32, i32* %6
%25 = mul nsw i32 %24, 3600
store i32 %25, i32* %2
br label %36
26: ; preds = %15
%27 = load i8, i8* %4
%28 = call i32 @log_error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8 signext %27)
store i32 0, i32* %2
br label %36
29: ; preds = %1
%30 = load i32, i32* %5
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 @log_perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %32, %29
br label %35
35: ; preds = %34
store i32 0, i32* %2
br label %36
36: ; preds = %35, %26, %23, %20, %18, %13
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
@.str = [6 x i8] c"%u %c\00"
@.str.1 = [32 x i8] c"Invalid time unit specified: %c\00"
@.str.2 = [12 x i8] c"nyx: sscanf\00"
define i32 @parse_time_unit(i8* nocapture %0) {
%2 = alloca i8
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %3, i8* %2)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %24
7: ; preds = %1
%8 = icmp eq i32 %5, 1
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = load i32, i32* %3
br label %28
11: ; preds = %7
%12 = load i8, i8* %2
%13 = sext i8 %12 to i32
switch i32 %13, label %22 [
i32 115, label %14
i32 83, label %14
i32 109, label %16
i32 77, label %16
i32 104, label %19
i32 72, label %19
]
14: ; preds = %11, %11
%15 = load i32, i32* %3
br label %28
16: ; preds = %11, %11
%17 = load i32, i32* %3
%18 = mul nsw i32 %17, 60
br label %28
19: ; preds = %11, %11
%20 = load i32, i32* %3
%21 = mul nsw i32 %20, 3600
br label %28
22: ; preds = %11
%23 = call i32 @log_error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8 signext %12)
br label %28
24: ; preds = %1
%25 = icmp eq i32 %5, -1
br i1 %25, label %26, label %28
26: ; preds = %24
%27 = call i32 @log_perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %26, %24, %22, %19, %16, %14, %9
%29 = phi i32 [ %10, %9 ], [ 0, %22 ], [ %21, %19 ], [ %18, %16 ], [ %15, %14 ], [ 0, %24 ], [ 0, %26 ]
ret i32 %29
}