#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 */
typedef int /*<<< orphan*/ s_table;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
void sortTable(char str[], char table[], int width) {
  char s_table[27];
  char ch;
  int j, pos, p;
  memset(s_table, 0, sizeof(s_table));
  for (p = 0, ch = 'A'; ch <= 'Z'; ch++) {
    pos = (int)(strchr(str, ch) - str);
    if (pos >= 0) {
      for (j = pos; j < 26; j += width)
        s_table[p++] = table[j];
    }
  }
  strcpy(table, s_table);
}


x86 assembly (clang, -O0):
<sortTable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x1b,%edx
call   1050 <memset@plt>
movl   $0x0,-0x40(%rbp)
movb   $0x41,-0x31(%rbp)
movsbl -0x31(%rbp),%eax
cmp    $0x5a,%eax
jg     11dd <sortTable+0xad>
mov    -0x8(%rbp),%rdi
movsbl -0x31(%rbp),%esi
call   1040 <strchr@plt>
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jl     11cb <sortTable+0x9b>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x38(%rbp)
cmpl   $0x1a,-0x38(%rbp)
jge    11c6 <sortTable+0x96>
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x40(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x40(%rbp)
cltq
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0x14(%rbp),%eax
add    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
jmp    1192 <sortTable+0x62>
jmp    11cb <sortTable+0x9b>
jmp    11d0 <sortTable+0xa0>
mov    -0x31(%rbp),%al
add    $0x1,%al
mov    %al,-0x31(%rbp)
jmp    115e <sortTable+0x2e>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sortTable>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %edx,%r15d
mov    %rsi,%r12
mov    %rdi,%r14
mov    %rsp,%rdi
xor    %ebp,%ebp
xor    %esi,%esi
mov    $0x1b,%edx
call   1050 <memset@plt>
movslq %r15d,%rbx
mov    $0x41,%r15b
jmp    116a <sortTable+0x3a>
xchg   %ax,%ax
add    $0x1,%r15b
cmp    $0x5b,%r15b
je     11a9 <sortTable+0x79>
movsbl %r15b,%esi
mov    %r14,%rdi
call   1040 <strchr@plt>
sub    %r14,%rax
cmp    $0x19,%eax
ja     1160 <sortTable+0x30>
movslq %ebp,%rcx
cltq
add    %rsp,%rcx
cs nopw 0x0(%rax,%rax,1)
movzbl (%r12,%rax,1),%edx
mov    %dl,(%rcx)
add    %rbx,%rax
add    $0x1,%rcx
add    $0x1,%ebp
cmp    $0x1a,%rax
jl     1190 <sortTable+0x60>
jmp    1160 <sortTable+0x30>
mov    %rsp,%rsi
mov    %r12,%rdi
call   1030 <strcpy@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @sortTable(i8* %0, i8* %1, i32 %2) {
%4 = alloca [27 x i8]
%5 = getelementptr inbounds [27 x i8], [27 x i8]* %4, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 27)
%7 = ptrtoint i8* %0 to i64
%8 = sext i32 %2 to i64
br label %9
9: ; preds = %3, %32
%10 = phi i32 [ 0, %3 ], [ %33, %32 ]
%11 = phi i8 [ 65, %3 ], [ %34, %32 ]
%12 = call i8* @strchr(i8* dereferenceable(1) %0, i8 signext %11)
%13 = ptrtoint i8* %12 to i64
%14 = sub i64 %13, %7
%15 = trunc i64 %14 to i32
%16 = icmp ult i32 %15, 26
br i1 %16, label %17, label %32
17: ; preds = %9
%18 = sext i32 %10 to i64
%19 = shl i64 %14, 32
%20 = ashr exact i64 %19, 32
br label %21
21: ; preds = %17, %21
%22 = phi i64 [ %20, %17 ], [ %28, %21 ]
%23 = phi i64 [ %18, %17 ], [ %26, %21 ]
%24 = getelementptr inbounds i8, i8* %1, i64 %22
%25 = load i8, i8* %24
%26 = add nsw i64 %23, 1
%27 = getelementptr inbounds [27 x i8], [27 x i8]* %4, i64 0, i64 %23
store i8 %25, i8* %27
%28 = add i64 %22, %8
%29 = icmp slt i64 %28, 26
br i1 %29, label %21, label %30
30: ; preds = %21
%31 = trunc i64 %26 to i32
br label %32
32: ; preds = %30, %9
%33 = phi i32 [ %10, %9 ], [ %31, %30 ]
%34 = add nuw nsw i8 %11, 1
%35 = icmp eq i8 %34, 91
br i1 %35, label %36, label %9
36: ; preds = %32
%37 = call i32 @strcpy(i8* %1, i8* %5)
ret void
}