#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*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *RotateNinetyDegree(char *matrix) {
  char *buffer = (char *)malloc((strlen(matrix) + 1) * sizeof(char));
  strcpy(buffer, matrix);
  for (int row = 0; row < 4; row++) {
    for (int col = 0; col < 5 - 1; col++) {
      matrix[row * 5 + col] = buffer[(5 - col - 2) * 5 + row];
    }
  }
  free(buffer);
  return matrix;
}


x86 assembly (clang, -O0):
<RotateNinetyDegree>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    11e5 <RotateNinetyDegree+0xa5>
movl   $0x0,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jge    11d2 <RotateNinetyDegree+0x92>
mov    -0x10(%rbp),%rax
mov    $0x5,%ecx
sub    -0x18(%rbp),%ecx
sub    $0x2,%ecx
imul   $0x5,%ecx,%ecx
add    -0x14(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
imul   $0x5,-0x14(%rbp),%ecx
add    -0x18(%rbp),%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    118e <RotateNinetyDegree+0x4e>
jmp    11d7 <RotateNinetyDegree+0x97>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117d <RotateNinetyDegree+0x3d>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RotateNinetyDegree>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    0xf(%rbx),%al
mov    %al,(%r14)
mov    0xa(%rbx),%al
mov    %al,0x1(%r14)
mov    0x5(%rbx),%al
mov    %al,0x2(%r14)
mov    (%rbx),%al
mov    %al,0x3(%r14)
mov    0x10(%rbx),%al
mov    %al,0x5(%r14)
mov    0xb(%rbx),%al
mov    %al,0x6(%r14)
mov    0x6(%rbx),%al
mov    %al,0x7(%r14)
mov    0x1(%rbx),%al
mov    %al,0x8(%r14)
mov    0x11(%rbx),%al
mov    %al,0xa(%r14)
mov    0xc(%rbx),%al
mov    %al,0xb(%r14)
mov    0x7(%rbx),%al
mov    %al,0xc(%r14)
mov    0x2(%rbx),%al
mov    %al,0xd(%r14)
mov    0x12(%rbx),%al
mov    %al,0xf(%r14)
mov    0xd(%rbx),%al
mov    %al,0x10(%r14)
mov    0x8(%rbx),%al
mov    %al,0x11(%r14)
mov    0x3(%rbx),%al
mov    %al,0x12(%r14)
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i8* @RotateNinetyDegree(i8* returned %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 1
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @strcpy(i8* %5, i8* %0)
%7 = getelementptr inbounds i8, i8* %5, i64 15
%8 = load i8, i8* %7
store i8 %8, i8* %0
%9 = getelementptr inbounds i8, i8* %5, i64 10
%10 = load i8, i8* %9
%11 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %10, i8* %11
%12 = getelementptr inbounds i8, i8* %5, i64 5
%13 = load i8, i8* %12
%14 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %13, i8* %14
%15 = load i8, i8* %5
%16 = getelementptr inbounds i8, i8* %0, i64 3
store i8 %15, i8* %16
%17 = getelementptr inbounds i8, i8* %5, i64 16
%18 = load i8, i8* %17
%19 = getelementptr inbounds i8, i8* %0, i64 5
store i8 %18, i8* %19
%20 = getelementptr inbounds i8, i8* %5, i64 11
%21 = load i8, i8* %20
%22 = getelementptr inbounds i8, i8* %0, i64 6
store i8 %21, i8* %22
%23 = getelementptr inbounds i8, i8* %5, i64 6
%24 = load i8, i8* %23
%25 = getelementptr inbounds i8, i8* %0, i64 7
store i8 %24, i8* %25
%26 = getelementptr inbounds i8, i8* %5, i64 1
%27 = load i8, i8* %26
%28 = getelementptr inbounds i8, i8* %0, i64 8
store i8 %27, i8* %28
%29 = getelementptr inbounds i8, i8* %5, i64 17
%30 = load i8, i8* %29
%31 = getelementptr inbounds i8, i8* %0, i64 10
store i8 %30, i8* %31
%32 = getelementptr inbounds i8, i8* %5, i64 12
%33 = load i8, i8* %32
%34 = getelementptr inbounds i8, i8* %0, i64 11
store i8 %33, i8* %34
%35 = getelementptr inbounds i8, i8* %5, i64 7
%36 = load i8, i8* %35
%37 = getelementptr inbounds i8, i8* %0, i64 12
store i8 %36, i8* %37
%38 = getelementptr inbounds i8, i8* %5, i64 2
%39 = load i8, i8* %38
%40 = getelementptr inbounds i8, i8* %0, i64 13
store i8 %39, i8* %40
%41 = getelementptr inbounds i8, i8* %5, i64 18
%42 = load i8, i8* %41
%43 = getelementptr inbounds i8, i8* %0, i64 15
store i8 %42, i8* %43
%44 = getelementptr inbounds i8, i8* %5, i64 13
%45 = load i8, i8* %44
%46 = getelementptr inbounds i8, i8* %0, i64 16
store i8 %45, i8* %46
%47 = getelementptr inbounds i8, i8* %5, i64 8
%48 = load i8, i8* %47
%49 = getelementptr inbounds i8, i8* %0, i64 17
store i8 %48, i8* %49
%50 = getelementptr inbounds i8, i8* %5, i64 3
%51 = load i8, i8* %50
%52 = getelementptr inbounds i8, i8* %0, i64 18
store i8 %51, i8* %52
%53 = tail call i32 @free(i8* %5)
ret i8* %0
}