#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 */
struct tm {
  int const tm_hour;
  int const tm_min;
  scalar_t__ tm_sec;
};

/* Variables and functions */
int tm_compare(struct tm const *, struct tm const *);
int tm_intraday_secs_diff(const struct tm *first, const struct tm *second) {
  static const int secs_in_day = 86400;
  static const int secs_in_hour = 3600;
  static const int secs_in_min = 60;
  const int time_comp = tm_compare(first, second);
  int difference = 0;
  if (time_comp == 0) {
    difference = 0;
  } else {
    difference = (second->tm_hour - first->tm_hour) * secs_in_hour;
    difference += (second->tm_min - first->tm_min) * secs_in_min;
    difference += (second->tm_sec - first->tm_sec);
    if (time_comp == 1 && difference > 0) {
      difference -= secs_in_day;
    } else if (time_comp == -1 && difference < 0) {
      difference += secs_in_day;
    }
  }
  return difference;
}


x86 assembly (clang, -O0):
<tm_intraday_secs_diff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <tm_compare@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    114d <tm_intraday_secs_diff+0x3d>
movl   $0x0,-0x18(%rbp)
jmp    11e0 <tm_intraday_secs_diff+0xd0>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%rcx
sub    (%rcx),%eax
imul   $0xe10,%eax,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    -0x8(%rbp),%rcx
sub    0x4(%rcx),%eax
imul   $0x3c,%eax,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x8(%rbp),%rax
sub    0x8(%rax),%rcx
movslq -0x18(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    11b7 <tm_intraday_secs_diff+0xa7>
cmpl   $0x0,-0x18(%rbp)
jle    11b7 <tm_intraday_secs_diff+0xa7>
mov    -0x18(%rbp),%eax
sub    $0x15180,%eax
mov    %eax,-0x18(%rbp)
jmp    11db <tm_intraday_secs_diff+0xcb>
cmpl   $0xffffffff,-0x14(%rbp)
jne    11d6 <tm_intraday_secs_diff+0xc6>
cmpl   $0x0,-0x18(%rbp)
jge    11d6 <tm_intraday_secs_diff+0xc6>
mov    -0x18(%rbp),%eax
add    $0x15180,%eax
mov    %eax,-0x18(%rbp)
jmp    11db <tm_intraday_secs_diff+0xcb>
jmp    11e0 <tm_intraday_secs_diff+0xd0>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tm_intraday_secs_diff>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
call   1030 <tm_compare@plt>
test   %eax,%eax
je     1156 <tm_intraday_secs_diff+0x46>
mov    (%rbx),%ecx
mov    0x4(%rbx),%edx
sub    (%r14),%ecx
sub    0x4(%r14),%edx
imul   $0xe10,%ecx,%ecx
imul   $0x3c,%edx,%esi
add    %ecx,%esi
mov    0x8(%rbx),%edx
sub    0x8(%r14),%edx
add    %esi,%edx
cmp    $0x1,%eax
jne    115a <tm_intraday_secs_diff+0x4a>
test   %edx,%edx
jle    115a <tm_intraday_secs_diff+0x4a>
add    $0xfffeae80,%edx
mov    %edx,%ecx
jmp    116b <tm_intraday_secs_diff+0x5b>
xor    %ecx,%ecx
jmp    116b <tm_intraday_secs_diff+0x5b>
lea    0x15180(%rdx),%ecx
test   %edx,%edx
cmovns %edx,%ecx
cmp    $0xffffffff,%eax
cmovne %edx,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i64 }
@tm_intraday_secs_diff.secs_in_day = internal constant i32 86400
@tm_intraday_secs_diff.secs_in_hour = internal constant i32 3600
@tm_intraday_secs_diff.secs_in_min = internal constant i32 60
define i32 @tm_intraday_secs_diff(%struct.tm* %0, %struct.tm* %1) {
%3 = alloca %struct.tm*
%4 = alloca %struct.tm*
%5 = alloca i32
%6 = alloca i32
store %struct.tm* %0, %struct.tm** %3
store %struct.tm* %1, %struct.tm** %4
%7 = load %struct.tm*, %struct.tm** %3
%8 = load %struct.tm*, %struct.tm** %4
%9 = call i32 @tm_compare(%struct.tm* %7, %struct.tm* %8)
store i32 %9, i32* %5
store i32 0, i32* %6
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 0, i32* %6
br label %62
13: ; preds = %2
%14 = load %struct.tm*, %struct.tm** %4
%15 = getelementptr inbounds %struct.tm, %struct.tm* %14, i32 0, i32 0
%16 = load i32, i32* %15
%17 = load %struct.tm*, %struct.tm** %3
%18 = getelementptr inbounds %struct.tm, %struct.tm* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = sub nsw i32 %16, %19
%21 = mul nsw i32 %20, 3600
store i32 %21, i32* %6
%22 = load %struct.tm*, %struct.tm** %4
%23 = getelementptr inbounds %struct.tm, %struct.tm* %22, i32 0, i32 1
%24 = load i32, i32* %23
%25 = load %struct.tm*, %struct.tm** %3
%26 = getelementptr inbounds %struct.tm, %struct.tm* %25, i32 0, i32 1
%27 = load i32, i32* %26
%28 = sub nsw i32 %24, %27
%29 = mul nsw i32 %28, 60
%30 = load i32, i32* %6
%31 = add nsw i32 %30, %29
store i32 %31, i32* %6
%32 = load %struct.tm*, %struct.tm** %4
%33 = getelementptr inbounds %struct.tm, %struct.tm* %32, i32 0, i32 2
%34 = load i64, i64* %33
%35 = load %struct.tm*, %struct.tm** %3
%36 = getelementptr inbounds %struct.tm, %struct.tm* %35, i32 0, i32 2
%37 = load i64, i64* %36
%38 = sub nsw i64 %34, %37
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = add nsw i64 %40, %38
%42 = trunc i64 %41 to i32
store i32 %42, i32* %6
%43 = load i32, i32* %5
%44 = icmp eq i32 %43, 1
br i1 %44, label %45, label %51
45: ; preds = %13
%46 = load i32, i32* %6
%47 = icmp sgt i32 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %45
%49 = load i32, i32* %6
%50 = sub nsw i32 %49, 86400
store i32 %50, i32* %6
br label %61
51: ; preds = %45, %13
%52 = load i32, i32* %5
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %60
54: ; preds = %51
%55 = load i32, i32* %6
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %54
%58 = load i32, i32* %6
%59 = add nsw i32 %58, 86400
store i32 %59, i32* %6
br label %60
60: ; preds = %57, %54, %51
br label %61
61: ; preds = %60, %48
br label %62
62: ; preds = %61, %12
%63 = load i32, i32* %6
ret i32 %63
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i64 }
define i32 @tm_intraday_secs_diff(%struct.tm* %0, %struct.tm* %1) {
%3 = tail call i32 @tm_compare(%struct.tm* %0, %struct.tm* %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %37, label %5
5: ; preds = %2
%6 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 0
%7 = load i32, i32* %6
%8 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 0
%9 = load i32, i32* %8
%10 = sub nsw i32 %7, %9
%11 = mul nsw i32 %10, 3600
%12 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 1
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 1
%15 = load i32, i32* %14
%16 = sub nsw i32 %13, %15
%17 = mul nsw i32 %16, 60
%18 = add nsw i32 %17, %11
%19 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 2
%20 = load i64, i64* %19
%21 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 2
%22 = load i64, i64* %21
%23 = sub nsw i64 %20, %22
%24 = trunc i64 %23 to i32
%25 = add i32 %18, %24
%26 = icmp eq i32 %3, 1
%27 = icmp sgt i32 %25, 0
%28 = select i1 %26, i1 %27, i1 false
br i1 %28, label %29, label %31
29: ; preds = %5
%30 = add nsw i32 %25, -86400
br label %37
31: ; preds = %5
%32 = icmp eq i32 %3, -1
%33 = icmp slt i32 %25, 0
%34 = select i1 %32, i1 %33, i1 false
%35 = add nsw i32 %25, 86400
%36 = select i1 %34, i32 %35, i32 %25
br label %37
37: ; preds = %31, %2, %29
%38 = phi i32 [ %30, %29 ], [ 0, %2 ], [ %36, %31 ]
ret i32 %38
}