#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 const *, char *, int *, int *, int *);
int gettime(const char *digit) {
  int hour, min, sec;
  hour = min = sec = 0;
  switch (sscanf(digit, "%2d:%2d:%2d", &hour, &min, &sec)) {
  case 1:
  case 2:
  case 3:
    if (hour < 0 || hour > 24 || min < 0 || min > 60 || sec < 0 || sec > 60)
      return -1;
    return hour * 3600 + min * 60 + sec;
  default:
    break;
  }
  return -1;
}


x86 assembly (clang, -O0):
<gettime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xec4(%rip),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
lea    -0x1c(%rbp),%r8
call   1030 <sscanf@plt>
add    $0xffffffff,%eax
sub    $0x2,%eax
ja     11be <gettime+0xae>
jmp    115e <gettime+0x4e>
cmpl   $0x0,-0x14(%rbp)
jl     119a <gettime+0x8a>
cmpl   $0x18,-0x14(%rbp)
jg     119a <gettime+0x8a>
cmpl   $0x0,-0x18(%rbp)
jl     119a <gettime+0x8a>
cmpl   $0x3c,-0x18(%rbp)
jg     119a <gettime+0x8a>
cmpl   $0x0,-0x1c(%rbp)
jl     119a <gettime+0x8a>
cmpl   $0x3c,-0x1c(%rbp)
jle    11a6 <gettime+0x96>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ca <gettime+0xba>
imul   $0xe10,-0x14(%rbp),%eax
imul   $0x3c,-0x18(%rbp),%ecx
add    %ecx,%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ca <gettime+0xba>
jmp    11c3 <gettime+0xb3>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gettime>:
sub    $0x18,%rsp
movl   $0x0,0xc(%rsp)
movl   $0x0,0x10(%rsp)
movl   $0x0,0x14(%rsp)
lea    0xecd(%rip),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
call   1030 <sscanf@plt>
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    $0xffffffff,%eax
cmp    $0x2,%ecx
ja     1186 <gettime+0x76>
mov    0x14(%rsp),%ecx
cmp    $0x18,%ecx
ja     1186 <gettime+0x76>
mov    0x10(%rsp),%edx
test   %edx,%edx
js     1186 <gettime+0x76>
cmp    $0x3c,%edx
jg     1186 <gettime+0x76>
mov    0xc(%rsp),%esi
test   %esi,%esi
js     1186 <gettime+0x76>
cmp    $0x3c,%esi
jg     1186 <gettime+0x76>
imul   $0xe10,%ecx,%ecx
imul   $0x3c,%edx,%eax
add    %ecx,%eax
add    %esi,%eax
add    $0x18,%rsp
ret

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

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