#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 *, ...);
int /*<<< orphan*/ sscanf(char *, char *, int *, int *, int *);
int main(int argc, char **argv) {
  if (argc < 3) {
    printf("Usage: timeadd <hh:mm:ss> (+|-)<sec>\n");
    return 1;
  }
  char *time_txt = argv[1];
  char *diff_txt = argv[2];
  int hh, mm, ss;
  sscanf(time_txt, "%d%*c%d%*c%d", &hh, &mm, &ss);
  int diff = atoi(diff_txt);
  int old_time = 3600 * hh + 60 * mm + ss;
  int new_time = old_time + diff;
  int is_negative;
  if (new_time < 0) {
    new_time = -new_time;
    is_negative = 1;
  } else {
    is_negative = 0;
  }
  int new_hh = new_time / 3600;
  int new_mm = (new_time % 3600) / 60;
  int new_ss = (new_time % 60);
  if (is_negative) {
    printf("-");
  }
  printf("%02d:%02d:%02d\n", new_hh, new_mm, new_ss);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    116a <main+0x3a>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    124e <main+0x11e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe99(%rip),%rsi
lea    -0x24(%rbp),%rdx
lea    -0x28(%rbp),%rcx
lea    -0x2c(%rbp),%r8
call   1040 <sscanf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x30(%rbp)
imul   $0xe10,-0x24(%rbp),%eax
imul   $0x3c,-0x28(%rbp),%ecx
add    %ecx,%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jge    11e4 <main+0xb4>
xor    %eax,%eax
sub    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    11eb <main+0xbb>
movl   $0x0,-0x3c(%rbp)
mov    -0x38(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x40(%rbp)
mov    -0x38(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x44(%rbp)
mov    -0x38(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,-0x48(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     1237 <main+0x107>
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x40(%rbp),%esi
mov    -0x44(%rbp),%edx
mov    -0x48(%rbp),%ecx
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jg     1175 <main+0x25>
lea    0xeb7(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebp
jmp    1218 <main+0xc8>
mov    0x8(%rsi),%rdi
mov    0x10(%rsi),%rbx
lea    0xe7c(%rip),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
call   1060 <sscanf@plt>
mov    %rbx,%rdi
call   1070 <atoi@plt>
imul   $0xe10,0x14(%rsp),%ecx
imul   $0x3c,0x10(%rsp),%edx
add    %eax,%ecx
add    %edx,%ecx
add    0xc(%rsp),%ecx
mov    %ecx,%ebx
neg    %ebx
cmovs  %ecx,%ebx
mov    $0x91a2b3c5,%r14d
imul   %rbx,%r14
shr    $0x2b,%r14
imul   $0xe10,%r14d,%eax
mov    %ebx,%edx
sub    %eax,%edx
imul   $0x8889,%edx,%r15d
shr    $0x15,%r15d
mov    $0x88888889,%eax
imul   %rbx,%rax
shr    $0x25,%rax
imul   $0x3c,%eax,%eax
sub    %eax,%ebx
test   %ecx,%ecx
jns    1200 <main+0xb0>
mov    $0x2d,%edi
call   1030 <putchar@plt>
lea    0xe06(%rip),%rdi
xor    %ebp,%ebp
mov    %r14d,%esi
mov    %r15d,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"Usage: timeadd <hh:mm:ss> (+|-)<sec>\0A\00"
@.str.1 = [13 x i8] c"%d%*c%d%*c%d\00"
@.str.2 = [2 x i8] c"-\00"
@.str.3 = [16 x i8] c"%02d:%02d:%02d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%18 = load i32, i32* %4
%19 = icmp slt i32 %18, 3
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %66
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
store i8* %25, i8** %6
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
store i8* %28, i8** %7
%29 = load i8*, i8** %6
%30 = call i32 @sscanf(i8* %29, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32* %8, i32* %9, i32* %10)
%31 = load i8*, i8** %7
%32 = call i32 @atoi(i8* %31)
store i32 %32, i32* %11
%33 = load i32, i32* %8
%34 = mul nsw i32 3600, %33
%35 = load i32, i32* %9
%36 = mul nsw i32 60, %35
%37 = add nsw i32 %34, %36
%38 = load i32, i32* %10
%39 = add nsw i32 %37, %38
store i32 %39, i32* %12
%40 = load i32, i32* %12
%41 = load i32, i32* %11
%42 = add nsw i32 %40, %41
store i32 %42, i32* %13
%43 = load i32, i32* %13
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %22
%46 = load i32, i32* %13
%47 = sub nsw i32 0, %46
store i32 %47, i32* %13
store i32 1, i32* %14
br label %49
48: ; preds = %22
store i32 0, i32* %14
br label %49
49: ; preds = %48, %45
%50 = load i32, i32* %13
%51 = sdiv i32 %50, 3600
store i32 %51, i32* %15
%52 = load i32, i32* %13
%53 = srem i32 %52, 3600
%54 = sdiv i32 %53, 60
store i32 %54, i32* %16
%55 = load i32, i32* %13
%56 = srem i32 %55, 60
store i32 %56, i32* %17
%57 = load i32, i32* %14
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %49
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %61
61: ; preds = %59, %49
%62 = load i32, i32* %15
%63 = load i32, i32* %16
%64 = load i32, i32* %17
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %62, i32 %63, i32 %64)
br label %66
66: ; preds = %61, %20
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
@.str.1 = [13 x i8] c"%d%*c%d%*c%d\00"
@.str.3 = [16 x i8] c"%02d:%02d:%02d\0A\00"
@str = [37 x i8] c"Usage: timeadd <hh:mm:ss> (+|-)<sec>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = icmp slt i32 %0, 3
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
br label %40
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = bitcast i32* %3 to i8*
%15 = bitcast i32* %4 to i8*
%16 = bitcast i32* %5 to i8*
%17 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %4, i32* %5)
%18 = call i32 @atoi(i8* %13)
%19 = load i32, i32* %3
%20 = mul nsw i32 %19, 3600
%21 = load i32, i32* %4
%22 = mul nsw i32 %21, 60
%23 = load i32, i32* %5
%24 = add i32 %20, %18
%25 = add i32 %24, %22
%26 = add i32 %25, %23
%27 = icmp slt i32 %26, 0
%28 = sub nsw i32 0, %26
%29 = select i1 %27, i32 %28, i32 %26
%30 = udiv i32 %29, 3600
%31 = urem i32 %29, 3600
%32 = trunc i32 %31 to i16
%33 = udiv i16 %32, 60
%34 = zext i16 %33 to i32
%35 = urem i32 %29, 60
br i1 %27, label %36, label %38
36: ; preds = %9
%37 = call i32 @putchar(i32 45)
br label %38
38: ; preds = %36, %9
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %30, i32 %34, i32 %35)
br label %40
40: ; preds = %38, %7
%41 = phi i32 [ 1, %7 ], [ 0, %38 ]
ret i32 %41
}