#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 */
long useme(long, ...);
void foo(void) {
  long secs = useme(41);
  long utc_secs = useme(42);
  long h, m;
  utc_secs = useme(42);
  h = secs / 3600;
  m = secs / 60;
  if (utc_secs >= 86400) {
    m = 59;
    h--;
    if (h < 0)
      h = 23;
  }
  useme(h, m);
}


x86 assembly (clang, -O0):
<foo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x29,%edi
mov    $0x0,%al
call   1030 <useme@plt>
mov    %rax,-0x8(%rbp)
mov    $0x2a,%edi
mov    $0x0,%al
call   1030 <useme@plt>
mov    %rax,-0x10(%rbp)
mov    $0x2a,%edi
mov    $0x0,%al
call   1030 <useme@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    $0xe10,%ecx
cqto
idiv   %rcx
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x3c,%ecx
cqto
idiv   %rcx
mov    %rax,-0x20(%rbp)
cmpq   $0x15180,-0x10(%rbp)
jl     11a6 <foo+0x96>
movq   $0x3b,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    11a1 <foo+0x91>
movq   $0x17,-0x18(%rbp)
jmp    11a6 <foo+0x96>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1030 <useme@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<foo>:
push   %rbx
mov    $0x29,%edi
xor    %eax,%eax
call   1030 <useme@plt>
mov    %rax,%rbx
mov    $0x2a,%edi
xor    %eax,%eax
call   1030 <useme@plt>
mov    $0x2a,%edi
xor    %eax,%eax
call   1030 <useme@plt>
mov    %rax,%r8
movabs $0x48d159e26af37c05,%rdx
59 d1 48
mov    %rbx,%rax
imul   %rdx
mov    %rdx,%rsi
mov    %rdx,%rcx
shr    $0x3f,%rcx
sar    $0xa,%rsi
movabs $0x8888888888888889,%rdx
88 88 88
mov    %rbx,%rax
imul   %rdx
lea    (%rdx,%rbx,1),%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x5,%rax
add    %rdx,%rax
lea    (%rsi,%rcx,1),%rdx
add    $0xffffffffffffffff,%rdx
cmp    $0xe10,%rbx
mov    $0x17,%edi
cmovge %rdx,%rdi
add    %rsi,%rcx
cmp    $0x15180,%r8
cmovl  %rcx,%rdi
mov    $0x3b,%esi
cmovl  %rax,%rsi
xor    %eax,%eax
pop    %rbx
jmp    1030 <useme@plt>

LLVM IR (-O0):
define void @foo() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = call i64 (i64, ...) @useme(i64 41)
store i64 %5, i64* %1
%6 = call i64 (i64, ...) @useme(i64 42)
store i64 %6, i64* %2
%7 = call i64 (i64, ...) @useme(i64 42)
store i64 %7, i64* %2
%8 = load i64, i64* %1
%9 = sdiv i64 %8, 3600
store i64 %9, i64* %3
%10 = load i64, i64* %1
%11 = sdiv i64 %10, 60
store i64 %11, i64* %4
%12 = load i64, i64* %2
%13 = icmp sge i64 %12, 86400
br i1 %13, label %14, label %21
14: ; preds = %0
store i64 59, i64* %4
%15 = load i64, i64* %3
%16 = add nsw i64 %15, -1
store i64 %16, i64* %3
%17 = load i64, i64* %3
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %14
store i64 23, i64* %3
br label %20
20: ; preds = %19, %14
br label %21
21: ; preds = %20, %0
%22 = load i64, i64* %3
%23 = load i64, i64* %4
%24 = call i64 (i64, ...) @useme(i64 %22, i64 %23)
ret void
}

LLVM IR (-O2):
define void @foo() {
%1 = tail call i64 (i64, ...) @useme(i64 41)
%2 = tail call i64 (i64, ...) @useme(i64 42)
%3 = tail call i64 (i64, ...) @useme(i64 42)
%4 = sdiv i64 %1, 3600
%5 = sdiv i64 %1, 60
%6 = icmp sgt i64 %3, 86399
%7 = add nsw i64 %4, -1
%8 = icmp slt i64 %1, 3600
%9 = select i1 %8, i64 23, i64 %7
%10 = select i1 %6, i64 %9, i64 %4
%11 = select i1 %6, i64 59, i64 %5
%12 = tail call i64 (i64, ...) @useme(i64 %10, i64 %11)
ret void
}