#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*/ memset(char *, int /*<<< orphan*/, int);
char *diceroll(int n) {
  static char ln[4 + 1];
  int i, j;
  char c;
  memset(ln, 0, 4);
  ln[4] = '\0';
  i = 0;
  do {
    ln[i] = n % 6;
    n = n / 6;
    i++;
  } while (n > 0 && i < 4);
  for (j = 0; j < 4 / 2; j++) {
    c = ln[j];
    ln[j] = ln[4 - 1 - j] + '1';
    ln[4 - 1 - j] = c + '1';
  }
  return ln;
}


x86 assembly (clang, -O0):
<diceroll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    0x2f07(%rip),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
movb   $0x0,0x2ef8(%rip)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x6,%ecx
cltd
idiv   %ecx
movslq -0x8(%rbp),%rcx
lea    0x2ed7(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
mov    $0x6,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x4(%rbp)
mov    %al,-0xe(%rbp)
jle    1185 <diceroll+0x75>
cmpl   $0x4,-0x8(%rbp)
setl   %al
mov    %al,-0xe(%rbp)
mov    -0xe(%rbp),%al
test   $0x1,%al
jne    113c <diceroll+0x2c>
movl   $0x0,-0xc(%rbp)
cmpl   $0x2,-0xc(%rbp)
jge    1207 <diceroll+0xf7>
movslq -0xc(%rbp),%rcx
lea    0x2e7d(%rip),%rax
mov    (%rax,%rcx,1),%al
mov    %al,-0xd(%rbp)
mov    $0x3,%eax
sub    -0xc(%rbp),%eax
movslq %eax,%rcx
lea    0x2e65(%rip),%rax
movsbl (%rax,%rcx,1),%eax
add    $0x31,%eax
mov    %al,%dl
movslq -0xc(%rbp),%rcx
lea    0x2e51(%rip),%rax
mov    %dl,(%rax,%rcx,1)
movsbl -0xd(%rbp),%eax
add    $0x31,%eax
mov    %al,%dl
mov    $0x3,%eax
sub    -0xc(%rbp),%eax
movslq %eax,%rcx
lea    0x2e33(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1197 <diceroll+0x87>
lea    0x2e1b(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<diceroll>:
push   %rbx
mov    %edi,%ebx
lea    0x2f0f(%rip),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
movb   $0x0,0x2f00(%rip)
movslq %ebx,%rax
imul   $0x2aaaaaab,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,1),%edx
lea    (%rdx,%rdx,2),%edx
mov    %eax,%esi
sub    %edx,%esi
mov    %sil,0x2ed4(%rip)
cmp    $0x6,%eax
jl     1204 <diceroll+0xf4>
movslq %ecx,%rdx
imul   $0x2aaaaaab,%rdx,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
shr    $0x20,%rdx
add    %esi,%edx
add    %edx,%edx
lea    (%rdx,%rdx,2),%edx
sub    %edx,%ecx
mov    %cl,0x2ea8(%rip)
cmp    $0x24,%ebx
jl     1204 <diceroll+0xf4>
imul   $0x38e38e39,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
sar    $0x3,%ecx
add    %edx,%ecx
movslq %ecx,%rcx
imul   $0x2aaaaaab,%rcx,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
shr    $0x20,%rdx
add    %esi,%edx
add    %edx,%edx
lea    (%rdx,%rdx,2),%edx
sub    %edx,%ecx
mov    %cl,0x2e69(%rip)
cmp    $0xd8,%ebx
jl     1204 <diceroll+0xf4>
imul   $0x4bda12f7,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
sar    $0x6,%eax
add    %ecx,%eax
cltq
imul   $0x2aaaaaab,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
mov    %al,0x2e28(%rip)
lea    0x2e1e(%rip),%rax
mov    0x2e18(%rip),%cl
mov    0x2e15(%rip),%dl
add    $0x31,%dl
mov    %dl,0x2e09(%rip)
add    $0x31,%cl
mov    %cl,0x2e03(%rip)
mov    0x2dfb(%rip),%cl
mov    0x2df6(%rip),%dl
add    $0x31,%dl
mov    %dl,0x2dec(%rip)
add    $0x31,%cl
mov    %cl,0x2de4(%rip)
pop    %rbx
ret

LLVM IR (-O0):
@diceroll.ln = internal global [5 x i8] zeroinitializer
define i8* @diceroll(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
store i32 %0, i32* %2
%6 = call i32 @memset(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @diceroll.ln, i64 0, i64 0), i32 0, i32 4)
store i8 0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @diceroll.ln, i64 0, i64 4)
store i32 0, i32* %3
br label %7
7: ; preds = %24, %1
%8 = load i32, i32* %2
%9 = srem i32 %8, 6
%10 = trunc i32 %9 to i8
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [5 x i8], [5 x i8]* @diceroll.ln, i64 0, i64 %12
store i8 %10, i8* %13
%14 = load i32, i32* %2
%15 = sdiv i32 %14, 6
store i32 %15, i32* %2
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %18
18: ; preds = %7
%19 = load i32, i32* %2
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i32, i32* %3
%23 = icmp slt i32 %22, 4
br label %24
24: ; preds = %21, %18
%25 = phi i1 [ false, %18 ], [ %23, %21 ]
br i1 %25, label %7, label %26
26: ; preds = %24
store i32 0, i32* %4
br label %27
27: ; preds = %54, %26
%28 = load i32, i32* %4
%29 = icmp slt i32 %28, 2
br i1 %29, label %30, label %57
30: ; preds = %27
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [5 x i8], [5 x i8]* @diceroll.ln, i64 0, i64 %32
%34 = load i8, i8* %33
store i8 %34, i8* %5
%35 = load i32, i32* %4
%36 = sub nsw i32 3, %35
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [5 x i8], [5 x i8]* @diceroll.ln, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = add nsw i32 %40, 49
%42 = trunc i32 %41 to i8
%43 = load i32, i32* %4
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [5 x i8], [5 x i8]* @diceroll.ln, i64 0, i64 %44
store i8 %42, i8* %45
%46 = load i8, i8* %5
%47 = sext i8 %46 to i32
%48 = add nsw i32 %47, 49
%49 = trunc i32 %48 to i8
%50 = load i32, i32* %4
%51 = sub nsw i32 3, %50
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [5 x i8], [5 x i8]* @diceroll.ln, i64 0, i64 %52
store i8 %49, i8* %53
br label %54
54: ; preds = %30
%55 = load i32, i32* %4
%56 = add nsw i32 %55, 1
store i32 %56, i32* %4
br label %27
57: ; preds = %27
ret i8* getelementptr inbounds ([5 x i8], [5 x i8]* @diceroll.ln, i64 0, i64 0)
}

LLVM IR (-O2):
@diceroll.ln = internal global [5 x i8] zeroinitializer
define i8* @diceroll(i32 %0) {
%2 = tail call i32 @memset(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @diceroll.ln, i64 0, i64 0), i32 0, i32 4)
store i8 0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @diceroll.ln, i64 0, i64 4)
%3 = srem i32 %0, 6
%4 = sdiv i32 %0, 6
%5 = trunc i32 %3 to i8
store i8 %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @diceroll.ln, i64 0, i64 0)
%6 = icmp sgt i32 %0, 5
br i1 %6, label %7, label %20
7: ; preds = %1
%8 = srem i32 %4, 6
%9 = trunc i32 %8 to i8
store i8 %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @diceroll.ln, i64 0, i64 1)
%10 = icmp sgt i32 %0, 35
br i1 %10, label %11, label %20
11: ; preds = %7
%12 = sdiv i32 %0, 36
%13 = srem i32 %12, 6
%14 = trunc i32 %13 to i8
store i8 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @diceroll.ln, i64 0, i64 2)
%15 = icmp sgt i32 %0, 215
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = sdiv i32 %0, 216
%18 = srem i32 %17, 6
%19 = trunc i32 %18 to i8
store i8 %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @diceroll.ln, i64 0, i64 3)
br label %20
20: ; preds = %16, %11, %7, %1
%21 = load i8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @diceroll.ln, i64 0, i64 0)
%22 = load i8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @diceroll.ln, i64 0, i64 3)
%23 = add i8 %22, 49
store i8 %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @diceroll.ln, i64 0, i64 0)
%24 = add i8 %21, 49
store i8 %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @diceroll.ln, i64 0, i64 3)
%25 = load i8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @diceroll.ln, i64 0, i64 1)
%26 = load i8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @diceroll.ln, i64 0, i64 2)
%27 = add i8 %26, 49
store i8 %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @diceroll.ln, i64 0, i64 1)
%28 = add i8 %25, 49
store i8 %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @diceroll.ln, i64 0, i64 2)
ret i8* getelementptr inbounds ([5 x i8], [5 x i8]* @diceroll.ln, i64 0, i64 0)
}