#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 get_motiflength_from_index(int);
int /*<<< orphan*/ sprintf(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void get_textmotif_from_index(int index, char *motif) {
  int temp_index;
  int rem;
  int i;
  int motif_length;
  if (index == 0) {
    sprintf(motif, "n");
  } else {
    motif_length = get_motiflength_from_index(index);
    switch (motif_length) {
    case 1:
      strcpy(motif, "n");
      break;
    case 2:
      strcpy(motif, "nn");
      break;
    case 3:
      strcpy(motif, "nnn");
      break;
    case 4:
      strcpy(motif, "nnnn");
      break;
    case 5:
      strcpy(motif, "nnnnn");
      break;
    case 6:
      strcpy(motif, "nnnnnn");
      break;
    case 7:
      strcpy(motif, "nnnnnnn");
      break;
    case 8:
      strcpy(motif, "nnnnnnnn");
      break;
    case 9:
      strcpy(motif, "nnnnnnnnn");
      break;
    case 10:
      strcpy(motif, "nnnnnnnnnn");
      break;
    }
    i = 1;
    temp_index = index;
    while (temp_index > 0) {
      rem = temp_index % 4;
      switch (rem) {
      case 0:
        temp_index -= 4;
        motif[motif_length - i] = 116;
        break;
      case 1:
        temp_index -= rem;
        motif[motif_length - i] = 97;
        break;
      case 2:
        temp_index -= rem;
        motif[motif_length - i] = 99;
        break;
      case 3:
        temp_index -= rem;
        motif[motif_length - i] = 103;
        break;
      }
      temp_index /= 4;
      i++;
    }
  }
}


x86 assembly (clang, -O0):
<get_textmotif_from_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    115e <get_textmotif_from_index+0x2e>
mov    -0x10(%rbp),%rdi
lea    0xeed(%rip),%rsi
call   1050 <sprintf@plt>
jmp    1350 <get_textmotif_from_index+0x220>
mov    -0x4(%rbp),%edi
call   1040 <get_motiflength_from_index@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x9,%eax
ja     125f <get_textmotif_from_index+0x12f>
mov    -0x28(%rbp),%rax
lea    0xe77(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
lea    0xea4(%rip),%rsi
call   1030 <strcpy@plt>
jmp    125f <get_textmotif_from_index+0x12f>
mov    -0x10(%rbp),%rdi
lea    0xe8e(%rip),%rsi
call   1030 <strcpy@plt>
jmp    125f <get_textmotif_from_index+0x12f>
mov    -0x10(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1030 <strcpy@plt>
jmp    125f <get_textmotif_from_index+0x12f>
mov    -0x10(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1030 <strcpy@plt>
jmp    125f <get_textmotif_from_index+0x12f>
mov    -0x10(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   1030 <strcpy@plt>
jmp    125f <get_textmotif_from_index+0x12f>
mov    -0x10(%rbp),%rdi
lea    0xe36(%rip),%rsi
call   1030 <strcpy@plt>
jmp    125f <get_textmotif_from_index+0x12f>
mov    -0x10(%rbp),%rdi
lea    0xe20(%rip),%rsi
call   1030 <strcpy@plt>
jmp    125f <get_textmotif_from_index+0x12f>
mov    -0x10(%rbp),%rdi
lea    0xe0a(%rip),%rsi
call   1030 <strcpy@plt>
jmp    125f <get_textmotif_from_index+0x12f>
mov    -0x10(%rbp),%rdi
lea    0xdf4(%rip),%rsi
call   1030 <strcpy@plt>
jmp    125f <get_textmotif_from_index+0x12f>
mov    -0x10(%rbp),%rdi
lea    0xdde(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    134b <get_textmotif_from_index+0x21b>
mov    -0x14(%rbp),%eax
mov    %eax,%edx
add    $0x3,%edx
test   %eax,%eax
mov    %eax,%ecx
cmovs  %edx,%ecx
and    $0xfffffffc,%ecx
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %rax,-0x30(%rbp)
sub    $0x3,%rax
ja     132f <get_textmotif_from_index+0x1ff>
mov    -0x30(%rbp),%rax
lea    0xd7f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x14(%rbp),%eax
sub    $0x4,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x74,(%rax,%rcx,1)
jmp    132f <get_textmotif_from_index+0x1ff>
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x61,(%rax,%rcx,1)
jmp    132f <get_textmotif_from_index+0x1ff>
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x63,(%rax,%rcx,1)
jmp    132f <get_textmotif_from_index+0x1ff>
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x67,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    126c <get_textmotif_from_index+0x13c>
jmp    1350 <get_textmotif_from_index+0x220>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_textmotif_from_index>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
test   %edi,%edi
je     119e <get_textmotif_from_index+0x7e>
mov    %edi,%ebx
call   1040 <get_motiflength_from_index@plt>
mov    %eax,%r15d
lea    -0x1(%r15),%eax
cmp    $0x9,%eax
ja     1157 <get_textmotif_from_index+0x37>
cltq
lea    0xec4(%rip),%rcx
movslq (%rcx,%rax,4),%rsi
add    %rcx,%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
test   %ebx,%ebx
jle    11a4 <get_textmotif_from_index+0x84>
movslq %r15d,%rax
add    %r14,%rax
add    $0xffffffffffffffff,%rax
lea    0xec8(%rip),%rdx
nopl   0x0(%rax)
mov    %ebx,%ecx
and    $0x3,%ecx
mov    (%rdx,%rcx,4),%esi
shl    $0x3,%ecx
mov    $0x67636174,%edi
shr    %cl,%edi
mov    %ebx,%ecx
add    %esi,%ecx
lea    0x3(%rbx,%rsi,1),%ebx
cmovns %ecx,%ebx
mov    %dil,(%rax)
sar    $0x2,%ebx
add    $0xffffffffffffffff,%rax
cmp    $0x3,%ecx
jg     1170 <get_textmotif_from_index+0x50>
jmp    11a4 <get_textmotif_from_index+0x84>
movw   $0x6e,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"n\00"
@.str.1 = [3 x i8] c"nn\00"
@.str.2 = [4 x i8] c"nnn\00"
@.str.3 = [5 x i8] c"nnnn\00"
@.str.4 = [6 x i8] c"nnnnn\00"
@.str.5 = [7 x i8] c"nnnnnn\00"
@.str.6 = [8 x i8] c"nnnnnnn\00"
@.str.7 = [9 x i8] c"nnnnnnnn\00"
@.str.8 = [10 x i8] c"nnnnnnnnn\00"
@.str.9 = [11 x i8] c"nnnnnnnnnn\00"
define void @get_textmotif_from_index(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%9 = load i32, i32* %3
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %102
14: ; preds = %2
%15 = load i32, i32* %3
%16 = call i32 @get_motiflength_from_index(i32 %15)
store i32 %16, i32* %8
%17 = load i32, i32* %8
switch i32 %17, label %48 [
i32 1, label %18
i32 2, label %21
i32 3, label %24
i32 4, label %27
i32 5, label %30
i32 6, label %33
i32 7, label %36
i32 8, label %39
i32 9, label %42
i32 10, label %45
]
18: ; preds = %14
%19 = load i8*, i8** %4
%20 = call i32 @strcpy(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %48
21: ; preds = %14
%22 = load i8*, i8** %4
%23 = call i32 @strcpy(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %48
24: ; preds = %14
%25 = load i8*, i8** %4
%26 = call i32 @strcpy(i8* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %48
27: ; preds = %14
%28 = load i8*, i8** %4
%29 = call i32 @strcpy(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %48
30: ; preds = %14
%31 = load i8*, i8** %4
%32 = call i32 @strcpy(i8* %31, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %48
33: ; preds = %14
%34 = load i8*, i8** %4
%35 = call i32 @strcpy(i8* %34, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %48
36: ; preds = %14
%37 = load i8*, i8** %4
%38 = call i32 @strcpy(i8* %37, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %48
39: ; preds = %14
%40 = load i8*, i8** %4
%41 = call i32 @strcpy(i8* %40, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
br label %48
42: ; preds = %14
%43 = load i8*, i8** %4
%44 = call i32 @strcpy(i8* %43, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0))
br label %48
45: ; preds = %14
%46 = load i8*, i8** %4
%47 = call i32 @strcpy(i8* %46, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
br label %48
48: ; preds = %14, %45, %42, %39, %36, %33, %30, %27, %24, %21, %18
store i32 1, i32* %7
%49 = load i32, i32* %3
store i32 %49, i32* %5
br label %50
50: ; preds = %96, %48
%51 = load i32, i32* %5
%52 = icmp sgt i32 %51, 0
br i1 %52, label %53, label %101
53: ; preds = %50
%54 = load i32, i32* %5
%55 = srem i32 %54, 4
store i32 %55, i32* %6
%56 = load i32, i32* %6
switch i32 %56, label %96 [
i32 0, label %57
i32 1, label %66
i32 2, label %76
i32 3, label %86
]
57: ; preds = %53
%58 = load i32, i32* %5
%59 = sub nsw i32 %58, 4
store i32 %59, i32* %5
%60 = load i8*, i8** %4
%61 = load i32, i32* %8
%62 = load i32, i32* %7
%63 = sub nsw i32 %61, %62
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %60, i64 %64
store i8 116, i8* %65
br label %96
66: ; preds = %53
%67 = load i32, i32* %6
%68 = load i32, i32* %5
%69 = sub nsw i32 %68, %67
store i32 %69, i32* %5
%70 = load i8*, i8** %4
%71 = load i32, i32* %8
%72 = load i32, i32* %7
%73 = sub nsw i32 %71, %72
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8, i8* %70, i64 %74
store i8 97, i8* %75
br label %96
76: ; preds = %53
%77 = load i32, i32* %6
%78 = load i32, i32* %5
%79 = sub nsw i32 %78, %77
store i32 %79, i32* %5
%80 = load i8*, i8** %4
%81 = load i32, i32* %8
%82 = load i32, i32* %7
%83 = sub nsw i32 %81, %82
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i8, i8* %80, i64 %84
store i8 99, i8* %85
br label %96
86: ; preds = %53
%87 = load i32, i32* %6
%88 = load i32, i32* %5
%89 = sub nsw i32 %88, %87
store i32 %89, i32* %5
%90 = load i8*, i8** %4
%91 = load i32, i32* %8
%92 = load i32, i32* %7
%93 = sub nsw i32 %91, %92
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds i8, i8* %90, i64 %94
store i8 103, i8* %95
br label %96
96: ; preds = %53, %86, %76, %66, %57
%97 = load i32, i32* %5
%98 = sdiv i32 %97, 4
store i32 %98, i32* %5
%99 = load i32, i32* %7
%100 = add nsw i32 %99, 1
store i32 %100, i32* %7
br label %50
101: ; preds = %50
br label %102
102: ; preds = %101, %11
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"n\00"
@.str.1 = [3 x i8] c"nn\00"
@.str.2 = [4 x i8] c"nnn\00"
@.str.3 = [5 x i8] c"nnnn\00"
@.str.4 = [6 x i8] c"nnnnn\00"
@.str.5 = [7 x i8] c"nnnnnn\00"
@.str.6 = [8 x i8] c"nnnnnnn\00"
@.str.7 = [9 x i8] c"nnnnnnnn\00"
@.str.8 = [10 x i8] c"nnnnnnnnn\00"
@.str.9 = [11 x i8] c"nnnnnnnnnn\00"
@reltable.get_textmotif_from_index = [10 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([2 x i8]* @.str to i64), i64 ptrtoint ([10 x i32]* @reltable.get_textmotif_from_index to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.1 to i64), i64 ptrtoint ([10 x i32]* @reltable.get_textmotif_from_index to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.2 to i64), i64 ptrtoint ([10 x i32]* @reltable.get_textmotif_from_index to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.3 to i64), i64 ptrtoint ([10 x i32]* @reltable.get_textmotif_from_index to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.4 to i64), i64 ptrtoint ([10 x i32]* @reltable.get_textmotif_from_index to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.5 to i64), i64 ptrtoint ([10 x i32]* @reltable.get_textmotif_from_index to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.6 to i64), i64 ptrtoint ([10 x i32]* @reltable.get_textmotif_from_index to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.7 to i64), i64 ptrtoint ([10 x i32]* @reltable.get_textmotif_from_index to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.8 to i64), i64 ptrtoint ([10 x i32]* @reltable.get_textmotif_from_index to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str.9 to i64), i64 ptrtoint ([10 x i32]* @reltable.get_textmotif_from_index to i64)) to i32)]
@switch.table.get_textmotif_from_index.10 = [4 x i32] [i32 -4, i32 -1, i32 -2, i32 -3]
define void @get_textmotif_from_index(i32 %0, i8* %1) {
%3 = icmp eq i32 %0, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = bitcast i8* %1 to i16*
store i16 110, i16* %5
br label %35
6: ; preds = %2
%7 = tail call i32 @get_motiflength_from_index(i32 %0)
%8 = add i32 %7, -1
%9 = icmp ult i32 %8, 10
br i1 %9, label %10, label %15
10: ; preds = %6
%11 = sext i32 %8 to i64
%12 = shl i64 %11, 2
%13 = call i8* @llvm.load.relative.i64(i8* bitcast ([10 x i32]* @reltable.get_textmotif_from_index to i8*), i64 %12)
%14 = tail call i32 @strcpy(i8* %1, i8* %13)
br label %15
15: ; preds = %6, %10
%16 = icmp sgt i32 %0, 0
br i1 %16, label %17, label %35
17: ; preds = %15
%18 = sext i32 %7 to i64
br label %19
19: ; preds = %17, %19
%20 = phi i64 [ 1, %17 ], [ %33, %19 ]
%21 = phi i32 [ %0, %17 ], [ %32, %19 ]
%22 = and i32 %21, 3
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds [4 x i32], [4 x i32]* @switch.table.get_textmotif_from_index.10, i64 0, i64 %23
%25 = load i32, i32* %24
%26 = shl nuw nsw i32 %22, 3
%27 = lshr i32 1734566260, %26
%28 = trunc i32 %27 to i8
%29 = add nsw i32 %21, %25
%30 = sub nsw i64 %18, %20
%31 = getelementptr inbounds i8, i8* %1, i64 %30
store i8 %28, i8* %31
%32 = sdiv i32 %29, 4
%33 = add nuw i64 %20, 1
%34 = icmp sgt i32 %29, 3
br i1 %34, label %19, label %35
35: ; preds = %19, %15, %4
ret void
}