#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_decrement_day(struct tm *, int const);
struct tm *tm_increment_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_decrement_day(changing_tm, -quantity);
  } else {
    int num_days = quantity;
    while (num_days--) {
      changing_tm->tm_mday += 1;
      switch (changing_tm->tm_mon) {
      case january:
      case march:
      case may:
      case july:
      case august:
      case october:
        if (changing_tm->tm_mday > 31) {
          changing_tm->tm_mday = 1;
          changing_tm->tm_mon += 1;
        }
        break;
      case december:
        if (changing_tm->tm_mday > 31) {
          changing_tm->tm_mday = 1;
          changing_tm->tm_mon = 0;
          if (changing_tm->tm_year == -1) {
            changing_tm->tm_year = 1;
          } else {
            changing_tm->tm_year += 1;
          }
        }
        break;
      case april:
      case june:
      case september:
      case november:
        if (changing_tm->tm_mday > 30) {
          changing_tm->tm_mday = 1;
          changing_tm->tm_mon += 1;
        }
        break;
      case 1:
        if (changing_tm->tm_mday > 29) {
          changing_tm->tm_mday = 1;
          changing_tm->tm_mon += 1;
        } else if (changing_tm->tm_mday > 28 &&
                   !is_leap_year(changing_tm->tm_year)) {
          changing_tm->tm_mday = 1;
          changing_tm->tm_mon += 1;
        }
        break;
      default:
        assert(false);
        break;
      }
    }
  }
  return changing_tm;
}


x86 assembly (clang, -O0):
<tm_increment_day>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    115c <tm_increment_day+0x2c>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
sub    -0xc(%rbp),%esi
call   1030 <tm_decrement_day@plt>
jmp    12d0 <tm_increment_day+0x1a0>
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     12cb <tm_increment_day+0x19b>
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    %rax,-0x18(%rbp)
sub    $0xb,%rax
ja     12bf <tm_increment_day+0x18f>
mov    -0x18(%rbp),%rax
lea    0xe5f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%rax
cmpl   $0x1f,(%rax)
jle    11ce <tm_increment_day+0x9e>
mov    -0x8(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%ecx
add    $0x1,%ecx
mov    %ecx,0x4(%rax)
jmp    12c6 <tm_increment_day+0x196>
mov    -0x8(%rbp),%rax
cmpl   $0x1f,(%rax)
jle    1225 <tm_increment_day+0xf5>
mov    -0x8(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x8(%rbp),%rax
movl   $0x0,0x4(%rax)
mov    -0x8(%rbp),%rax
cmpl   $0xffffffff,0x8(%rax)
jne    1213 <tm_increment_day+0xe3>
mov    -0x8(%rbp),%rax
movl   $0x1,0x8(%rax)
jmp    1220 <tm_increment_day+0xf0>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%ecx
add    $0x1,%ecx
mov    %ecx,0x8(%rax)
jmp    1225 <tm_increment_day+0xf5>
jmp    12c6 <tm_increment_day+0x196>
mov    -0x8(%rbp),%rax
cmpl   $0x1e,(%rax)
jle    124e <tm_increment_day+0x11e>
mov    -0x8(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%ecx
add    $0x1,%ecx
mov    %ecx,0x4(%rax)
jmp    12c6 <tm_increment_day+0x196>
mov    -0x8(%rbp),%rax
cmpl   $0x1d,(%rax)
jle    127c <tm_increment_day+0x14c>
mov    -0x8(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%ecx
add    $0x1,%ecx
mov    %ecx,0x4(%rax)
jmp    12ba <tm_increment_day+0x18a>
mov    -0x8(%rbp),%rax
cmpl   $0x1c,(%rax)
jle    12b5 <tm_increment_day+0x185>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%edi
call   1050 <is_leap_year@plt>
cmp    $0x0,%eax
jne    12b5 <tm_increment_day+0x185>
mov    -0x8(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%ecx
add    $0x1,%ecx
mov    %ecx,0x4(%rax)
jmp    12ba <tm_increment_day+0x18a>
jmp    12c6 <tm_increment_day+0x196>
xor    %edi,%edi
call   1040 <assert@plt>
jmp    1162 <tm_increment_day+0x32>
jmp    12d0 <tm_increment_day+0x1a0>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tm_increment_day>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
test   %esi,%esi
js     1202 <tm_increment_day+0xd2>
je     120e <tm_increment_day+0xde>
lea    0xeaf(%rip),%r14
movabs $0x200000001,%r15
jmp    1174 <tm_increment_day+0x44>
nopl   (%rax)
movl   $0x1,(%rbx)
add    $0x1,%eax
mov    %eax,0x4(%rbx)
test   %ebp,%ebp
je     120e <tm_increment_day+0xde>
add    $0xffffffff,%ebp
mov    (%rbx),%ecx
mov    0x4(%rbx),%eax
lea    0x1(%rcx),%edx
mov    %edx,(%rbx)
cmp    $0xb,%rax
ja     11a7 <tm_increment_day+0x77>
movslq (%r14,%rax,4),%rdx
add    %r14,%rdx
jmp    *%rdx
cmp    $0x1f,%ecx
jge    1160 <tm_increment_day+0x30>
jmp    116c <tm_increment_day+0x3c>
nopw   0x0(%rax,%rax,1)
cmp    $0x1e,%ecx
jge    1160 <tm_increment_day+0x30>
jmp    116c <tm_increment_day+0x3c>
xor    %edi,%edi
call   1040 <assert@plt>
jmp    116c <tm_increment_day+0x3c>
cmp    $0x1d,%ecx
jl     11d6 <tm_increment_day+0xa6>
mov    %r15,(%rbx)
jmp    116c <tm_increment_day+0x3c>
cmp    $0x1f,%ecx
jl     116c <tm_increment_day+0x3c>
movq   $0x1,(%rbx)
mov    0x8(%rbx),%eax
cmp    $0xffffffff,%eax
je     11f6 <tm_increment_day+0xc6>
add    $0x1,%eax
mov    %eax,0x8(%rbx)
jmp    116c <tm_increment_day+0x3c>
cmp    $0x1c,%ecx
jne    116c <tm_increment_day+0x3c>
mov    0x8(%rbx),%edi
call   1050 <is_leap_year@plt>
test   %eax,%eax
jne    116c <tm_increment_day+0x3c>
movl   $0x1,(%rbx)
addl   $0x1,0x4(%rbx)
jmp    116c <tm_increment_day+0x3c>
movl   $0x1,0x8(%rbx)
jmp    116c <tm_increment_day+0x3c>
neg    %ebp
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <tm_decrement_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_increment_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_decrement_day(%struct.tm* %9, i32 %11)
br label %113
13: ; preds = %2
%14 = load i32, i32* %4
store i32 %14, i32* %5
br label %15
15: ; preds = %111, %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 %112
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 = add nsw i32 %22, 1
store i32 %23, i32* %21
%24 = load %struct.tm*, %struct.tm** %3
%25 = getelementptr inbounds %struct.tm, %struct.tm* %24, i32 0, i32 1
%26 = load i32, i32* %25
switch i32 %26, label %109 [
i32 0, label %27
i32 2, label %27
i32 4, label %27
i32 6, label %27
i32 7, label %27
i32 9, label %27
i32 11, label %40
i32 3, label %64
i32 5, label %64
i32 8, label %64
i32 10, label %64
i32 1, label %77
]
27: ; preds = %19, %19, %19, %19, %19, %19
%28 = load %struct.tm*, %struct.tm** %3
%29 = getelementptr inbounds %struct.tm, %struct.tm* %28, i32 0, i32 0
%30 = load i32, i32* %29
%31 = icmp sgt i32 %30, 31
br i1 %31, label %32, label %39
32: ; preds = %27
%33 = load %struct.tm*, %struct.tm** %3
%34 = getelementptr inbounds %struct.tm, %struct.tm* %33, i32 0, i32 0
store i32 1, i32* %34
%35 = load %struct.tm*, %struct.tm** %3
%36 = getelementptr inbounds %struct.tm, %struct.tm* %35, i32 0, i32 1
%37 = load i32, i32* %36
%38 = add nsw i32 %37, 1
store i32 %38, i32* %36
br label %39
39: ; preds = %32, %27
br label %111
40: ; preds = %19
%41 = load %struct.tm*, %struct.tm** %3
%42 = getelementptr inbounds %struct.tm, %struct.tm* %41, i32 0, i32 0
%43 = load i32, i32* %42
%44 = icmp sgt i32 %43, 31
br i1 %44, label %45, label %63
45: ; preds = %40
%46 = load %struct.tm*, %struct.tm** %3
%47 = getelementptr inbounds %struct.tm, %struct.tm* %46, i32 0, i32 0
store i32 1, i32* %47
%48 = load %struct.tm*, %struct.tm** %3
%49 = getelementptr inbounds %struct.tm, %struct.tm* %48, i32 0, i32 1
store i32 0, i32* %49
%50 = load %struct.tm*, %struct.tm** %3
%51 = getelementptr inbounds %struct.tm, %struct.tm* %50, i32 0, i32 2
%52 = load i32, i32* %51
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %57
54: ; preds = %45
%55 = load %struct.tm*, %struct.tm** %3
%56 = getelementptr inbounds %struct.tm, %struct.tm* %55, i32 0, i32 2
store i32 1, i32* %56
br label %62
57: ; preds = %45
%58 = load %struct.tm*, %struct.tm** %3
%59 = getelementptr inbounds %struct.tm, %struct.tm* %58, i32 0, i32 2
%60 = load i32, i32* %59
%61 = add nsw i32 %60, 1
store i32 %61, i32* %59
br label %62
62: ; preds = %57, %54
br label %63
63: ; preds = %62, %40
br label %111
64: ; preds = %19, %19, %19, %19
%65 = load %struct.tm*, %struct.tm** %3
%66 = getelementptr inbounds %struct.tm, %struct.tm* %65, i32 0, i32 0
%67 = load i32, i32* %66
%68 = icmp sgt i32 %67, 30
br i1 %68, label %69, label %76
69: ; preds = %64
%70 = load %struct.tm*, %struct.tm** %3
%71 = getelementptr inbounds %struct.tm, %struct.tm* %70, i32 0, i32 0
store i32 1, i32* %71
%72 = load %struct.tm*, %struct.tm** %3
%73 = getelementptr inbounds %struct.tm, %struct.tm* %72, i32 0, i32 1
%74 = load i32, i32* %73
%75 = add nsw i32 %74, 1
store i32 %75, i32* %73
br label %76
76: ; preds = %69, %64
br label %111
77: ; preds = %19
%78 = load %struct.tm*, %struct.tm** %3
%79 = getelementptr inbounds %struct.tm, %struct.tm* %78, i32 0, i32 0
%80 = load i32, i32* %79
%81 = icmp sgt i32 %80, 29
br i1 %81, label %82, label %89
82: ; preds = %77
%83 = load %struct.tm*, %struct.tm** %3
%84 = getelementptr inbounds %struct.tm, %struct.tm* %83, i32 0, i32 0
store i32 1, i32* %84
%85 = load %struct.tm*, %struct.tm** %3
%86 = getelementptr inbounds %struct.tm, %struct.tm* %85, i32 0, i32 1
%87 = load i32, i32* %86
%88 = add nsw i32 %87, 1
store i32 %88, i32* %86
br label %108
89: ; preds = %77
%90 = load %struct.tm*, %struct.tm** %3
%91 = getelementptr inbounds %struct.tm, %struct.tm* %90, i32 0, i32 0
%92 = load i32, i32* %91
%93 = icmp sgt i32 %92, 28
br i1 %93, label %94, label %107
94: ; preds = %89
%95 = load %struct.tm*, %struct.tm** %3
%96 = getelementptr inbounds %struct.tm, %struct.tm* %95, i32 0, i32 2
%97 = load i32, i32* %96
%98 = call i32 @is_leap_year(i32 %97)
%99 = icmp ne i32 %98, 0
br i1 %99, label %107, label %100
100: ; preds = %94
%101 = load %struct.tm*, %struct.tm** %3
%102 = getelementptr inbounds %struct.tm, %struct.tm* %101, i32 0, i32 0
store i32 1, i32* %102
%103 = load %struct.tm*, %struct.tm** %3
%104 = getelementptr inbounds %struct.tm, %struct.tm* %103, i32 0, i32 1
%105 = load i32, i32* %104
%106 = add nsw i32 %105, 1
store i32 %106, i32* %104
br label %107
107: ; preds = %100, %94, %89
br label %108
108: ; preds = %107, %82
br label %111
109: ; preds = %19
%110 = call i32 @assert(i32 0)
br label %111
111: ; preds = %109, %108, %76, %63, %39
br label %15
112: ; preds = %15
br label %113
113: ; preds = %112, %8
%114 = load %struct.tm*, %struct.tm** %3
ret %struct.tm* %114
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32 }
define %struct.tm* @tm_increment_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 %51, 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_decrement_day(%struct.tm* %0, i32 %11)
br label %51
13: ; preds = %6, %49
%14 = phi i32 [ %1, %6 ], [ %15, %49 ]
%15 = add nsw i32 %14, -1
%16 = load i32, i32* %7
%17 = add nsw i32 %16, 1
store i32 %17, i32* %7
%18 = load i32, i32* %8
switch i32 %18, label %47 [
i32 0, label %19
i32 2, label %19
i32 4, label %19
i32 6, label %19
i32 7, label %19
i32 9, label %19
i32 11, label %23
i32 3, label %31
i32 5, label %31
i32 8, label %31
i32 10, label %31
i32 1, label %35
]
19: ; preds = %13, %13, %13, %13, %13, %13
%20 = icmp sgt i32 %16, 30
br i1 %20, label %21, label %49
21: ; preds = %19
store i32 1, i32* %7
%22 = add nuw nsw i32 %18, 1
store i32 %22, i32* %8
br label %49
23: ; preds = %13
%24 = icmp sgt i32 %16, 30
br i1 %24, label %25, label %49
25: ; preds = %23
store i32 1, i32* %7
store i32 0, i32* %8
%26 = load i32, i32* %9
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %29
28: ; preds = %25
store i32 1, i32* %9
br label %49
29: ; preds = %25
%30 = add nuw nsw i32 %26, 1
store i32 %30, i32* %9
br label %49
31: ; preds = %13, %13, %13, %13
%32 = icmp sgt i32 %16, 29
br i1 %32, label %33, label %49
33: ; preds = %31
store i32 1, i32* %7
%34 = add nuw nsw i32 %18, 1
store i32 %34, i32* %8
br label %49
35: ; preds = %13
%36 = icmp sgt i32 %16, 28
br i1 %36, label %37, label %38
37: ; preds = %35
store i32 1, i32* %7
store i32 2, i32* %8
br label %49
38: ; preds = %35
%39 = icmp eq i32 %16, 28
br i1 %39, label %40, label %49
40: ; preds = %38
%41 = load i32, i32* %9
%42 = tail call i32 @is_leap_year(i32 %41)
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %49
44: ; preds = %40
store i32 1, i32* %7
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 1
store i32 %46, i32* %8
br label %49
47: ; preds = %13
%48 = tail call i32 @assert(i32 0)
br label %49
49: ; preds = %37, %44, %40, %38, %31, %33, %23, %29, %28, %19, %21, %47
%50 = icmp eq i32 %15, 0
br i1 %50, label %51, label %13
51: ; preds = %49, %4, %10
ret %struct.tm* %0
}