#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 /*<<< orphan*/ buf;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
int getDurationSec(unsigned char *duration) {
  int hh, mm, ss;
  char buf[24];
  if ((duration[0] == 0xFF) && (duration[1] == 0xFF) && (duration[2] == 0xFF)) {
    hh = mm = ss = 0;
    ss = -1;
  } else {
    memset(buf, '\0', sizeof(buf));
    sprintf(buf, "%x", duration[0]);
    hh = atoi(buf) * 3600;
    memset(buf, '\0', sizeof(buf));
    sprintf(buf, "%x", duration[1]);
    mm = atoi(buf) * 60;
    memset(buf, '\0', sizeof(buf));
    sprintf(buf, "%x", duration[2]);
    ss = atoi(buf);
  }
  return hh + mm + ss;
}


x86 assembly (clang, -O0):
<getDurationSec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xff,%eax
jne    1195 <getDurationSec+0x65>
mov    -0x8(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0xff,%eax
jne    1195 <getDurationSec+0x65>
mov    -0x8(%rbp),%rax
movzbl 0x2(%rax),%eax
cmp    $0xff,%eax
jne    1195 <getDurationSec+0x65>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0xffffffff,-0x14(%rbp)
jmp    1239 <getDurationSec+0x109>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rax
lea    0xe4c(%rip),%rsi
movzbl (%rax),%edx
call   1050 <sprintf@plt>
lea    -0x30(%rbp),%rdi
call   1040 <atoi@plt>
imul   $0xe10,%eax,%eax
mov    %eax,-0xc(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rax
lea    0xe13(%rip),%rsi
movzbl 0x1(%rax),%edx
call   1050 <sprintf@plt>
lea    -0x30(%rbp),%rdi
call   1040 <atoi@plt>
imul   $0x3c,%eax,%eax
mov    %eax,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rax
lea    0xddc(%rip),%rsi
movzbl 0x2(%rax),%edx
call   1050 <sprintf@plt>
lea    -0x30(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getDurationSec>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
cmpb   $0xff,(%rdi)
jne    1154 <getDurationSec+0x24>
cmpb   $0xff,0x1(%rbx)
jne    1154 <getDurationSec+0x24>
cmpb   $0xff,0x2(%rbx)
je     11eb <getDurationSec+0xbb>
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
movzbl (%rbx),%edx
lea    0xe90(%rip),%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <sprintf@plt>
mov    %r14,%rdi
call   1040 <atoi@plt>
imul   $0xe10,%eax,%r12d
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
movzbl 0x1(%rbx),%edx
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <sprintf@plt>
mov    %r14,%rdi
call   1040 <atoi@plt>
imul   $0x3c,%eax,%ebp
add    %r12d,%ebp
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
movzbl 0x2(%rbx),%edx
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <sprintf@plt>
mov    %r14,%rdi
call   1040 <atoi@plt>
add    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%eax
jmp    11de <getDurationSec+0xae>

LLVM IR (-O0):
@.str = [3 x i8] c"%x\00"
define i32 @getDurationSec(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [24 x i8]
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = getelementptr inbounds i8, i8* %7, i64 0
%9 = load i8, i8* %8
%10 = zext i8 %9 to i32
%11 = icmp eq i32 %10, 255
br i1 %11, label %12, label %25
12: ; preds = %1
%13 = load i8*, i8** %2
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = icmp eq i32 %16, 255
br i1 %17, label %18, label %25
18: ; preds = %12
%19 = load i8*, i8** %2
%20 = getelementptr inbounds i8, i8* %19, i64 2
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = icmp eq i32 %22, 255
br i1 %23, label %24, label %25
24: ; preds = %18
store i32 0, i32* %5
store i32 0, i32* %4
store i32 0, i32* %3
store i32 -1, i32* %5
br label %55
25: ; preds = %18, %12, %1
%26 = getelementptr inbounds [24 x i8], [24 x i8]* %6, i64 0, i64 0
%27 = call i32 @memset(i8* %26, i8 signext 0, i32 24)
%28 = getelementptr inbounds [24 x i8], [24 x i8]* %6, i64 0, i64 0
%29 = load i8*, i8** %2
%30 = getelementptr inbounds i8, i8* %29, i64 0
%31 = load i8, i8* %30
%32 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext %31)
%33 = getelementptr inbounds [24 x i8], [24 x i8]* %6, i64 0, i64 0
%34 = call i32 @atoi(i8* %33)
%35 = mul nsw i32 %34, 3600
store i32 %35, i32* %3
%36 = getelementptr inbounds [24 x i8], [24 x i8]* %6, i64 0, i64 0
%37 = call i32 @memset(i8* %36, i8 signext 0, i32 24)
%38 = getelementptr inbounds [24 x i8], [24 x i8]* %6, i64 0, i64 0
%39 = load i8*, i8** %2
%40 = getelementptr inbounds i8, i8* %39, i64 1
%41 = load i8, i8* %40
%42 = call i32 @sprintf(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext %41)
%43 = getelementptr inbounds [24 x i8], [24 x i8]* %6, i64 0, i64 0
%44 = call i32 @atoi(i8* %43)
%45 = mul nsw i32 %44, 60
store i32 %45, i32* %4
%46 = getelementptr inbounds [24 x i8], [24 x i8]* %6, i64 0, i64 0
%47 = call i32 @memset(i8* %46, i8 signext 0, i32 24)
%48 = getelementptr inbounds [24 x i8], [24 x i8]* %6, i64 0, i64 0
%49 = load i8*, i8** %2
%50 = getelementptr inbounds i8, i8* %49, i64 2
%51 = load i8, i8* %50
%52 = call i32 @sprintf(i8* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext %51)
%53 = getelementptr inbounds [24 x i8], [24 x i8]* %6, i64 0, i64 0
%54 = call i32 @atoi(i8* %53)
store i32 %54, i32* %5
br label %55
55: ; preds = %25, %24
%56 = load i32, i32* %3
%57 = load i32, i32* %4
%58 = add nsw i32 %56, %57
%59 = load i32, i32* %5
%60 = add nsw i32 %58, %59
ret i32 %60
}

LLVM IR (-O2):
@.str = [3 x i8] c"%x\00"
define i32 @getDurationSec(i8* nocapture %0) {
%2 = alloca [24 x i8]
%3 = getelementptr inbounds [24 x i8], [24 x i8]* %2, i64 0, i64 0
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, -1
br i1 %5, label %6, label %14
6: ; preds = %1
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, -1
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = getelementptr inbounds i8, i8* %0, i64 2
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, -1
br i1 %13, label %33, label %14
14: ; preds = %10, %6, %1
%15 = call i32 @memset(i8* %3, i8 signext 0, i32 24)
%16 = load i8, i8* %0
%17 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext %16)
%18 = call i32 @atoi(i8* %3)
%19 = mul nsw i32 %18, 3600
%20 = call i32 @memset(i8* %3, i8 signext 0, i32 24)
%21 = getelementptr inbounds i8, i8* %0, i64 1
%22 = load i8, i8* %21
%23 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext %22)
%24 = call i32 @atoi(i8* %3)
%25 = mul nsw i32 %24, 60
%26 = call i32 @memset(i8* %3, i8 signext 0, i32 24)
%27 = getelementptr inbounds i8, i8* %0, i64 2
%28 = load i8, i8* %27
%29 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext %28)
%30 = call i32 @atoi(i8* %3)
%31 = add nsw i32 %25, %19
%32 = add nsw i32 %31, %30
br label %33
33: ; preds = %10, %14
%34 = phi i32 [ %32, %14 ], [ -1, %10 ]
ret i32 %34
}