#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 */
typedef int uint8_t;
typedef scalar_t__ uint32_t;
typedef int uint16_t;
typedef int int16_t;

/* Variables and functions */
int /*<<< orphan*/ jdn_to_gr(scalar_t__, int *, int *, int *);
int /*<<< orphan*/ printf(char *, int, int, int, int, int, ...);
void stub1(scalar_t__, ...);
void stub2(scalar_t__ *, int16_t, uint8_t, uint16_t);
void stub3(int16_t, uint8_t, uint16_t, ...);
void stub4(int16_t, uint8_t, uint16_t, ...);
int tst_calendar(void (*cal_to_jdn)(uint32_t *, int16_t, uint8_t, uint16_t),
                 void (*jdn_to_cal)(uint32_t, int16_t *, uint8_t *, uint16_t *),
                 void (*cal_to_gr)(int16_t, uint8_t, uint16_t, int16_t *,
                                   uint8_t *, uint16_t *),
                 void (*gr_to_cal)(int16_t, uint8_t, uint16_t, int16_t *,
                                   uint8_t *, uint16_t *),
                 uint32_t min_jd, uint32_t max_jd) {
  uint32_t jdn = 0;
  uint32_t jdn2 = 0;
  for (jdn = min_jd; jdn < max_jd; ++jdn) {
    int16_t year;
    uint8_t month;
    uint16_t day;
    (*jdn_to_cal)(jdn, &year, &month, &day);
    (*cal_to_jdn)(&jdn2, year, month, day);
    if (jdn != jdn2) {
      printf("JDN conversion failed! %d != %d for %+04d-%02d-%02d\n", jdn, jdn2,
             year, month, day);
      return -1;
    }
    int16_t gy[2] = {0, 0};
    uint8_t gm[2] = {0, 0};
    uint16_t gd[2] = {0, 0};
    jdn_to_gr(jdn, &gy[0], &gm[0], &gd[0]);
    (*gr_to_cal)(gy[0], gm[0], gd[0], &year, &month, &day);
    (*cal_to_gr)(year, month, day, &gy[1], &gm[1], &gd[1]);
    if (gy[0] != gy[1] || gm[0] != gm[1] || gd[0] != gd[1]) {
      printf("Gregorian to calendar conversion failed! "
             "%04d-%02d-%02d != %04d-%02d-%02d!\n",
             gy[0], gm[0], gd[0], gy[1], gm[1], gd[1]);
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<tst_calendar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x38(%rbp),%rax
jge    12d3 <tst_calendar+0x1a3>
mov    -0x18(%rbp),%rax
mov    -0x40(%rbp),%rdi
lea    -0x4c(%rbp),%rsi
lea    -0x50(%rbp),%rdx
lea    -0x54(%rbp),%rcx
call   *%rax
mov    -0x10(%rbp),%rax
mov    -0x4c(%rbp),%esi
mov    -0x50(%rbp),%edx
mov    -0x54(%rbp),%ecx
lea    -0x48(%rbp),%rdi
call   *%rax
mov    -0x40(%rbp),%rax
cmp    -0x48(%rbp),%rax
je     11e1 <tst_calendar+0xb1>
mov    -0x40(%rbp),%rax
mov    %eax,%esi
mov    -0x48(%rbp),%rax
mov    %eax,%edx
mov    -0x4c(%rbp),%ecx
mov    -0x50(%rbp),%r8d
mov    -0x54(%rbp),%r9d
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12da <tst_calendar+0x1aa>
lea    -0x5c(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
lea    -0x64(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
lea    -0x6c(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    -0x40(%rbp),%rdi
lea    -0x5c(%rbp),%rsi
lea    -0x64(%rbp),%rdx
lea    -0x6c(%rbp),%rcx
call   1050 <jdn_to_gr@plt>
mov    -0x28(%rbp),%rax
mov    -0x5c(%rbp),%edi
mov    -0x64(%rbp),%esi
mov    -0x6c(%rbp),%edx
lea    -0x4c(%rbp),%rcx
lea    -0x50(%rbp),%r8
lea    -0x54(%rbp),%r9
call   *%rax
mov    -0x20(%rbp),%rax
mov    -0x4c(%rbp),%edi
mov    -0x50(%rbp),%esi
mov    -0x54(%rbp),%edx
lea    -0x5c(%rbp),%rcx
add    $0x4,%rcx
lea    -0x64(%rbp),%r8
add    $0x4,%r8
lea    -0x6c(%rbp),%r9
add    $0x4,%r9
call   *%rax
mov    -0x5c(%rbp),%eax
cmp    -0x58(%rbp),%eax
jne    128c <tst_calendar+0x15c>
mov    -0x64(%rbp),%eax
cmp    -0x60(%rbp),%eax
jne    128c <tst_calendar+0x15c>
mov    -0x6c(%rbp),%eax
cmp    -0x68(%rbp),%eax
je     12bd <tst_calendar+0x18d>
mov    -0x5c(%rbp),%esi
mov    -0x64(%rbp),%edx
mov    -0x6c(%rbp),%ecx
mov    -0x58(%rbp),%r8d
mov    -0x60(%rbp),%r9d
mov    -0x68(%rbp),%eax
lea    0xd8e(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12da <tst_calendar+0x1aa>
jmp    12c2 <tst_calendar+0x192>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    116b <tst_calendar+0x3b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tst_calendar>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
movq   $0x0,0x38(%rsp)
xor    %eax,%eax
cmp    %r9,%r8
jge    12b2 <tst_calendar+0x192>
mov    %r8,%r13
mov    %rcx,%r14
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    %rdi,0x60(%rsp)
lea    0x24(%rsp),%r12
lea    0x14(%rsp),%rax
lea    0x20(%rsp),%rcx
mov    %rsi,0x48(%rsp)
mov    %r9,0x40(%rsp)
mov    %rdx,0x58(%rsp)
mov    %r14,0x50(%rsp)
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r12,%r15
mov    %r12,%rsi
mov    %rax,%rbp
mov    %rax,%rdx
mov    %rcx,%r14
call   *%rbx
mov    0x24(%rsp),%esi
mov    0x14(%rsp),%edx
mov    0x20(%rsp),%ecx
lea    0x38(%rsp),%rdi
call   *0x60(%rsp)
mov    0x38(%rsp),%rdx
cmp    %rdx,%r13
jne    128e <tst_calendar+0x16e>
movq   $0x0,0x30(%rsp)
movq   $0x0,0x28(%rsp)
movq   $0x0,0x18(%rsp)
mov    %r13,%rdi
lea    0x30(%rsp),%rsi
lea    0x28(%rsp),%rdx
lea    0x18(%rsp),%rcx
call   1040 <jdn_to_gr@plt>
mov    0x30(%rsp),%edi
mov    0x28(%rsp),%esi
mov    0x18(%rsp),%edx
mov    %r15,%r12
mov    %r15,%rcx
mov    %rbp,%r8
mov    %r14,%r15
mov    %r14,%r9
mov    0x50(%rsp),%r14
call   *%r14
mov    0x24(%rsp),%edi
mov    0x14(%rsp),%esi
mov    0x20(%rsp),%edx
lea    0x34(%rsp),%rcx
lea    0x2c(%rsp),%r8
lea    0x1c(%rsp),%r9
mov    0x58(%rsp),%rbp
call   *%rbp
mov    0x30(%rsp),%esi
mov    0x34(%rsp),%r8d
mov    0x28(%rsp),%edx
mov    0x2c(%rsp),%r9d
cmp    %r8d,%esi
jne    127a <tst_calendar+0x15a>
cmp    %r9d,%edx
jne    1277 <tst_calendar+0x157>
mov    0x18(%rsp),%eax
cmp    0x1c(%rsp),%eax
jne    1277 <tst_calendar+0x157>
add    $0x1,%r13
mov    0x40(%rsp),%r9
cmp    %r13,%r9
mov    0x48(%rsp),%rbx
lea    0x14(%rsp),%rax
mov    %r15,%rcx
jne    1180 <tst_calendar+0x60>
xor    %eax,%eax
jmp    12b2 <tst_calendar+0x192>
mov    %esi,%r8d
mov    0x18(%rsp),%ecx
mov    0x1c(%rsp),%eax
mov    %eax,(%rsp)
lea    0xda9(%rip),%rdi
jmp    12a6 <tst_calendar+0x186>
mov    0x24(%rsp),%ecx
mov    0x14(%rsp),%r8d
mov    0x20(%rsp),%r9d
lea    0xd5d(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [53 x i8] c"JDN conversion failed! %d != %d for %+04d-%02d-%02d\0A\00"
@.str.1 = [76 x i8] c"Gregorian to calendar conversion failed! %04d-%02d-%02d != %04d-%02d-%02d!\0A\00"
define i32 @tst_calendar(void (i64*, i32, i32, i32)* %0, void (i64, i32*, i32*, i32*)* %1, void (i32, i32, i32, i32*, i32*, i32*)* %2, void (i32, i32, i32, i32*, i32*, i32*)* %3, i64 %4, i64 %5) {
%7 = alloca i32
%8 = alloca void (i64*, i32, i32, i32)*
%9 = alloca void (i64, i32*, i32*, i32*)*
%10 = alloca void (i32, i32, i32, i32*, i32*, i32*)*
%11 = alloca void (i32, i32, i32, i32*, i32*, i32*)*
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca [2 x i32]
%20 = alloca [2 x i32]
%21 = alloca [2 x i32]
store void (i64*, i32, i32, i32)* %0, void (i64*, i32, i32, i32)** %8
store void (i64, i32*, i32*, i32*)* %1, void (i64, i32*, i32*, i32*)** %9
store void (i32, i32, i32, i32*, i32*, i32*)* %2, void (i32, i32, i32, i32*, i32*, i32*)** %10
store void (i32, i32, i32, i32*, i32*, i32*)* %3, void (i32, i32, i32, i32*, i32*, i32*)** %11
store i64 %4, i64* %12
store i64 %5, i64* %13
store i64 0, i64* %14
store i64 0, i64* %15
%22 = load i64, i64* %12
store i64 %22, i64* %14
br label %23
23: ; preds = %101, %6
%24 = load i64, i64* %14
%25 = load i64, i64* %13
%26 = icmp slt i64 %24, %25
br i1 %26, label %27, label %104
27: ; preds = %23
%28 = load void (i64, i32*, i32*, i32*)*, void (i64, i32*, i32*, i32*)** %9
%29 = load i64, i64* %14
%30 = load void (i64*, i32, i32, i32)*, void (i64*, i32, i32, i32)** %8
%31 = load i32, i32* %16
%32 = load i32, i32* %17
%33 = load i32, i32* %18
%34 = load i64, i64* %14
%35 = load i64, i64* %15
%36 = icmp ne i64 %34, %35
br i1 %36, label %37, label %46
37: ; preds = %27
%38 = load i64, i64* %14
%39 = trunc i64 %38 to i32
%40 = load i64, i64* %15
%41 = trunc i64 %40 to i32
%42 = load i32, i32* %16
%43 = load i32, i32* %17
%44 = load i32, i32* %18
%45 = call i32 (i8*, i32, i32, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i32 %39, i32 %41, i32 %42, i32 %43, i32 %44)
store i32 -1, i32* %7
br label %105
46: ; preds = %27
%47 = bitcast [2 x i32]* %19 to i8*
%48 = bitcast [2 x i32]* %20 to i8*
%49 = bitcast [2 x i32]* %21 to i8*
%50 = load i64, i64* %14
%51 = getelementptr inbounds [2 x i32], [2 x i32]* %19, i64 0, i64 0
%52 = getelementptr inbounds [2 x i32], [2 x i32]* %20, i64 0, i64 0
%53 = getelementptr inbounds [2 x i32], [2 x i32]* %21, i64 0, i64 0
%54 = call i32 @jdn_to_gr(i64 %50, i32* %51, i32* %52, i32* %53)
%55 = load void (i32, i32, i32, i32*, i32*, i32*)*, void (i32, i32, i32, i32*, i32*, i32*)** %11
%56 = getelementptr inbounds [2 x i32], [2 x i32]* %19, i64 0, i64 0
%57 = load i32, i32* %56
%58 = getelementptr inbounds [2 x i32], [2 x i32]* %20, i64 0, i64 0
%59 = load i32, i32* %58
%60 = getelementptr inbounds [2 x i32], [2 x i32]* %21, i64 0, i64 0
%61 = load i32, i32* %60
%62 = load void (i32, i32, i32, i32*, i32*, i32*)*, void (i32, i32, i32, i32*, i32*, i32*)** %10
%63 = load i32, i32* %16
%64 = load i32, i32* %17
%65 = load i32, i32* %18
%66 = getelementptr inbounds [2 x i32], [2 x i32]* %19, i64 0, i64 1
%67 = getelementptr inbounds [2 x i32], [2 x i32]* %20, i64 0, i64 1
%68 = getelementptr inbounds [2 x i32], [2 x i32]* %21, i64 0, i64 1
%69 = getelementptr inbounds [2 x i32], [2 x i32]* %19, i64 0, i64 0
%70 = load i32, i32* %69
%71 = getelementptr inbounds [2 x i32], [2 x i32]* %19, i64 0, i64 1
%72 = load i32, i32* %71
%73 = icmp ne i32 %70, %72
br i1 %73, label %86, label %74
74: ; preds = %46
%75 = getelementptr inbounds [2 x i32], [2 x i32]* %20, i64 0, i64 0
%76 = load i32, i32* %75
%77 = getelementptr inbounds [2 x i32], [2 x i32]* %20, i64 0, i64 1
%78 = load i32, i32* %77
%79 = icmp ne i32 %76, %78
br i1 %79, label %86, label %80
80: ; preds = %74
%81 = getelementptr inbounds [2 x i32], [2 x i32]* %21, i64 0, i64 0
%82 = load i32, i32* %81
%83 = getelementptr inbounds [2 x i32], [2 x i32]* %21, i64 0, i64 1
%84 = load i32, i32* %83
%85 = icmp ne i32 %82, %84
br i1 %85, label %86, label %100
86: ; preds = %80, %74, %46
%87 = getelementptr inbounds [2 x i32], [2 x i32]* %19, i64 0, i64 0
%88 = load i32, i32* %87
%89 = getelementptr inbounds [2 x i32], [2 x i32]* %20, i64 0, i64 0
%90 = load i32, i32* %89
%91 = getelementptr inbounds [2 x i32], [2 x i32]* %21, i64 0, i64 0
%92 = load i32, i32* %91
%93 = getelementptr inbounds [2 x i32], [2 x i32]* %19, i64 0, i64 1
%94 = load i32, i32* %93
%95 = getelementptr inbounds [2 x i32], [2 x i32]* %20, i64 0, i64 1
%96 = load i32, i32* %95
%97 = getelementptr inbounds [2 x i32], [2 x i32]* %21, i64 0, i64 1
%98 = load i32, i32* %97
%99 = call i32 (i8*, i32, i32, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.1, i64 0, i64 0), i32 %88, i32 %90, i32 %92, i32 %94, i32 %96, i32 %98)
store i32 -1, i32* %7
br label %105
100: ; preds = %80
br label %101
101: ; preds = %100
%102 = load i64, i64* %14
%103 = add nsw i64 %102, 1
store i64 %103, i64* %14
br label %23
104: ; preds = %23
store i32 0, i32* %7
br label %105
105: ; preds = %104, %86, %37
%106 = load i32, i32* %7
ret i32 %106
}

LLVM IR (-O2):
@.str = [53 x i8] c"JDN conversion failed! %d != %d for %+04d-%02d-%02d\0A\00"
@.str.1 = [76 x i8] c"Gregorian to calendar conversion failed! %04d-%02d-%02d != %04d-%02d-%02d!\0A\00"
define i32 @tst_calendar(void (i64*, i32, i32, i32)* nocapture %0, void (i64, i32*, i32*, i32*)* nocapture %1, void (i32, i32, i32, i32*, i32*, i32*)* nocapture %2, void (i32, i32, i32, i32*, i32*, i32*)* nocapture %3, i64 %4, i64 %5) {
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = bitcast i64* %7 to i8*
store i64 0, i64* %7
%15 = icmp slt i64 %4, %5
br i1 %15, label %16, label %73
16: ; preds = %6
%17 = bitcast i64* %13 to [2 x i32]*
%18 = bitcast i64* %12 to [2 x i32]*
%19 = bitcast i64* %11 to [2 x i32]*
%20 = bitcast i32* %8 to i8*
%21 = bitcast i32* %9 to i8*
%22 = bitcast i32* %10 to i8*
%23 = bitcast i64* %11 to i8*
%24 = bitcast i64* %12 to i8*
%25 = bitcast i64* %13 to i8*
%26 = bitcast i64* %11 to i32*
%27 = bitcast i64* %12 to i32*
%28 = bitcast i64* %13 to i32*
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %19, i64 0, i64 1
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %18, i64 0, i64 1
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %17, i64 0, i64 1
br label %32
32: ; preds = %16, %70
%33 = phi i64 [ %4, %16 ], [ %71, %70 ]
%34 = load i32, i32* %8
%35 = load i32, i32* %9
%36 = load i32, i32* %10
%37 = load i64, i64* %7
%38 = icmp eq i64 %33, %37
br i1 %38, label %46, label %39
39: ; preds = %32
%40 = trunc i64 %33 to i32
%41 = trunc i64 %37 to i32
%42 = load i32, i32* %8
%43 = load i32, i32* %9
%44 = load i32, i32* %10
%45 = call i32 (i8*, i32, i32, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i32 %40, i32 %41, i32 %42, i32 %43, i32 %44)
br label %73
46: ; preds = %32
store i64 0, i64* %11
store i64 0, i64* %12
store i64 0, i64* %13
%47 = call i32 @jdn_to_gr(i64 %33, i32* %26, i32* %27, i32* %28)
%48 = load i32, i32* %26
%49 = load i32, i32* %27
%50 = load i32, i32* %28
%51 = load i32, i32* %8
%52 = load i32, i32* %9
%53 = load i32, i32* %10
%54 = load i32, i32* %26
%55 = load i32, i32* %29
%56 = icmp eq i32 %54, %55
%57 = load i32, i32* %27
%58 = load i32, i32* %30
br i1 %56, label %59, label %65
59: ; preds = %46
%60 = icmp eq i32 %57, %58
br i1 %60, label %61, label %65
61: ; preds = %59
%62 = load i32, i32* %28
%63 = load i32, i32* %31
%64 = icmp eq i32 %62, %63
br i1 %64, label %70, label %65
65: ; preds = %59, %61, %46
%66 = phi i32 [ %55, %46 ], [ %54, %61 ], [ %54, %59 ]
%67 = load i32, i32* %28
%68 = load i32, i32* %31
%69 = call i32 (i8*, i32, i32, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.1, i64 0, i64 0), i32 %54, i32 %57, i32 %67, i32 %66, i32 %58, i32 %68)
br label %73
70: ; preds = %61
%71 = add i64 %33, 1
%72 = icmp eq i64 %71, %5
br i1 %72, label %73, label %32
73: ; preds = %70, %6, %65, %39
%74 = phi i32 [ -1, %65 ], [ -1, %39 ], [ 0, %6 ], [ 0, %70 ]
ret i32 %74
}