#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 /*<<< orphan*/ printf(char *, char const *);
scalar_t__ strlen(char const *);
int CalculateSeconds(const char *timeString) {
  int len = 0;
  int i;
  int factor = 0;
  int num = 0;
  int retVal = 0;
  char buffer[2];
  len = (int)strlen(timeString);
  buffer[1] = '\0';
  for (i = len - 1; i > 0; i--) {
    buffer[0] = timeString[i];
    if (buffer[0] == ':') {
    } else if ((buffer[0] >= '0') && (buffer[0] <= '9')) {
      switch (factor) {
      case 0:
        factor = 1;
        break;
      case 1:
        factor = 10;
        break;
      case 10:
        factor = 60;
        break;
      case 60:
        factor = 600;
        break;
      case 600:
        factor = 14400;
        break;
      case 14400:
        factor = 144000;
        break;
      }
      num = atoi(buffer) * factor;
      retVal += num;
    } else {
      printf("CalculateSeconds(%s) encountered illegal char.\r\n", timeString);
      return -1;
    }
  }
  return retVal;
}


x86 assembly (clang, -O0):
<CalculateSeconds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
movb   $0x0,-0x25(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    12b6 <CalculateSeconds+0x186>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x26(%rbp)
movsbl -0x26(%rbp),%eax
cmp    $0x3a,%eax
jne    119b <CalculateSeconds+0x6b>
jmp    12a3 <CalculateSeconds+0x173>
movsbl -0x26(%rbp),%eax
cmp    $0x30,%eax
jl     1282 <CalculateSeconds+0x152>
movsbl -0x26(%rbp),%eax
cmp    $0x39,%eax
jg     1282 <CalculateSeconds+0x152>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
test   %eax,%eax
je     1221 <CalculateSeconds+0xf1>
jmp    11c8 <CalculateSeconds+0x98>
mov    -0x2c(%rbp),%eax
sub    $0x1,%eax
je     122d <CalculateSeconds+0xfd>
jmp    11d9 <CalculateSeconds+0xa9>
mov    -0x2c(%rbp),%eax
sub    $0xa,%eax
je     1239 <CalculateSeconds+0x109>
jmp    11ea <CalculateSeconds+0xba>
mov    -0x2c(%rbp),%eax
sub    $0x3c,%eax
je     1245 <CalculateSeconds+0x115>
jmp    11fb <CalculateSeconds+0xcb>
mov    -0x2c(%rbp),%eax
sub    $0x258,%eax
je     1251 <CalculateSeconds+0x121>
jmp    120e <CalculateSeconds+0xde>
mov    -0x2c(%rbp),%eax
sub    $0x3840,%eax
je     125d <CalculateSeconds+0x12d>
jmp    1264 <CalculateSeconds+0x134>
movl   $0x1,-0x1c(%rbp)
jmp    1264 <CalculateSeconds+0x134>
movl   $0xa,-0x1c(%rbp)
jmp    1264 <CalculateSeconds+0x134>
movl   $0x3c,-0x1c(%rbp)
jmp    1264 <CalculateSeconds+0x134>
movl   $0x258,-0x1c(%rbp)
jmp    1264 <CalculateSeconds+0x134>
movl   $0x3840,-0x1c(%rbp)
jmp    1264 <CalculateSeconds+0x134>
movl   $0x23280,-0x1c(%rbp)
lea    -0x26(%rbp),%rdi
call   1050 <atoi@plt>
imul   -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    129e <CalculateSeconds+0x16e>
mov    -0x10(%rbp),%rsi
lea    0xd73(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12bc <CalculateSeconds+0x18c>
jmp    12a3 <CalculateSeconds+0x173>
jmp    12a8 <CalculateSeconds+0x178>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1171 <CalculateSeconds+0x41>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CalculateSeconds>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r15
call   1030 <strlen@plt>
movb   $0x0,0xf(%rsp)
xor    %r12d,%r12d
cmp    $0x2,%eax
jl     1209 <CalculateSeconds+0xd9>
mov    %eax,%ebx
add    $0x1,%rbx
xor    %r12d,%r12d
lea    0xe(%rsp),%r14
xor    %ebp,%ebp
jmp    118c <CalculateSeconds+0x5c>
mov    $0x3840,%ebp
nopl   0x0(%rax)
mov    %r14,%rdi
call   1050 <atoi@plt>
imul   %ebp,%eax
add    %eax,%r12d
add    $0xffffffffffffffff,%rbx
cmp    $0x2,%rbx
jbe    1209 <CalculateSeconds+0xd9>
lea    -0x2(%rbx),%eax
movzbl (%r15,%rax,1),%eax
mov    %al,0xe(%rsp)
cmp    $0x3a,%al
je     117e <CalculateSeconds+0x4e>
add    $0xd0,%al
cmp    $0x9,%al
ja     11f4 <CalculateSeconds+0xc4>
cmp    $0x3b,%ebp
jg     11c0 <CalculateSeconds+0x90>
test   %ebp,%ebp
je     11dc <CalculateSeconds+0xac>
cmp    $0x1,%ebp
je     11e3 <CalculateSeconds+0xb3>
cmp    $0xa,%ebp
jne    1170 <CalculateSeconds+0x40>
mov    $0x3c,%ebp
jmp    1170 <CalculateSeconds+0x40>
nopl   0x0(%rax)
cmp    $0x3c,%ebp
je     11ea <CalculateSeconds+0xba>
cmp    $0x258,%ebp
je     1167 <CalculateSeconds+0x37>
cmp    $0x3840,%ebp
jne    1170 <CalculateSeconds+0x40>
mov    $0x23280,%ebp
jmp    1170 <CalculateSeconds+0x40>
mov    $0x1,%ebp
jmp    1170 <CalculateSeconds+0x40>
mov    $0xa,%ebp
jmp    1170 <CalculateSeconds+0x40>
mov    $0x258,%ebp
jmp    1170 <CalculateSeconds+0x40>
lea    0xe05(%rip),%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%r12d
mov    %r12d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [49 x i8] c"CalculateSeconds(%s) encountered illegal char.\0D\0A\00"
define i32 @CalculateSeconds(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [2 x i8]
store i8* %0, i8** %3
store i32 0, i32* %4
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%10 = load i8*, i8** %3
%11 = call i64 @strlen(i8* %10)
%12 = trunc i64 %11 to i32
store i32 %12, i32* %4
%13 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 1
store i8 0, i8* %13
%14 = load i32, i32* %4
%15 = sub nsw i32 %14, 1
store i32 %15, i32* %5
br label %16
16: ; preds = %62, %1
%17 = load i32, i32* %5
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %65
19: ; preds = %16
%20 = load i8*, i8** %3
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
store i8 %24, i8* %25
%26 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 58
br i1 %29, label %30, label %31
30: ; preds = %19
br label %61
31: ; preds = %19
%32 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp sge i32 %34, 48
br i1 %35, label %36, label %57
36: ; preds = %31
%37 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp sle i32 %39, 57
br i1 %40, label %41, label %57
41: ; preds = %36
%42 = load i32, i32* %6
switch i32 %42, label %49 [
i32 0, label %43
i32 1, label %44
i32 10, label %45
i32 60, label %46
i32 600, label %47
i32 14400, label %48
]
43: ; preds = %41
store i32 1, i32* %6
br label %49
44: ; preds = %41
store i32 10, i32* %6
br label %49
45: ; preds = %41
store i32 60, i32* %6
br label %49
46: ; preds = %41
store i32 600, i32* %6
br label %49
47: ; preds = %41
store i32 14400, i32* %6
br label %49
48: ; preds = %41
store i32 144000, i32* %6
br label %49
49: ; preds = %41, %48, %47, %46, %45, %44, %43
%50 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%51 = call i32 @atoi(i8* %50)
%52 = load i32, i32* %6
%53 = mul nsw i32 %51, %52
store i32 %53, i32* %7
%54 = load i32, i32* %7
%55 = load i32, i32* %8
%56 = add nsw i32 %55, %54
store i32 %56, i32* %8
br label %60
57: ; preds = %36, %31
%58 = load i8*, i8** %3
%59 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %58)
store i32 -1, i32* %2
br label %67
60: ; preds = %49
br label %61
61: ; preds = %60, %30
br label %62
62: ; preds = %61
%63 = load i32, i32* %5
%64 = add nsw i32 %63, -1
store i32 %64, i32* %5
br label %16
65: ; preds = %16
%66 = load i32, i32* %8
store i32 %66, i32* %2
br label %67
67: ; preds = %65, %57
%68 = load i32, i32* %2
ret i32 %68
}

LLVM IR (-O2):
@.str = [49 x i8] c"CalculateSeconds(%s) encountered illegal char.\0D\0A\00"
define i32 @CalculateSeconds(i8* %0) {
%2 = alloca [2 x i8]
%3 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = trunc i64 %4 to i32
%6 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 1
store i8 0, i8* %6
%7 = icmp sgt i32 %5, 1
br i1 %7, label %8, label %40
8: ; preds = %1
%9 = and i64 %4, 4294967295
br label %10
10: ; preds = %8, %36
%11 = phi i64 [ %9, %8 ], [ %14, %36 ]
%12 = phi i32 [ 0, %8 ], [ %38, %36 ]
%13 = phi i32 [ 0, %8 ], [ %37, %36 ]
%14 = add nsw i64 %11, -1
%15 = and i64 %14, 4294967295
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = load i8, i8* %16
store i8 %17, i8* %3
%18 = icmp eq i8 %17, 58
br i1 %18, label %36, label %19
19: ; preds = %10
%20 = add i8 %17, -48
%21 = icmp ult i8 %20, 10
br i1 %21, label %22, label %34
22: ; preds = %19
switch i32 %13, label %29 [
i32 0, label %23
i32 1, label %24
i32 10, label %25
i32 60, label %26
i32 600, label %27
i32 14400, label %28
]
23: ; preds = %22
br label %29
24: ; preds = %22
br label %29
25: ; preds = %22
br label %29
26: ; preds = %22
br label %29
27: ; preds = %22
br label %29
28: ; preds = %22
br label %29
29: ; preds = %22, %28, %27, %26, %25, %24, %23
%30 = phi i32 [ %13, %22 ], [ 144000, %28 ], [ 14400, %27 ], [ 600, %26 ], [ 60, %25 ], [ 10, %24 ], [ 1, %23 ]
%31 = call i32 @atoi(i8* %3)
%32 = mul nsw i32 %31, %30
%33 = add nsw i32 %32, %12
br label %36
34: ; preds = %19
%35 = tail call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %40
36: ; preds = %29, %10
%37 = phi i32 [ %13, %10 ], [ %30, %29 ]
%38 = phi i32 [ %12, %10 ], [ %33, %29 ]
%39 = icmp ugt i64 %11, 2
br i1 %39, label %10, label %40
40: ; preds = %36, %1, %34
%41 = phi i32 [ -1, %34 ], [ 0, %1 ], [ %38, %36 ]
ret i32 %41
}