#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 atoi(char *);
int strlen(char *);
int a2s(char *str) {
  int hours = 0, minutes = 0, seconds = 0, len;
  hours = atoi(str);
  if ((len = strlen(str)) > 3)
    minutes = atoi(&(str[3]));
  if (len > 6)
    seconds = atoi(&(str[6]));
  return seconds + (minutes + (hours * 60)) * 60;
}


x86 assembly (clang, -O0):
<a2s>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x3,%eax
jle    1172 <a2s+0x52>
mov    -0x8(%rbp),%rdi
add    $0x3,%rdi
call   1040 <atoi@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x6,-0x18(%rbp)
jle    118c <a2s+0x6c>
mov    -0x8(%rbp),%rdi
add    $0x6,%rdi
call   1040 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%ecx
imul   $0x3c,-0xc(%rbp),%edx
add    %edx,%ecx
imul   $0x3c,%ecx,%ecx
add    %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<a2s>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbx
call   1040 <atoi@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1030 <strlen@plt>
xor    %r12d,%r12d
cmp    $0x4,%eax
jl     1167 <a2s+0x47>
mov    %eax,%ebp
lea    0x3(%rbx),%rdi
call   1040 <atoi@plt>
mov    %eax,%r15d
cmp    $0x7,%ebp
jb     116a <a2s+0x4a>
add    $0x6,%rbx
mov    %rbx,%rdi
call   1040 <atoi@plt>
mov    %eax,%r12d
jmp    116a <a2s+0x4a>
xor    %r15d,%r15d
imul   $0x3c,%r14d,%eax
add    %r15d,%eax
imul   $0x3c,%eax,%eax
add    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @a2s(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
%7 = load i8*, i8** %2
%8 = call i32 @atoi(i8* %7)
store i32 %8, i32* %3
%9 = load i8*, i8** %2
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %6
%11 = icmp sgt i32 %10, 3
br i1 %11, label %12, label %16
12: ; preds = %1
%13 = load i8*, i8** %2
%14 = getelementptr inbounds i8, i8* %13, i64 3
%15 = call i32 @atoi(i8* %14)
store i32 %15, i32* %4
br label %16
16: ; preds = %12, %1
%17 = load i32, i32* %6
%18 = icmp sgt i32 %17, 6
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load i8*, i8** %2
%21 = getelementptr inbounds i8, i8* %20, i64 6
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %5
br label %23
23: ; preds = %19, %16
%24 = load i32, i32* %5
%25 = load i32, i32* %4
%26 = load i32, i32* %3
%27 = mul nsw i32 %26, 60
%28 = add nsw i32 %25, %27
%29 = mul nsw i32 %28, 60
%30 = add nsw i32 %24, %29
ret i32 %30
}

LLVM IR (-O2):
define i32 @a2s(i8* %0) {
%2 = tail call i32 @atoi(i8* %0)
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp sgt i32 %3, 3
br i1 %4, label %5, label %12
5: ; preds = %1
%6 = getelementptr inbounds i8, i8* %0, i64 3
%7 = tail call i32 @atoi(i8* %6)
%8 = icmp ugt i32 %3, 6
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = getelementptr inbounds i8, i8* %0, i64 6
%11 = tail call i32 @atoi(i8* %10)
br label %12
12: ; preds = %1, %9, %5
%13 = phi i32 [ %7, %9 ], [ %7, %5 ], [ 0, %1 ]
%14 = phi i32 [ %11, %9 ], [ 0, %5 ], [ 0, %1 ]
%15 = mul nsw i32 %2, 60
%16 = add nsw i32 %13, %15
%17 = mul nsw i32 %16, 60
%18 = add nsw i32 %17, %14
ret i32 %18
}