#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*/ assert(int);
int /*<<< orphan*/ effective_transpose(int *, int *, int);
int /*<<< orphan*/ free(void *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ randomize(void *, int);
int /*<<< orphan*/ transpose(int *, int *, int);
void test(void) {
  int *d = (int *)malloc((sizeof(int) * 9973 * 9973));
  int *s = (int *)malloc((sizeof(int) * 9973 * 9973));
  randomize((void *)s, (sizeof(int) * 9973 * 9973));
  transpose(d, s, 9973);
  for (int i = 0; i < 9973; i++)
    for (int j = 0; j < 9973; j++)
      assert(s[i * 9973 + j] == d[j * 9973 + i]);
  memset(d, 0, (sizeof(int) * 9973 * 9973));
  effective_transpose(d, s, 9973);
  for (int i = 0; i < 9973; i++)
    for (int j = 0; j < 9973; j++)
      assert(s[i * 9973 + j] == d[j * 9973 + i]);
  free((void *)d);
  free((void *)s);
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x17b699e4,%edi
call   1080 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    $0x17b699e4,%edi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x17b699e4,%esi
call   1090 <randomize@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x26f5,%edx
call   1070 <transpose@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x26f5,-0x14(%rbp)
jge    1232 <test+0xc2>
movl   $0x0,-0x18(%rbp)
cmpl   $0x26f5,-0x18(%rbp)
jge    121f <test+0xaf>
mov    -0x10(%rbp),%rax
imul   $0x26f5,-0x14(%rbp),%ecx
add    -0x18(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
imul   $0x26f5,-0x18(%rbp),%edx
add    -0x14(%rbp),%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11cf <test+0x5f>
jmp    1224 <test+0xb4>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11bb <test+0x4b>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x17b699e4,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x26f5,%edx
call   1040 <effective_transpose@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x26f5,-0x1c(%rbp)
jge    12d2 <test+0x162>
movl   $0x0,-0x20(%rbp)
cmpl   $0x26f5,-0x20(%rbp)
jge    12bf <test+0x14f>
mov    -0x10(%rbp),%rax
imul   $0x26f5,-0x1c(%rbp),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
imul   $0x26f5,-0x20(%rbp),%edx
add    -0x1c(%rbp),%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    126f <test+0xff>
jmp    12c4 <test+0x154>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    125b <test+0xeb>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x17b699e4,%edi
call   1080 <malloc@plt>
mov    %rax,%r13
mov    $0x17b699e4,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x17b699e4,%esi
call   1090 <randomize@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0x26f5,%edx
call   1070 <transpose@plt>
xor    %r12d,%r12d
mov    %r15,%rbx
mov    %r13,(%rsp)
nopl   0x0(%rax)
mov    %r13,%rbp
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
mov    (%rbx,%r14,4),%eax
xor    %edi,%edi
cmp    0x0(%rbp),%eax
sete   %dil
call   1060 <assert@plt>
add    $0x1,%r14
add    $0x9bd4,%rbp
cmp    $0x26f5,%r14
jne    11d0 <test+0x60>
add    $0x1,%r12
add    $0x4,%r13
add    $0x9bd4,%rbx
cmp    $0x26f5,%r12
jne    11c0 <test+0x50>
xor    %r12d,%r12d
mov    (%rsp),%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x17b699e4,%edx
call   1050 <memset@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0x26f5,%edx
call   1040 <effective_transpose@plt>
mov    %r15,%r14
nopw   0x0(%rax,%rax,1)
mov    %r13,%rbp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r14,%rbx,4),%eax
xor    %edi,%edi
cmp    0x0(%rbp),%eax
sete   %dil
call   1060 <assert@plt>
add    $0x1,%rbx
add    $0x9bd4,%rbp
cmp    $0x26f5,%rbx
jne    1250 <test+0xe0>
add    $0x1,%r12
add    $0x4,%r13
add    $0x9bd4,%r14
cmp    $0x26f5,%r12
jne    1240 <test+0xd0>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @test() {
%1 = alloca i32*
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = call i64 @malloc(i32 397842916)
%8 = inttoptr i64 %7 to i32*
store i32* %8, i32** %1
%9 = call i64 @malloc(i32 397842916)
%10 = inttoptr i64 %9 to i32*
store i32* %10, i32** %2
%11 = load i32*, i32** %2
%12 = bitcast i32* %11 to i8*
%13 = call i32 @randomize(i8* %12, i32 397842916)
%14 = load i32*, i32** %1
%15 = load i32*, i32** %2
%16 = call i32 @transpose(i32* %14, i32* %15, i32 9973)
store i32 0, i32* %3
br label %17
17: ; preds = %48, %0
%18 = load i32, i32* %3
%19 = icmp slt i32 %18, 9973
br i1 %19, label %20, label %51
20: ; preds = %17
store i32 0, i32* %4
br label %21
21: ; preds = %44, %20
%22 = load i32, i32* %4
%23 = icmp slt i32 %22, 9973
br i1 %23, label %24, label %47
24: ; preds = %21
%25 = load i32*, i32** %2
%26 = load i32, i32* %3
%27 = mul nsw i32 %26, 9973
%28 = load i32, i32* %4
%29 = add nsw i32 %27, %28
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %25, i64 %30
%32 = load i32, i32* %31
%33 = load i32*, i32** %1
%34 = load i32, i32* %4
%35 = mul nsw i32 %34, 9973
%36 = load i32, i32* %3
%37 = add nsw i32 %35, %36
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %33, i64 %38
%40 = load i32, i32* %39
%41 = icmp eq i32 %32, %40
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
br label %44
44: ; preds = %24
%45 = load i32, i32* %4
%46 = add nsw i32 %45, 1
store i32 %46, i32* %4
br label %21
47: ; preds = %21
br label %48
48: ; preds = %47
%49 = load i32, i32* %3
%50 = add nsw i32 %49, 1
store i32 %50, i32* %3
br label %17
51: ; preds = %17
%52 = load i32*, i32** %1
%53 = call i32 @memset(i32* %52, i32 0, i32 397842916)
%54 = load i32*, i32** %1
%55 = load i32*, i32** %2
%56 = call i32 @effective_transpose(i32* %54, i32* %55, i32 9973)
store i32 0, i32* %5
br label %57
57: ; preds = %88, %51
%58 = load i32, i32* %5
%59 = icmp slt i32 %58, 9973
br i1 %59, label %60, label %91
60: ; preds = %57
store i32 0, i32* %6
br label %61
61: ; preds = %84, %60
%62 = load i32, i32* %6
%63 = icmp slt i32 %62, 9973
br i1 %63, label %64, label %87
64: ; preds = %61
%65 = load i32*, i32** %2
%66 = load i32, i32* %5
%67 = mul nsw i32 %66, 9973
%68 = load i32, i32* %6
%69 = add nsw i32 %67, %68
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i32, i32* %65, i64 %70
%72 = load i32, i32* %71
%73 = load i32*, i32** %1
%74 = load i32, i32* %6
%75 = mul nsw i32 %74, 9973
%76 = load i32, i32* %5
%77 = add nsw i32 %75, %76
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i32, i32* %73, i64 %78
%80 = load i32, i32* %79
%81 = icmp eq i32 %72, %80
%82 = zext i1 %81 to i32
%83 = call i32 @assert(i32 %82)
br label %84
84: ; preds = %64
%85 = load i32, i32* %6
%86 = add nsw i32 %85, 1
store i32 %86, i32* %6
br label %61
87: ; preds = %61
br label %88
88: ; preds = %87
%89 = load i32, i32* %5
%90 = add nsw i32 %89, 1
store i32 %90, i32* %5
br label %57
91: ; preds = %57
%92 = load i32*, i32** %1
%93 = bitcast i32* %92 to i8*
%94 = call i32 @free(i8* %93)
%95 = load i32*, i32** %2
%96 = bitcast i32* %95 to i8*
%97 = call i32 @free(i8* %96)
ret void
}

LLVM IR (-O2):
define void @test() {
%1 = tail call i64 @malloc(i32 397842916)
%2 = inttoptr i64 %1 to i32*
%3 = tail call i64 @malloc(i32 397842916)
%4 = inttoptr i64 %3 to i32*
%5 = inttoptr i64 %3 to i8*
%6 = tail call i32 @randomize(i8* %5, i32 397842916)
%7 = tail call i32 @transpose(i32* %2, i32* %4, i32 9973)
br label %8
8: ; preds = %0, %14
%9 = phi i64 [ 0, %0 ], [ %15, %14 ]
%10 = mul nuw nsw i64 %9, 9973
br label %17
11: ; preds = %14
%12 = tail call i32 @memset(i32* %2, i32 0, i32 397842916)
%13 = tail call i32 @effective_transpose(i32* %2, i32* %4, i32 9973)
br label %31
14: ; preds = %17
%15 = add nuw nsw i64 %9, 1
%16 = icmp eq i64 %15, 9973
br i1 %16, label %11, label %8
17: ; preds = %8, %17
%18 = phi i64 [ 0, %8 ], [ %29, %17 ]
%19 = add nuw nsw i64 %18, %10
%20 = getelementptr inbounds i32, i32* %4, i64 %19
%21 = load i32, i32* %20
%22 = mul nuw nsw i64 %18, 9973
%23 = add nuw nsw i64 %22, %9
%24 = getelementptr inbounds i32, i32* %2, i64 %23
%25 = load i32, i32* %24
%26 = icmp eq i32 %21, %25
%27 = zext i1 %26 to i32
%28 = tail call i32 @assert(i32 %27)
%29 = add nuw nsw i64 %18, 1
%30 = icmp eq i64 %29, 9973
br i1 %30, label %14, label %17
31: ; preds = %11, %38
%32 = phi i64 [ 0, %11 ], [ %39, %38 ]
%33 = mul nuw nsw i64 %32, 9973
br label %41
34: ; preds = %38
%35 = inttoptr i64 %1 to i8*
%36 = tail call i32 @free(i8* %35)
%37 = tail call i32 @free(i8* %5)
ret void
38: ; preds = %41
%39 = add nuw nsw i64 %32, 1
%40 = icmp eq i64 %39, 9973
br i1 %40, label %34, label %31
41: ; preds = %31, %41
%42 = phi i64 [ 0, %31 ], [ %53, %41 ]
%43 = add nuw nsw i64 %42, %33
%44 = getelementptr inbounds i32, i32* %4, i64 %43
%45 = load i32, i32* %44
%46 = mul nuw nsw i64 %42, 9973
%47 = add nuw nsw i64 %46, %32
%48 = getelementptr inbounds i32, i32* %2, i64 %47
%49 = load i32, i32* %48
%50 = icmp eq i32 %45, %49
%51 = zext i1 %50 to i32
%52 = tail call i32 @assert(i32 %51)
%53 = add nuw nsw i64 %42, 1
%54 = icmp eq i64 %53, 9973
br i1 %54, label %38, label %41
}