#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 find_index(char *);
int /*<<< orphan*/ printf(char *, int, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
void cal_tzolkin(int h_day, char *h_mon, int h_year) {
  char *tzolkin_days[20] = {"imix",  "ik",    "akbal", "kan",   "chicchan",
                            "cimi",  "manik", "lamat", "muluk", "ok",
                            "chuen", "eb",    "ben",   "ix",    "mem",
                            "cib",   "caban", "eznab", "canac", "ahau"};
  int index, total_days, days_of_year, year;
  char day[10];
  total_days = h_year * 365 + find_index(h_mon) * 20 + h_day;
  year = total_days / 260;
  days_of_year = total_days % 260;
  strcpy(day, tzolkin_days[(days_of_year) % 20]);
  printf("%d %s %d\n", (days_of_year) % 13 + 1, day, year);
}


x86 assembly (clang, -O0):
<cal_tzolkin>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0xc0(%rbp),%rdi
lea    0x2c1d(%rip),%rsi
mov    $0xa0,%edx
call   1050 <memcpy@plt>
imul   $0x16d,-0x14(%rbp),%eax
mov    %eax,-0xe0(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <find_index@plt>
mov    %eax,%ecx
mov    -0xe0(%rbp),%eax
imul   $0x14,%ecx,%ecx
add    %ecx,%eax
add    -0x4(%rbp),%eax
mov    %eax,-0xc8(%rbp)
mov    -0xc8(%rbp),%eax
mov    $0x104,%ecx
cltd
idiv   %ecx
mov    %eax,-0xd0(%rbp)
mov    -0xc8(%rbp),%eax
mov    $0x104,%ecx
cltd
idiv   %ecx
mov    %edx,-0xcc(%rbp)
lea    -0xda(%rbp),%rdi
mov    -0xcc(%rbp),%eax
mov    $0x14,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    -0xc0(%rbp,%rax,8),%rsi
ff
call   1030 <strcpy@plt>
mov    -0xcc(%rbp),%eax
mov    $0xd,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
add    $0x1,%esi
lea    -0xda(%rbp),%rdx
mov    -0xd0(%rbp),%ecx
lea    0xe51(%rip),%rdi
call   1040 <printf@plt>
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cal_tzolkin>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebp
imul   $0x16d,%edx,%ebx
mov    %rsi,%rdi
call   1050 <find_index@plt>
lea    (%rax,%rax,4),%eax
add    %ebp,%ebx
lea    (%rbx,%rax,4),%eax
movslq %eax,%r15
imul   $0x7e07e07f,%r15,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x27,%rbx
add    %eax,%ebx
mov    %ebx,%eax
shl    $0x8,%eax
lea    (%rax,%rbx,4),%eax
sub    %eax,%r15d
movswl %r15w,%ebp
imul   $0x6667,%ebp,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x13,%eax
add    %ecx,%eax
shl    $0x2,%eax
lea    (%rax,%rax,4),%eax
mov    %r15d,%ecx
sub    %eax,%ecx
movswq %cx,%rax
lea    0xeca(%rip),%rcx
movslq (%rcx,%rax,4),%rsi
add    %rcx,%rsi
lea    0xe(%rsp),%r14
mov    %r14,%rdi
call   1030 <strcpy@plt>
imul   $0x4ec5,%ebp,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x12,%eax
add    %ecx,%eax
lea    (%rax,%rax,2),%ecx
lea    (%rax,%rcx,4),%eax
neg    %eax
add    %r15d,%eax
add    $0x1,%eax
movswl %ax,%esi
lea    0xe84(%rip),%rdi
mov    %r14,%rdx
mov    %ebx,%ecx
call   1040 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"imix\00"
@.str.1 = [3 x i8] c"ik\00"
@.str.2 = [6 x i8] c"akbal\00"
@.str.3 = [4 x i8] c"kan\00"
@.str.4 = [9 x i8] c"chicchan\00"
@.str.5 = [5 x i8] c"cimi\00"
@.str.6 = [6 x i8] c"manik\00"
@.str.7 = [6 x i8] c"lamat\00"
@.str.8 = [6 x i8] c"muluk\00"
@.str.9 = [3 x i8] c"ok\00"
@.str.10 = [6 x i8] c"chuen\00"
@.str.11 = [3 x i8] c"eb\00"
@.str.12 = [4 x i8] c"ben\00"
@.str.13 = [3 x i8] c"ix\00"
@.str.14 = [4 x i8] c"mem\00"
@.str.15 = [4 x i8] c"cib\00"
@.str.16 = [6 x i8] c"caban\00"
@.str.17 = [6 x i8] c"eznab\00"
@.str.18 = [6 x i8] c"canac\00"
@.str.19 = [5 x i8] c"ahau\00"
@__const.cal_tzolkin.tzolkin_days = [20 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.14, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.16, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.17, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.18, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.19, i32 0, i32 0)]
@.str.20 = [10 x i8] c"%d %s %d\0A\00"
define void @cal_tzolkin(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [20 x i8*]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [10 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%13 = bitcast [20 x i8*]* %7 to i8*
%14 = load i32, i32* %6
%15 = mul nsw i32 %14, 365
%16 = load i8*, i8** %5
%17 = call i32 @find_index(i8* %16)
%18 = mul nsw i32 %17, 20
%19 = add nsw i32 %15, %18
%20 = load i32, i32* %4
%21 = add nsw i32 %19, %20
store i32 %21, i32* %9
%22 = load i32, i32* %9
%23 = sdiv i32 %22, 260
store i32 %23, i32* %11
%24 = load i32, i32* %9
%25 = srem i32 %24, 260
store i32 %25, i32* %10
%26 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 0
%27 = load i32, i32* %10
%28 = srem i32 %27, 20
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [20 x i8*], [20 x i8*]* %7, i64 0, i64 %29
%31 = load i8*, i8** %30
%32 = call i32 @strcpy(i8* %26, i8* %31)
%33 = load i32, i32* %10
%34 = srem i32 %33, 13
%35 = add nsw i32 %34, 1
%36 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 0
%37 = load i32, i32* %11
%38 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.20, i64 0, i64 0), i32 %35, i8* %36, i32 %37)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"imix\00"
@.str.1 = [3 x i8] c"ik\00"
@.str.2 = [6 x i8] c"akbal\00"
@.str.3 = [4 x i8] c"kan\00"
@.str.4 = [9 x i8] c"chicchan\00"
@.str.5 = [5 x i8] c"cimi\00"
@.str.6 = [6 x i8] c"manik\00"
@.str.7 = [6 x i8] c"lamat\00"
@.str.8 = [6 x i8] c"muluk\00"
@.str.9 = [3 x i8] c"ok\00"
@.str.10 = [6 x i8] c"chuen\00"
@.str.11 = [3 x i8] c"eb\00"
@.str.12 = [4 x i8] c"ben\00"
@.str.13 = [3 x i8] c"ix\00"
@.str.14 = [4 x i8] c"mem\00"
@.str.15 = [4 x i8] c"cib\00"
@.str.16 = [6 x i8] c"caban\00"
@.str.17 = [6 x i8] c"eznab\00"
@.str.18 = [6 x i8] c"canac\00"
@.str.19 = [5 x i8] c"ahau\00"
@reltable.cal_tzolkin = [20 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str to i64), i64 ptrtoint ([20 x i32]* @reltable.cal_tzolkin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.1 to i64), i64 ptrtoint ([20 x i32]* @reltable.cal_tzolkin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.2 to i64), i64 ptrtoint ([20 x i32]* @reltable.cal_tzolkin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.3 to i64), i64 ptrtoint ([20 x i32]* @reltable.cal_tzolkin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.4 to i64), i64 ptrtoint ([20 x i32]* @reltable.cal_tzolkin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.5 to i64), i64 ptrtoint ([20 x i32]* @reltable.cal_tzolkin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.6 to i64), i64 ptrtoint ([20 x i32]* @reltable.cal_tzolkin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.7 to i64), i64 ptrtoint ([20 x i32]* @reltable.cal_tzolkin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.8 to i64), i64 ptrtoint ([20 x i32]* @reltable.cal_tzolkin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.9 to i64), i64 ptrtoint ([20 x i32]* @reltable.cal_tzolkin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.10 to i64), i64 ptrtoint ([20 x i32]* @reltable.cal_tzolkin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.11 to i64), i64 ptrtoint ([20 x i32]* @reltable.cal_tzolkin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.12 to i64), i64 ptrtoint ([20 x i32]* @reltable.cal_tzolkin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.13 to i64), i64 ptrtoint ([20 x i32]* @reltable.cal_tzolkin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.14 to i64), i64 ptrtoint ([20 x i32]* @reltable.cal_tzolkin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.15 to i64), i64 ptrtoint ([20 x i32]* @reltable.cal_tzolkin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.16 to i64), i64 ptrtoint ([20 x i32]* @reltable.cal_tzolkin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.17 to i64), i64 ptrtoint ([20 x i32]* @reltable.cal_tzolkin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.18 to i64), i64 ptrtoint ([20 x i32]* @reltable.cal_tzolkin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.19 to i64), i64 ptrtoint ([20 x i32]* @reltable.cal_tzolkin to i64)) to i32)]
@.str.20 = [10 x i8] c"%d %s %d\0A\00"
define void @cal_tzolkin(i32 %0, i8* %1, i32 %2) {
%4 = alloca [10 x i8]
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%6 = mul nsw i32 %2, 365
%7 = tail call i32 @find_index(i8* %1)
%8 = mul nsw i32 %7, 20
%9 = add i32 %6, %0
%10 = add i32 %9, %8
%11 = sdiv i32 %10, 260
%12 = srem i32 %10, 260
%13 = trunc i32 %12 to i16
%14 = srem i16 %13, 20
%15 = sext i16 %14 to i64
%16 = shl i64 %15, 2
%17 = call i8* @llvm.load.relative.i64(i8* bitcast ([20 x i32]* @reltable.cal_tzolkin to i8*), i64 %16)
%18 = call i32 @strcpy(i8* %5, i8* %17)
%19 = srem i16 %13, 13
%20 = add nsw i16 %19, 1
%21 = sext i16 %20 to i32
%22 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.20, i64 0, i64 0), i32 %21, i8* %5, i32 %11)
ret void
}