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

/* Variables and functions */
struct tm *localtime(int /*<<< orphan*/ *);
double diftim(time_t t2, time_t t1) {
  struct tm *ptm;
  double tim;
  int hh1, mm1, ss1, hh2, mm2, ss2;
  ptm = localtime(&t1);
  hh1 = ptm->tm_hour;
  mm1 = ptm->tm_min;
  ss1 = ptm->tm_sec;
  ptm = localtime(&t2);
  hh2 = ptm->tm_hour;
  mm2 = ptm->tm_min;
  ss2 = ptm->tm_sec;
  if (hh2 < hh1)
    hh2 += 24;
  tim = 3600.0 * (hh2 - hh1);
  tim += 60.0 * (mm2 - mm1);
  tim += ss2 - ss1;
  return (tim);
}


x86 assembly (clang, -O0):
<diftim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x8(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x24(%rbp)
lea    -0x4(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1187 <diftim+0x77>
mov    -0x28(%rbp),%eax
add    $0x18,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
sub    -0x1c(%rbp),%eax
cvtsi2sd %eax,%xmm1
movsd  0xe6f(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x2c(%rbp),%eax
sub    -0x20(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  0xe47(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x30(%rbp),%eax
sub    -0x24(%rbp),%eax
cvtsi2sd %eax,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<diftim>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,0xc(%rsp)
mov    %esi,0x8(%rsp)
lea    0x8(%rsp),%rdi
call   1030 <localtime@plt>
mov    (%rax),%ebx
mov    0x4(%rax),%ebp
mov    0x8(%rax),%r14d
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
mov    (%rax),%ecx
lea    0x18(%rcx),%edx
cmp    %ebx,%ecx
cmovge %ecx,%edx
sub    %ebx,%edx
cvtsi2sd %edx,%xmm0
mulsd  0xeab(%rip),%xmm0
mov    0x4(%rax),%ecx
sub    %ebp,%ecx
cvtsi2sd %ecx,%xmm1
mov    0x8(%rax),%eax
mulsd  0xe9f(%rip),%xmm1
addsd  %xmm0,%xmm1
sub    %r14d,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32 }
define double @diftim(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.tm*
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%13 = call %struct.tm* @localtime(i32* %4)
store %struct.tm* %13, %struct.tm** %5
%14 = load %struct.tm*, %struct.tm** %5
%15 = getelementptr inbounds %struct.tm, %struct.tm* %14, i32 0, i32 0
%16 = load i32, i32* %15
store i32 %16, i32* %7
%17 = load %struct.tm*, %struct.tm** %5
%18 = getelementptr inbounds %struct.tm, %struct.tm* %17, i32 0, i32 1
%19 = load i32, i32* %18
store i32 %19, i32* %8
%20 = load %struct.tm*, %struct.tm** %5
%21 = getelementptr inbounds %struct.tm, %struct.tm* %20, i32 0, i32 2
%22 = load i32, i32* %21
store i32 %22, i32* %9
%23 = call %struct.tm* @localtime(i32* %3)
store %struct.tm* %23, %struct.tm** %5
%24 = load %struct.tm*, %struct.tm** %5
%25 = getelementptr inbounds %struct.tm, %struct.tm* %24, i32 0, i32 0
%26 = load i32, i32* %25
store i32 %26, i32* %10
%27 = load %struct.tm*, %struct.tm** %5
%28 = getelementptr inbounds %struct.tm, %struct.tm* %27, i32 0, i32 1
%29 = load i32, i32* %28
store i32 %29, i32* %11
%30 = load %struct.tm*, %struct.tm** %5
%31 = getelementptr inbounds %struct.tm, %struct.tm* %30, i32 0, i32 2
%32 = load i32, i32* %31
store i32 %32, i32* %12
%33 = load i32, i32* %10
%34 = load i32, i32* %7
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %39
36: ; preds = %2
%37 = load i32, i32* %10
%38 = add nsw i32 %37, 24
store i32 %38, i32* %10
br label %39
39: ; preds = %36, %2
%40 = load i32, i32* %10
%41 = load i32, i32* %7
%42 = sub nsw i32 %40, %41
%43 = sitofp i32 %42 to double
%44 = fmul double 3.600000e+03, %43
store double %44, double* %6
%45 = load i32, i32* %11
%46 = load i32, i32* %8
%47 = sub nsw i32 %45, %46
%48 = sitofp i32 %47 to double
%49 = load double, double* %6
%50 = call double @llvm.fmuladd.f64(double 6.000000e+01, double %48, double %49)
store double %50, double* %6
%51 = load i32, i32* %12
%52 = load i32, i32* %9
%53 = sub nsw i32 %51, %52
%54 = sitofp i32 %53 to double
%55 = load double, double* %6
%56 = fadd double %55, %54
store double %56, double* %6
%57 = load double, double* %6
ret double %57
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32 }
define double @diftim(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = call %struct.tm* @localtime(i32* %4)
%6 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 0
%7 = load i32, i32* %6
%8 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 1
%9 = load i32, i32* %8
%10 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 2
%11 = load i32, i32* %10
%12 = call %struct.tm* @localtime(i32* %3)
%13 = getelementptr inbounds %struct.tm, %struct.tm* %12, i64 0, i32 0
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.tm, %struct.tm* %12, i64 0, i32 1
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.tm, %struct.tm* %12, i64 0, i32 2
%18 = load i32, i32* %17
%19 = icmp slt i32 %14, %7
%20 = add nsw i32 %14, 24
%21 = select i1 %19, i32 %20, i32 %14
%22 = sub nsw i32 %21, %7
%23 = sitofp i32 %22 to double
%24 = fmul double %23, 3.600000e+03
%25 = sub nsw i32 %16, %9
%26 = sitofp i32 %25 to double
%27 = call double @llvm.fmuladd.f64(double %26, double 6.000000e+01, double %24)
%28 = sub nsw i32 %18, %11
%29 = sitofp i32 %28 to double
%30 = fadd double %27, %29
ret double %30
}