#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 */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
long date_to_long(int, int, int);
int /*<<< orphan*/ is_leap_year(int);
int /*<<< orphan*/ is_valid_date(long);
int /*<<< orphan*/ long_to_date(long, int *, int *, int *);
long subtract_a_day(long l) {
  int y, m, d;
  long_to_date(l, &y, &m, &d);
  --d;
  if (d < 1) {
    switch (m) {
    case 1:
      m = 12;
      d = 31;
      --y;
      break;
    case 2:
    case 4:
    case 6:
    case 8:
    case 9:
    case 11:
      --m;
      d = 31;
      break;
    case 5:
    case 7:
    case 10:
    case 12:
      --m;
      d = 30;
      break;
    case 3:
      m = 2;
      d = is_leap_year(y) ? 29 : 28;
      break;
    default:
      assert(0);
      break;
    }
  }
  long l2 = date_to_long(y, m, d);
  assert(is_valid_date(l2));
  return l2;
}


x86 assembly (clang, -O0):
<subtract_a_day>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
call   1060 <long_to_date@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jge    1228 <subtract_a_day+0xd8>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0xb,%eax
ja     121c <subtract_a_day+0xcc>
mov    -0x28(%rbp),%rax
lea    0xe5c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0xc,-0x10(%rbp)
movl   $0x1f,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1223 <subtract_a_day+0xd3>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
movl   $0x1f,-0x14(%rbp)
jmp    1223 <subtract_a_day+0xd3>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
movl   $0x1e,-0x14(%rbp)
jmp    1223 <subtract_a_day+0xd3>
movl   $0x2,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <is_leap_year@plt>
mov    %eax,%edx
mov    $0x1c,%eax
mov    $0x1d,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    1223 <subtract_a_day+0xd3>
xor    %edi,%edi
call   1040 <assert@plt>
jmp    1228 <subtract_a_day+0xd8>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1070 <date_to_long@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <is_valid_date@plt>
mov    %eax,%edi
call   1040 <assert@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<subtract_a_day>:
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
call   1060 <long_to_date@plt>
mov    0x4(%rsp),%eax
lea    -0x1(%rax),%edx
mov    %edx,0x4(%rsp)
cmp    $0x1,%eax
jg     1208 <subtract_a_day+0xb8>
mov    0x8(%rsp),%eax
add    $0xffffffff,%eax
cmp    $0xb,%eax
ja     11bf <subtract_a_day+0x6f>
lea    0xe70(%rip),%rcx
movslq (%rcx,%rax,4),%rdx
add    %rcx,%rdx
jmp    *%rdx
mov    %eax,0x8(%rsp)
movl   $0x1f,0x4(%rsp)
mov    $0x1f,%edx
jmp    1208 <subtract_a_day+0xb8>
mov    %eax,0x8(%rsp)
movl   $0x1e,0x4(%rsp)
mov    $0x1e,%edx
jmp    1208 <subtract_a_day+0xb8>
xor    %edi,%edi
call   1040 <assert@plt>
mov    0x4(%rsp),%edx
jmp    1208 <subtract_a_day+0xb8>
movl   $0xc,0x8(%rsp)
movl   $0x1f,0x4(%rsp)
addl   $0xffffffff,0xc(%rsp)
mov    $0x1f,%edx
jmp    1208 <subtract_a_day+0xb8>
movl   $0x2,0x8(%rsp)
mov    0xc(%rsp),%edi
call   1050 <is_leap_year@plt>
cmp    $0x1,%eax
mov    $0x1d,%edx
sbb    $0x0,%edx
mov    %edx,0x4(%rsp)
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
call   1070 <date_to_long@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <is_valid_date@plt>
mov    %eax,%edi
call   1040 <assert@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i64 @subtract_a_day(i64 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
store i64 %0, i64* %2
%7 = load i64, i64* %2
%8 = call i32 @long_to_date(i64 %7, i32* %3, i32* %4, i32* %5)
%9 = load i32, i32* %5
%10 = add nsw i32 %9, -1
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, 1
br i1 %12, label %13, label %33
13: ; preds = %1
%14 = load i32, i32* %4
switch i32 %14, label %30 [
i32 1, label %15
i32 2, label %18
i32 4, label %18
i32 6, label %18
i32 8, label %18
i32 9, label %18
i32 11, label %18
i32 5, label %21
i32 7, label %21
i32 10, label %21
i32 12, label %21
i32 3, label %24
]
15: ; preds = %13
store i32 12, i32* %4
store i32 31, i32* %5
%16 = load i32, i32* %3
%17 = add nsw i32 %16, -1
store i32 %17, i32* %3
br label %32
18: ; preds = %13, %13, %13, %13, %13, %13
%19 = load i32, i32* %4
%20 = add nsw i32 %19, -1
store i32 %20, i32* %4
store i32 31, i32* %5
br label %32
21: ; preds = %13, %13, %13, %13
%22 = load i32, i32* %4
%23 = add nsw i32 %22, -1
store i32 %23, i32* %4
store i32 30, i32* %5
br label %32
24: ; preds = %13
store i32 2, i32* %4
%25 = load i32, i32* %3
%26 = call i32 @is_leap_year(i32 %25)
%27 = icmp ne i32 %26, 0
%28 = zext i1 %27 to i64
%29 = select i1 %27, i32 29, i32 28
store i32 %29, i32* %5
br label %32
30: ; preds = %13
%31 = call i32 @assert(i32 0)
br label %32
32: ; preds = %30, %24, %21, %18, %15
br label %33
33: ; preds = %32, %1
%34 = load i32, i32* %3
%35 = load i32, i32* %4
%36 = load i32, i32* %5
%37 = call i64 @date_to_long(i32 %34, i32 %35, i32 %36)
store i64 %37, i64* %6
%38 = load i64, i64* %6
%39 = call i32 @is_valid_date(i64 %38)
%40 = call i32 @assert(i32 %39)
%41 = load i64, i64* %6
ret i64 %41
}

LLVM IR (-O2):
define i64 @subtract_a_day(i64 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = call i32 @long_to_date(i64 %0, i32* %2, i32* %3, i32* %4)
%9 = load i32, i32* %4
%10 = add nsw i32 %9, -1
store i32 %10, i32* %4
%11 = icmp slt i32 %9, 2
br i1 %11, label %12, label %29
12: ; preds = %1
%13 = load i32, i32* %3
switch i32 %13, label %26 [
i32 1, label %14
i32 2, label %17
i32 4, label %17
i32 6, label %17
i32 8, label %17
i32 9, label %17
i32 11, label %17
i32 5, label %19
i32 7, label %19
i32 10, label %19
i32 12, label %19
i32 3, label %21
]
14: ; preds = %12
store i32 12, i32* %3
store i32 31, i32* %4
%15 = load i32, i32* %2
%16 = add nsw i32 %15, -1
store i32 %16, i32* %2
br label %29
17: ; preds = %12, %12, %12, %12, %12, %12
%18 = add nsw i32 %13, -1
store i32 %18, i32* %3
store i32 31, i32* %4
br label %29
19: ; preds = %12, %12, %12, %12
%20 = add nsw i32 %13, -1
store i32 %20, i32* %3
store i32 30, i32* %4
br label %29
21: ; preds = %12
store i32 2, i32* %3
%22 = load i32, i32* %2
%23 = call i32 @is_leap_year(i32 %22)
%24 = icmp eq i32 %23, 0
%25 = select i1 %24, i32 28, i32 29
store i32 %25, i32* %4
br label %29
26: ; preds = %12
%27 = call i32 @assert(i32 0)
%28 = load i32, i32* %4
br label %29
29: ; preds = %14, %17, %19, %21, %26, %1
%30 = phi i32 [ 31, %14 ], [ 31, %17 ], [ 30, %19 ], [ %25, %21 ], [ %28, %26 ], [ %10, %1 ]
%31 = load i32, i32* %2
%32 = load i32, i32* %3
%33 = call i64 @date_to_long(i32 %31, i32 %32, i32 %30)
%34 = call i32 @is_valid_date(i64 %33)
%35 = call i32 @assert(i32 %34)
ret i64 %33
}