#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_mday;
  int tm_mon;
  int tm_year;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ is_leap_year(int);
int /*<<< orphan*/ tm_increment_day(struct tm *, int const);
struct tm *tm_decrement_day(struct tm *changing_tm, const int quantity) {
  enum months {
    january,
    february,
    march,
    april,
    may,
    june,
    july,
    august,
    september,
    october,
    november,
    december
  };
  if (quantity < 0) {
    tm_increment_day(changing_tm, -quantity);
  } else {
    int num_days = quantity;
    while (num_days--) {
      if (changing_tm->tm_mday > 1) {
        changing_tm->tm_mday -= 1;
      } else {
        switch (changing_tm->tm_mon) {
        case january:
          changing_tm->tm_mday = 31;
          changing_tm->tm_mon = 11;
          if (changing_tm->tm_year == 1) {
            changing_tm->tm_year = -1;
          } else {
            changing_tm->tm_year -= 1;
          }
          break;
        case february:
        case april:
        case june:
        case august:
        case september:
        case november:
          changing_tm->tm_mday = 31;
          changing_tm->tm_mon -= 1;
          break;
        case may:
        case july:
        case october:
        case december:
          changing_tm->tm_mday = 30;
          changing_tm->tm_mon -= 1;
          break;
        case march:
          if (is_leap_year(changing_tm->tm_year)) {
            changing_tm->tm_mday = 29;
          } else {
            changing_tm->tm_mday = 28;
          }
          changing_tm->tm_mon -= 1;
          break;
        default:
          assert(false);
          break;
        }
      }
    }
  }
  return changing_tm;
}


x86 assembly (clang, -O0):
<tm_decrement_day>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    115c <tm_decrement_day+0x2c>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
sub    -0xc(%rbp),%esi
call   1050 <tm_increment_day@plt>
jmp    128f <tm_decrement_day+0x15f>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x10(%rbp)
cmp    $0x0,%eax
je     128a <tm_decrement_day+0x15a>
mov    -0x8(%rbp),%rax
cmpl   $0x1,(%rax)
jle    1193 <tm_decrement_day+0x63>
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
sub    $0x1,%ecx
mov    %ecx,(%rax)
jmp    1285 <tm_decrement_day+0x155>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    %rax,-0x18(%rbp)
sub    $0xb,%rax
ja     1279 <tm_decrement_day+0x149>
mov    -0x18(%rbp),%rax
lea    0xe4d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%rax
movl   $0x1f,(%rax)
mov    -0x8(%rbp),%rax
movl   $0xb,0x4(%rax)
mov    -0x8(%rbp),%rax
cmpl   $0x1,0x8(%rax)
jne    11ef <tm_decrement_day+0xbf>
mov    -0x8(%rbp),%rax
movl   $0xffffffff,0x8(%rax)
jmp    11fc <tm_decrement_day+0xcc>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%ecx
sub    $0x1,%ecx
mov    %ecx,0x8(%rax)
jmp    1280 <tm_decrement_day+0x150>
mov    -0x8(%rbp),%rax
movl   $0x1f,(%rax)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%ecx
sub    $0x1,%ecx
mov    %ecx,0x4(%rax)
jmp    1280 <tm_decrement_day+0x150>
mov    -0x8(%rbp),%rax
movl   $0x1e,(%rax)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%ecx
sub    $0x1,%ecx
mov    %ecx,0x4(%rax)
jmp    1280 <tm_decrement_day+0x150>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%edi
call   1040 <is_leap_year@plt>
cmp    $0x0,%eax
je     125d <tm_decrement_day+0x12d>
mov    -0x8(%rbp),%rax
movl   $0x1d,(%rax)
jmp    1267 <tm_decrement_day+0x137>
mov    -0x8(%rbp),%rax
movl   $0x1c,(%rax)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%ecx
sub    $0x1,%ecx
mov    %ecx,0x4(%rax)
jmp    1280 <tm_decrement_day+0x150>
xor    %edi,%edi
call   1030 <assert@plt>
jmp    1285 <tm_decrement_day+0x155>
jmp    1162 <tm_decrement_day+0x32>
jmp    128f <tm_decrement_day+0x15f>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tm_decrement_day>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
test   %esi,%esi
js     11db <tm_decrement_day+0xab>
je     11e7 <tm_decrement_day+0xb7>
lea    0xeaf(%rip),%r14
movabs $0xb0000001f,%r15
jmp    1169 <tm_decrement_day+0x39>
nopl   (%rax)
add    $0xffffffff,%eax
mov    %eax,(%rbx)
test   %ebp,%ebp
je     11e7 <tm_decrement_day+0xb7>
add    $0xffffffff,%ebp
mov    (%rbx),%eax
cmp    $0x2,%eax
jge    1160 <tm_decrement_day+0x30>
mov    0x4(%rbx),%eax
cmp    $0xb,%rax
ja     119b <tm_decrement_day+0x6b>
movslq (%r14,%rax,4),%rcx
add    %r14,%rcx
jmp    *%rcx
movl   $0x1f,(%rbx)
jmp    1193 <tm_decrement_day+0x63>
movl   $0x1e,(%rbx)
add    $0xffffffff,%eax
mov    %eax,0x4(%rbx)
jmp    1165 <tm_decrement_day+0x35>
xor    %edi,%edi
call   1030 <assert@plt>
jmp    1165 <tm_decrement_day+0x35>
mov    %r15,(%rbx)
mov    0x8(%rbx),%eax
cmp    $0x1,%eax
jne    11d3 <tm_decrement_day+0xa3>
movl   $0xffffffff,0x8(%rbx)
jmp    1165 <tm_decrement_day+0x35>
mov    0x8(%rbx),%edi
call   1040 <is_leap_year@plt>
cmp    $0x1,%eax
mov    $0x1d,%eax
sbb    $0x0,%eax
mov    %eax,(%rbx)
addl   $0xffffffff,0x4(%rbx)
jmp    1165 <tm_decrement_day+0x35>
add    $0xffffffff,%eax
mov    %eax,0x8(%rbx)
jmp    1165 <tm_decrement_day+0x35>
neg    %ebp
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <tm_increment_day@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32 }
define %struct.tm* @tm_decrement_day(%struct.tm* %0, i32 %1) {
%3 = alloca %struct.tm*
%4 = alloca i32
%5 = alloca i32
store %struct.tm* %0, %struct.tm** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load %struct.tm*, %struct.tm** %3
%10 = load i32, i32* %4
%11 = sub nsw i32 0, %10
%12 = call i32 @tm_increment_day(%struct.tm* %9, i32 %11)
br label %87
13: ; preds = %2
%14 = load i32, i32* %4
store i32 %14, i32* %5
br label %15
15: ; preds = %85, %13
%16 = load i32, i32* %5
%17 = add nsw i32 %16, -1
store i32 %17, i32* %5
%18 = icmp ne i32 %16, 0
br i1 %18, label %19, label %86
19: ; preds = %15
%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 %22, 1
br i1 %23, label %24, label %29
24: ; preds = %19
%25 = load %struct.tm*, %struct.tm** %3
%26 = getelementptr inbounds %struct.tm, %struct.tm* %25, i32 0, i32 0
%27 = load i32, i32* %26
%28 = sub nsw i32 %27, 1
store i32 %28, i32* %26
br label %85
29: ; preds = %19
%30 = load %struct.tm*, %struct.tm** %3
%31 = getelementptr inbounds %struct.tm, %struct.tm* %30, i32 0, i32 1
%32 = load i32, i32* %31
switch i32 %32, label %82 [
i32 0, label %33
i32 1, label %51
i32 3, label %51
i32 5, label %51
i32 7, label %51
i32 8, label %51
i32 10, label %51
i32 4, label %58
i32 6, label %58
i32 9, label %58
i32 11, label %58
i32 2, label %65
]
33: ; preds = %29
%34 = load %struct.tm*, %struct.tm** %3
%35 = getelementptr inbounds %struct.tm, %struct.tm* %34, i32 0, i32 0
store i32 31, i32* %35
%36 = load %struct.tm*, %struct.tm** %3
%37 = getelementptr inbounds %struct.tm, %struct.tm* %36, i32 0, i32 1
store i32 11, i32* %37
%38 = load %struct.tm*, %struct.tm** %3
%39 = getelementptr inbounds %struct.tm, %struct.tm* %38, i32 0, i32 2
%40 = load i32, i32* %39
%41 = icmp eq i32 %40, 1
br i1 %41, label %42, label %45
42: ; preds = %33
%43 = load %struct.tm*, %struct.tm** %3
%44 = getelementptr inbounds %struct.tm, %struct.tm* %43, i32 0, i32 2
store i32 -1, i32* %44
br label %50
45: ; preds = %33
%46 = load %struct.tm*, %struct.tm** %3
%47 = getelementptr inbounds %struct.tm, %struct.tm* %46, i32 0, i32 2
%48 = load i32, i32* %47
%49 = sub nsw i32 %48, 1
store i32 %49, i32* %47
br label %50
50: ; preds = %45, %42
br label %84
51: ; preds = %29, %29, %29, %29, %29, %29
%52 = load %struct.tm*, %struct.tm** %3
%53 = getelementptr inbounds %struct.tm, %struct.tm* %52, i32 0, i32 0
store i32 31, i32* %53
%54 = load %struct.tm*, %struct.tm** %3
%55 = getelementptr inbounds %struct.tm, %struct.tm* %54, i32 0, i32 1
%56 = load i32, i32* %55
%57 = sub nsw i32 %56, 1
store i32 %57, i32* %55
br label %84
58: ; preds = %29, %29, %29, %29
%59 = load %struct.tm*, %struct.tm** %3
%60 = getelementptr inbounds %struct.tm, %struct.tm* %59, i32 0, i32 0
store i32 30, i32* %60
%61 = load %struct.tm*, %struct.tm** %3
%62 = getelementptr inbounds %struct.tm, %struct.tm* %61, i32 0, i32 1
%63 = load i32, i32* %62
%64 = sub nsw i32 %63, 1
store i32 %64, i32* %62
br label %84
65: ; preds = %29
%66 = load %struct.tm*, %struct.tm** %3
%67 = getelementptr inbounds %struct.tm, %struct.tm* %66, i32 0, i32 2
%68 = load i32, i32* %67
%69 = call i32 @is_leap_year(i32 %68)
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %65
%72 = load %struct.tm*, %struct.tm** %3
%73 = getelementptr inbounds %struct.tm, %struct.tm* %72, i32 0, i32 0
store i32 29, i32* %73
br label %77
74: ; preds = %65
%75 = load %struct.tm*, %struct.tm** %3
%76 = getelementptr inbounds %struct.tm, %struct.tm* %75, i32 0, i32 0
store i32 28, i32* %76
br label %77
77: ; preds = %74, %71
%78 = load %struct.tm*, %struct.tm** %3
%79 = getelementptr inbounds %struct.tm, %struct.tm* %78, i32 0, i32 1
%80 = load i32, i32* %79
%81 = sub nsw i32 %80, 1
store i32 %81, i32* %79
br label %84
82: ; preds = %29
%83 = call i32 @assert(i32 0)
br label %84
84: ; preds = %82, %77, %58, %51, %50
br label %85
85: ; preds = %84, %24
br label %15
86: ; preds = %15
br label %87
87: ; preds = %86, %8
%88 = load %struct.tm*, %struct.tm** %3
ret %struct.tm* %88
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32 }
define %struct.tm* @tm_decrement_day(%struct.tm* returned %0, i32 %1) {
%3 = icmp slt i32 %1, 0
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = icmp eq i32 %1, 0
br i1 %5, label %43, label %6
6: ; preds = %4
%7 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 0
%8 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 1
%9 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 2
br label %13
10: ; preds = %2
%11 = sub nsw i32 0, %1
%12 = tail call i32 @tm_increment_day(%struct.tm* %0, i32 %11)
br label %43
13: ; preds = %6, %41
%14 = phi i32 [ %1, %6 ], [ %15, %41 ]
%15 = add nsw i32 %14, -1
%16 = load i32, i32* %7
%17 = icmp sgt i32 %16, 1
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = add nsw i32 %16, -1
store i32 %19, i32* %7
br label %41
20: ; preds = %13
%21 = load i32, i32* %8
switch i32 %21, label %39 [
i32 0, label %22
i32 1, label %28
i32 3, label %28
i32 5, label %28
i32 7, label %28
i32 8, label %28
i32 10, label %28
i32 4, label %30
i32 6, label %30
i32 9, label %30
i32 11, label %30
i32 2, label %32
]
22: ; preds = %20
store i32 31, i32* %7
store i32 11, i32* %8
%23 = load i32, i32* %9
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 -1, i32* %9
br label %41
26: ; preds = %22
%27 = add nsw i32 %23, -1
store i32 %27, i32* %9
br label %41
28: ; preds = %20, %20, %20, %20, %20, %20
store i32 31, i32* %7
%29 = add nsw i32 %21, -1
store i32 %29, i32* %8
br label %41
30: ; preds = %20, %20, %20, %20
store i32 30, i32* %7
%31 = add nsw i32 %21, -1
store i32 %31, i32* %8
br label %41
32: ; preds = %20
%33 = load i32, i32* %9
%34 = tail call i32 @is_leap_year(i32 %33)
%35 = icmp eq i32 %34, 0
%36 = select i1 %35, i32 28, i32 29
store i32 %36, i32* %7
%37 = load i32, i32* %8
%38 = add nsw i32 %37, -1
store i32 %38, i32* %8
br label %41
39: ; preds = %20
%40 = tail call i32 @assert(i32 0)
br label %41
41: ; preds = %28, %30, %32, %39, %26, %25, %18
%42 = icmp eq i32 %15, 0
br i1 %42, label %43, label %13
43: ; preds = %41, %4, %10
ret %struct.tm* %0
}