#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 */
char *get_representation(char *, int);
scalar_t__ is_magic(char *);
scalar_t__ next_permutation(char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(void) {
  char representation[16 + 1] = "";
  char digits[] = "123456789A";
  do {
    if (is_magic(digits)) {
      char *r_ptr = get_representation(digits, 16);
      if (r_ptr && strcmp(r_ptr, representation) > 0)
        strcpy(representation, r_ptr);
    }
  } while (next_permutation(digits));
  printf("%s\n", representation);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x11,%edx
call   1080 <memset@plt>
mov    0xe6a(%rip),%rax
mov    %rax,-0x2b(%rbp)
mov    0xe67(%rip),%ax
mov    %ax,-0x23(%rbp)
mov    0xe5f(%rip),%al
mov    %al,-0x21(%rbp)
lea    -0x2b(%rbp),%rdi
call   1050 <is_magic@plt>
cmp    $0x0,%rax
je     1207 <main+0x97>
lea    -0x2b(%rbp),%rdi
mov    $0x10,%esi
call   1060 <get_representation@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1202 <main+0x92>
mov    -0x38(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jle    1202 <main+0x92>
lea    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    1207 <main+0x97>
jmp    120c <main+0x9c>
lea    -0x2b(%rbp),%rdi
call   1030 <next_permutation@plt>
cmp    $0x0,%rax
jne    11ae <main+0x3e>
lea    -0x20(%rbp),%rsi
lea    0xde1(%rip),%rdi
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movb   $0x0,0x20(%rsp)
movabs $0x3837363534333231,%rax
36 37 38
mov    %rax,(%rsp)
movl   $0x413938,0x7(%rsp)
mov    %rsp,%r15
lea    0x10(%rsp),%r14
jmp    11ad <main+0x4d>
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1030 <next_permutation@plt>
test   %rax,%rax
je     11ec <main+0x8c>
mov    %r15,%rdi
call   1050 <is_magic@plt>
test   %rax,%rax
je     11a0 <main+0x40>
mov    %r15,%rdi
mov    $0x10,%esi
call   1060 <get_representation@plt>
test   %rax,%rax
je     11a0 <main+0x40>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jle    11a0 <main+0x40>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
jmp    11a0 <main+0x40>
lea    0xe18(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.digits = [11 x i8] c"123456789A\00"
@.str = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [17 x i8]
%3 = alloca [11 x i8]
%4 = alloca i8*
store i32 0, i32* %1
%5 = bitcast [17 x i8]* %2 to i8*
%6 = bitcast [11 x i8]* %3 to i8*
br label %7
7: ; preds = %27, %0
%8 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%9 = call i64 @is_magic(i8* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %26
11: ; preds = %7
%12 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%13 = call i8* @get_representation(i8* %12, i32 16)
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %25
16: ; preds = %11
%17 = load i8*, i8** %4
%18 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
%19 = call i64 @strcmp(i8* %17, i8* %18)
%20 = icmp sgt i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
%23 = load i8*, i8** %4
%24 = call i32 @strcpy(i8* %22, i8* %23)
br label %25
25: ; preds = %21, %16, %11
br label %26
26: ; preds = %25, %7
br label %27
27: ; preds = %26
%28 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%29 = call i64 @next_permutation(i8* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %7, label %31
31: ; preds = %27
%32 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
%33 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %32)
ret i32 0
}

LLVM IR (-O2):
@__const.main.digits = [11 x i8] c"123456789A\00"
@.str = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca [17 x i8]
%2 = alloca [11 x i8]
%3 = getelementptr inbounds [17 x i8], [17 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
br label %5
5: ; preds = %16, %0
%6 = call i64 @is_magic(i8* %4)
%7 = icmp eq i64 %6, 0
br i1 %7, label %16, label %8
8: ; preds = %5
%9 = call i8* @get_representation(i8* %4, i32 16)
%10 = icmp eq i8* %9, null
br i1 %10, label %16, label %11
11: ; preds = %8
%12 = call i64 @strcmp(i8* %9, i8* %3)
%13 = icmp sgt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 @strcpy(i8* %3, i8* %9)
br label %16
16: ; preds = %8, %11, %14, %5
%17 = call i64 @next_permutation(i8* %4)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %5
19: ; preds = %16
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %3)
ret i32 0
}