#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 tm_hour;
};

/* Variables and functions */
int /*<<< orphan*/ tm_decrement_day(struct tm *, int);
int /*<<< orphan*/ tm_increment_hour(struct tm *, int const);
struct tm *tm_decrement_hour(struct tm *changing_tm, const int quantity) {
  static const int hours_in_day = 24;
  if (quantity < 0) {
    tm_increment_hour(changing_tm, -quantity);
  } else {
    int num_hours = quantity;
    if (num_hours >= hours_in_day || num_hours > changing_tm->tm_hour) {
      int num_days = quantity / hours_in_day;
      num_hours -= num_days * hours_in_day;
      if (num_hours > changing_tm->tm_hour) {
        ++num_days;
        num_hours -= changing_tm->tm_hour;
        changing_tm->tm_hour = hours_in_day;
      }
      tm_decrement_day(changing_tm, num_days);
    }
    changing_tm->tm_hour -= num_hours;
  }
  return changing_tm;
}


x86 assembly (clang, -O0):
<tm_decrement_hour>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    114c <tm_decrement_hour+0x2c>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
sub    -0xc(%rbp),%esi
call   1040 <tm_increment_hour@plt>
jmp    11ce <tm_decrement_hour+0xae>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x18,-0x10(%rbp)
jge    116b <tm_decrement_hour+0x4b>
mov    -0x10(%rbp),%eax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%eax
jle    11c1 <tm_decrement_hour+0xa1>
mov    -0xc(%rbp),%eax
mov    $0x18,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
imul   $0x18,-0x14(%rbp),%ecx
mov    -0x10(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%eax
jle    11b5 <tm_decrement_hour+0x95>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movl   $0x18,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <tm_decrement_day@plt>
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
sub    %edx,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tm_decrement_hour>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
test   %esi,%esi
js     1173 <tm_decrement_hour+0x53>
mov    (%rbx),%eax
cmp    $0x17,%ebp
ja     1137 <tm_decrement_hour+0x17>
cmp    %ebp,%eax
jge    116d <tm_decrement_hour+0x4d>
mov    %ebp,%ecx
mov    $0xaaaaaaab,%esi
imul   %rcx,%rsi
shr    $0x24,%rsi
lea    0x0(,%rsi,8),%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%ebp
mov    %ebp,%ecx
sub    %eax,%ecx
jle    1163 <tm_decrement_hour+0x43>
add    $0x1,%esi
movl   $0x18,(%rbx)
mov    %ecx,%ebp
mov    %rbx,%rdi
call   1030 <tm_decrement_day@plt>
mov    (%rbx),%eax
sub    %ebp,%eax
mov    %eax,(%rbx)
jmp    117f <tm_decrement_hour+0x5f>
neg    %ebp
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <tm_increment_hour@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.tm = type { i32 }
define %struct.tm* @tm_decrement_hour(%struct.tm* returned %0, i32 %1) {
%3 = icmp slt i32 %1, 0
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = sub nsw i32 0, %1
%6 = tail call i32 @tm_increment_hour(%struct.tm* %0, i32 %5)
br label %32
7: ; preds = %2
%8 = icmp ugt i32 %1, 23
%9 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 0
%10 = load i32, i32* %9
%11 = icmp slt i32 %10, %1
%12 = select i1 %8, i1 true, i1 %11
br i1 %12, label %13, label %27
13: ; preds = %7
%14 = udiv i32 %1, 24
%15 = mul nsw i32 %14, -24
%16 = add nsw i32 %15, %1
%17 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 0
%18 = icmp sgt i32 %16, %10
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = add nuw nsw i32 %14, 1
%21 = sub nsw i32 %16, %10
store i32 24, i32* %17
br label %22
22: ; preds = %19, %13
%23 = phi i32 [ %21, %19 ], [ %16, %13 ]
%24 = phi i32 [ %20, %19 ], [ %14, %13 ]
%25 = tail call i32 @tm_decrement_day(%struct.tm* %0, i32 %24)
%26 = load i32, i32* %17
br label %27
27: ; preds = %7, %22
%28 = phi i32 [ %26, %22 ], [ %10, %7 ]
%29 = phi i32 [ %23, %22 ], [ %1, %7 ]
%30 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 0
%31 = sub nsw i32 %28, %29
store i32 %31, i32* %30
br label %32
32: ; preds = %27, %4
ret %struct.tm* %0
}