#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*/ printf(char *, ...);
void print_index(int ndim, int *dims, int k) {
  if (ndim > 1) {
    print_index(ndim - 1, dims + 1, k / dims[0]);
    printf(",");
  }
  printf("%d", k % dims[0]);
}


x86 assembly (clang, -O0):
<print_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x1,-0x4(%rbp)
jle    1169 <print_index+0x49>
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
mov    -0x10(%rbp),%rsi
add    $0x4,%rsi
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
cltd
idivl  (%rcx)
mov    %eax,%edx
call   1040 <print_index@plt>
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
cltd
idivl  (%rcx)
mov    %edx,%esi
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_index>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%rbx
cmp    $0x2,%edi
jl     115a <print_index+0x2a>
add    $0xffffffff,%edi
lea    0x4(%rbx),%rsi
mov    %ebp,%eax
cltd
idivl  (%rbx)
mov    %eax,%edx
call   1050 <print_index@plt>
mov    $0x2c,%edi
call   1030 <putchar@plt>
mov    %ebp,%eax
cltd
idivl  (%rbx)
lea    0xe9a(%rip),%rdi
mov    %edx,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
@.str.1 = [3 x i8] c"%d\00"
define void @print_index(i32 %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%7 = load i32, i32* %4
%8 = icmp sgt i32 %7, 1
br i1 %8, label %9, label %20
9: ; preds = %3
%10 = load i32, i32* %4
%11 = sub nsw i32 %10, 1
%12 = load i32*, i32** %5
%13 = getelementptr inbounds i32, i32* %12, i64 1
%14 = load i32, i32* %6
%15 = load i32*, i32** %5
%16 = getelementptr inbounds i32, i32* %15, i64 0
%17 = load i32, i32* %16
%18 = sdiv i32 %14, %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %9, %3
%21 = load i32, i32* %6
%22 = load i32*, i32** %5
%23 = getelementptr inbounds i32, i32* %22, i64 0
%24 = load i32, i32* %23
%25 = srem i32 %21, %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %25)
ret void
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
define void @print_index(i32 %0, i32* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %11
5: ; preds = %3
%6 = add nsw i32 %0, -1
%7 = getelementptr inbounds i32, i32* %1, i64 1
%8 = load i32, i32* %1
%9 = sdiv i32 %2, %8
tail call void @print_index(i32 %6, i32* %7, i32 %9)
%10 = tail call i32 @putchar(i32 44)
br label %11
11: ; preds = %5, %3
%12 = load i32, i32* %1
%13 = srem i32 %2, %12
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %13)
ret void
}