#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 char_value(char const);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int);
int /*<<< orphan*/ strcat(char *, char *);
size_t strlen(char *);
char *get_representation(const char *digits, size_t len) {
  static char representation[(6 * 5) + 1];
  representation[0] = '\0';
  size_t min = 0;
  for (size_t i = 1; i < 5; i++)
    if (char_value(digits[i]) < char_value(digits[min]))
      min = i;
  for (size_t i = min; i < min + 5; i++) {
    size_t j = i % 5;
    char buf[7];
    sprintf(buf, "%d%d%d", char_value(digits[j]), char_value(digits[j + 5]),
            char_value(digits[((j + 1) % 5) + 5]));
    strcat(representation, buf);
  }
  if (strlen(representation) == len)
    return representation;
  else
    return NULL;
}


x86 assembly (clang, -O0):
<get_representation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movb   $0x0,0x2ef9(%rip)
movq   $0x0,-0x20(%rbp)
movq   $0x1,-0x28(%rbp)
cmpq   $0x5,-0x28(%rbp)
jae    11c2 <get_representation+0x82>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <char_value@plt>
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <char_value@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
cmp    %ecx,%eax
jge    11ac <get_representation+0x6c>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    11b1 <get_representation+0x71>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1167 <get_representation+0x27>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
add    $0x5,%rcx
cmp    %rcx,%rax
jae    1284 <get_representation+0x144>
mov    -0x30(%rbp),%rax
mov    $0x5,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x38(%rbp)
lea    -0x3f(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <char_value@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsbl 0x5(%rax,%rcx,1),%edi
call   1030 <char_value@plt>
mov    %eax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    $0x5,%ecx
xor    %edx,%edx
div    %rcx
mov    -0x60(%rbp),%rax
movsbl 0x5(%rax,%rdx,1),%edi
call   1030 <char_value@plt>
mov    -0x58(%rbp),%rdi
mov    -0x4c(%rbp),%edx
mov    -0x48(%rbp),%ecx
mov    %eax,%r8d
lea    0xda2(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x3f(%rbp),%rsi
lea    0x2de2(%rip),%rdi
call   1050 <strcat@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11ca <get_representation+0x8a>
lea    0x2dc5(%rip),%rdi
call   1040 <strlen@plt>
cmp    -0x18(%rbp),%rax
jne    12aa <get_representation+0x16a>
lea    0x2daf(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12b2 <get_representation+0x172>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_representation>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,0x18(%rsp)
mov    %rdi,%rbx
movb   $0x0,0x2ef3(%rip)
movsbl 0x1(%rdi),%edi
call   1030 <char_value@plt>
mov    %eax,%r14d
movsbl (%rbx),%edi
call   1030 <char_value@plt>
xor    %ebp,%ebp
cmp    %eax,%r14d
setl   %bpl
movsbl 0x2(%rbx),%edi
call   1030 <char_value@plt>
mov    %eax,%r14d
movsbl (%rbx,%rbp,1),%edi
call   1030 <char_value@plt>
cmp    %eax,%r14d
mov    $0x2,%r14d
cmovge %rbp,%r14
movsbl 0x3(%rbx),%edi
call   1030 <char_value@plt>
mov    %eax,%ebp
movsbl (%rbx,%r14,1),%edi
call   1030 <char_value@plt>
cmp    %eax,%ebp
mov    $0x3,%ebp
cmovge %r14,%rbp
movsbl 0x4(%rbx),%edi
call   1030 <char_value@plt>
mov    %eax,%r14d
movsbl (%rbx,%rbp,1),%edi
call   1030 <char_value@plt>
cmp    %eax,%r14d
mov    $0x4,%eax
cmovge %rbp,%rax
lea    0x6(%rax),%r13d
lea    0x1(%rax),%r15d
lea    (%rbx,%rax,1),%r12
mov    %rbx,0x20(%rsp)
lea    (%rbx,%rax,1),%r14
add    $0x5,%r14
mov    $0x5,%ecx
nopl   0x0(%rax,%rax,1)
mov    %rcx,0x28(%rsp)
mov    %rax,0x10(%rsp)
mov    0x10(%rsp),%rax
movabs $0xcccccccccccccccd,%rcx
cc cc cc
mul    %rcx
shr    $0x2,%rdx
lea    (%rdx,%rdx,4),%eax
mov    %r15d,%ecx
sub    %al,%cl
movzbl %cl,%ecx
imul   $0xcd,%ecx,%ecx
shr    $0xa,%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %r13d,%ebx
sub    %cl,%bl
sub    %al,%bl
lea    (%rdx,%rdx,4),%rax
mov    %r12,%rcx
sub    %rax,%rcx
mov    %r14,%rbp
sub    %rax,%rbp
movsbl (%rcx),%edi
call   1030 <char_value@plt>
mov    %eax,0xc(%rsp)
movsbl 0x0(%rbp),%edi
call   1030 <char_value@plt>
mov    %eax,%ebp
movzbl %bl,%eax
mov    0x20(%rsp),%rcx
movsbl (%rcx,%rax,1),%edi
call   1030 <char_value@plt>
lea    0x31(%rsp),%rbx
mov    %rbx,%rdi
lea    0xd7b(%rip),%rsi
mov    0xc(%rsp),%edx
mov    %ebp,%ecx
mov    %eax,%r8d
call   1060 <sprintf@plt>
lea    0x2db6(%rip),%rdi
mov    %rbx,%rsi
call   1050 <strcat@plt>
mov    0x28(%rsp),%rcx
mov    0x10(%rsp),%rax
add    $0x1,%rax
add    $0x1,%r13b
add    $0x1,%r15b
add    $0x1,%r12
add    $0x1,%r14
add    $0xffffffffffffffff,%rcx
jne    1200 <get_representation+0xc0>
lea    0x2d7f(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
xor    %ecx,%ecx
cmp    0x18(%rsp),%rax
cmove  %rbx,%rcx
mov    %rcx,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@get_representation.representation = internal global [31 x i8] zeroinitializer
@.str = [7 x i8] c"%d%d%d\00"
define i8* @get_representation(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca [7 x i8]
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8 0, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @get_representation.representation, i64 0, i64 0)
store i64 0, i64* %6
store i64 1, i64* %7
br label %11
11: ; preds = %29, %2
%12 = load i64, i64* %7
%13 = icmp ult i64 %12, 5
br i1 %13, label %14, label %32
14: ; preds = %11
%15 = load i8*, i8** %4
%16 = load i64, i64* %7
%17 = getelementptr inbounds i8, i8* %15, i64 %16
%18 = load i8, i8* %17
%19 = call i32 @char_value(i8 signext %18)
%20 = load i8*, i8** %4
%21 = load i64, i64* %6
%22 = getelementptr inbounds i8, i8* %20, i64 %21
%23 = load i8, i8* %22
%24 = call i32 @char_value(i8 signext %23)
%25 = icmp slt i32 %19, %24
br i1 %25, label %26, label %28
26: ; preds = %14
%27 = load i64, i64* %7
store i64 %27, i64* %6
br label %28
28: ; preds = %26, %14
br label %29
29: ; preds = %28
%30 = load i64, i64* %7
%31 = add i64 %30, 1
store i64 %31, i64* %7
br label %11
32: ; preds = %11
%33 = load i64, i64* %6
store i64 %33, i64* %8
br label %34
34: ; preds = %65, %32
%35 = load i64, i64* %8
%36 = load i64, i64* %6
%37 = add i64 %36, 5
%38 = icmp ult i64 %35, %37
br i1 %38, label %39, label %68
39: ; preds = %34
%40 = load i64, i64* %8
%41 = urem i64 %40, 5
store i64 %41, i64* %9
%42 = getelementptr inbounds [7 x i8], [7 x i8]* %10, i64 0, i64 0
%43 = load i8*, i8** %4
%44 = load i64, i64* %9
%45 = getelementptr inbounds i8, i8* %43, i64 %44
%46 = load i8, i8* %45
%47 = call i32 @char_value(i8 signext %46)
%48 = load i8*, i8** %4
%49 = load i64, i64* %9
%50 = add i64 %49, 5
%51 = getelementptr inbounds i8, i8* %48, i64 %50
%52 = load i8, i8* %51
%53 = call i32 @char_value(i8 signext %52)
%54 = load i8*, i8** %4
%55 = load i64, i64* %9
%56 = add i64 %55, 1
%57 = urem i64 %56, 5
%58 = add i64 %57, 5
%59 = getelementptr inbounds i8, i8* %54, i64 %58
%60 = load i8, i8* %59
%61 = call i32 @char_value(i8 signext %60)
%62 = call i32 @sprintf(i8* %42, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %47, i32 %53, i32 %61)
%63 = getelementptr inbounds [7 x i8], [7 x i8]* %10, i64 0, i64 0
%64 = call i32 @strcat(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @get_representation.representation, i64 0, i64 0), i8* %63)
br label %65
65: ; preds = %39
%66 = load i64, i64* %8
%67 = add i64 %66, 1
store i64 %67, i64* %8
br label %34
68: ; preds = %34
%69 = call i64 @strlen(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @get_representation.representation, i64 0, i64 0))
%70 = load i64, i64* %5
%71 = icmp eq i64 %69, %70
br i1 %71, label %72, label %73
72: ; preds = %68
store i8* getelementptr inbounds ([31 x i8], [31 x i8]* @get_representation.representation, i64 0, i64 0), i8** %3
br label %74
73: ; preds = %68
store i8* null, i8** %3
br label %74
74: ; preds = %73, %72
%75 = load i8*, i8** %3
ret i8* %75
}

LLVM IR (-O2):
@get_representation.representation = internal global [31 x i8] zeroinitializer
@.str = [7 x i8] c"%d%d%d\00"
define i8* @get_representation(i8* nocapture %0, i64 %1) {
%3 = alloca [7 x i8]
store i8 0, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @get_representation.representation, i64 0, i64 0)
%4 = getelementptr inbounds i8, i8* %0, i64 1
%5 = load i8, i8* %4
%6 = tail call i32 @char_value(i8 signext %5)
%7 = load i8, i8* %0
%8 = tail call i32 @char_value(i8 signext %7)
%9 = icmp slt i32 %6, %8
%10 = zext i1 %9 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 2
%12 = load i8, i8* %11
%13 = tail call i32 @char_value(i8 signext %12)
%14 = getelementptr inbounds i8, i8* %0, i64 %10
%15 = load i8, i8* %14
%16 = tail call i32 @char_value(i8 signext %15)
%17 = icmp slt i32 %13, %16
%18 = select i1 %17, i64 2, i64 %10
%19 = getelementptr inbounds i8, i8* %0, i64 3
%20 = load i8, i8* %19
%21 = tail call i32 @char_value(i8 signext %20)
%22 = getelementptr inbounds i8, i8* %0, i64 %18
%23 = load i8, i8* %22
%24 = tail call i32 @char_value(i8 signext %23)
%25 = icmp slt i32 %21, %24
%26 = select i1 %25, i64 3, i64 %18
%27 = getelementptr inbounds i8, i8* %0, i64 4
%28 = load i8, i8* %27
%29 = tail call i32 @char_value(i8 signext %28)
%30 = getelementptr inbounds i8, i8* %0, i64 %26
%31 = load i8, i8* %30
%32 = tail call i32 @char_value(i8 signext %31)
%33 = icmp slt i32 %29, %32
%34 = select i1 %33, i64 4, i64 %26
%35 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 0
%36 = add nuw nsw i64 %34, 4
br label %41
37: ; preds = %41
%38 = call i64 @strlen(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @get_representation.representation, i64 0, i64 0))
%39 = icmp eq i64 %38, %1
%40 = select i1 %39, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @get_representation.representation, i64 0, i64 0), i8* null
ret i8* %40
41: ; preds = %2, %41
%42 = phi i64 [ %34, %2 ], [ %61, %41 ]
%43 = urem i64 %42, 5
%44 = getelementptr inbounds i8, i8* %0, i64 %43
%45 = load i8, i8* %44
%46 = call i32 @char_value(i8 signext %45)
%47 = add nuw nsw i64 %43, 5
%48 = getelementptr inbounds i8, i8* %0, i64 %47
%49 = load i8, i8* %48
%50 = call i32 @char_value(i8 signext %49)
%51 = trunc i64 %43 to i8
%52 = add nuw nsw i8 %51, 1
%53 = urem i8 %52, 5
%54 = add nuw nsw i8 %53, 5
%55 = zext i8 %54 to i64
%56 = getelementptr inbounds i8, i8* %0, i64 %55
%57 = load i8, i8* %56
%58 = call i32 @char_value(i8 signext %57)
%59 = call i32 @sprintf(i8* %35, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %46, i32 %50, i32 %58)
%60 = call i32 @strcat(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @get_representation.representation, i64 0, i64 0), i8* %35)
%61 = add nuw nsw i64 %42, 1
%62 = icmp eq i64 %42, %36
br i1 %62, label %37, label %41
}