#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*/ d2xy(int, long, int *, int *);
scalar_t__ malloc(int);
long xy2d(int, int, int);
char *test_hilbert() {
  int N = 4;
  int *rows = (int *)malloc(N * sizeof(int));
  int *cols = (int *)malloc(N * sizeof(int));
  int nhilbert = 131072;
  long h;
  rows[0] = 5931;
  cols[0] = 91204;
  h = xy2d(nhilbert, rows[0], cols[0]);
  d2xy(nhilbert, h, &rows[1], &cols[1]);
  do {
    if (!(rows[0] == rows[1]))
      return "error, rows[0] != rows[1]";
  } while (0);
  do {
    if (!(cols[0] == cols[1]))
      return "error, cols[0] != cols[1]";
  } while (0);
  return 0;
}


x86 assembly (clang, -O0):
<test_hilbert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x4,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x20000,-0x24(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x172b,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x16444,(%rax)
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
call   1040 <xy2d@plt>
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
add    $0x4,%rdx
mov    -0x20(%rbp),%rcx
add    $0x4,%rcx
call   1030 <d2xy@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    -0x18(%rbp),%rcx
cmp    0x4(%rcx),%eax
je     11d7 <test_hilbert+0xa7>
lea    0xe32(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1211 <test_hilbert+0xe1>
jmp    11dc <test_hilbert+0xac>
jmp    11e1 <test_hilbert+0xb1>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    -0x20(%rbp),%rcx
cmp    0x4(%rcx),%eax
je     1204 <test_hilbert+0xd4>
lea    0xe1f(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1211 <test_hilbert+0xe1>
jmp    1209 <test_hilbert+0xd9>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_hilbert>:
push   %r14
push   %rbx
push   %rax
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
movl   $0x172b,(%rbx)
movl   $0x16444,(%rax)
mov    (%rbx),%esi
mov    $0x20000,%edi
mov    $0x16444,%edx
call   1040 <xy2d@plt>
lea    0x4(%rbx),%rdx
lea    0x4(%r14),%rcx
mov    $0x20000,%edi
mov    %rax,%rsi
call   1030 <d2xy@plt>
mov    (%rbx),%eax
cmp    0x4(%rbx),%eax
jne    119d <test_hilbert+0x6d>
mov    (%r14),%ecx
xor    %eax,%eax
cmp    0x4(%r14),%ecx
lea    0xe83(%rip),%rcx
cmovne %rcx,%rax
jmp    11a4 <test_hilbert+0x74>
lea    0xe5c(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [26 x i8] c"error, rows[0] != rows[1]\00"
@.str.1 = [26 x i8] c"error, cols[0] != cols[1]\00"
define i8* @test_hilbert() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i64
store i32 4, i32* %2
%7 = load i32, i32* %2
%8 = sext i32 %7 to i64
%9 = mul i64 %8, 4
%10 = trunc i64 %9 to i32
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i32*
store i32* %12, i32** %3
%13 = load i32, i32* %2
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 4
%16 = trunc i64 %15 to i32
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i32*
store i32* %18, i32** %4
store i32 131072, i32* %5
%19 = load i32*, i32** %3
%20 = getelementptr inbounds i32, i32* %19, i64 0
store i32 5931, i32* %20
%21 = load i32*, i32** %4
%22 = getelementptr inbounds i32, i32* %21, i64 0
store i32 91204, i32* %22
%23 = load i32, i32* %5
%24 = load i32*, i32** %3
%25 = getelementptr inbounds i32, i32* %24, i64 0
%26 = load i32, i32* %25
%27 = load i32*, i32** %4
%28 = getelementptr inbounds i32, i32* %27, i64 0
%29 = load i32, i32* %28
%30 = call i64 @xy2d(i32 %23, i32 %26, i32 %29)
store i64 %30, i64* %6
%31 = load i32, i32* %5
%32 = load i64, i64* %6
%33 = load i32*, i32** %3
%34 = getelementptr inbounds i32, i32* %33, i64 1
%35 = load i32*, i32** %4
%36 = getelementptr inbounds i32, i32* %35, i64 1
%37 = call i32 @d2xy(i32 %31, i64 %32, i32* %34, i32* %36)
br label %38
38: ; preds = %0
%39 = load i32*, i32** %3
%40 = getelementptr inbounds i32, i32* %39, i64 0
%41 = load i32, i32* %40
%42 = load i32*, i32** %3
%43 = getelementptr inbounds i32, i32* %42, i64 1
%44 = load i32, i32* %43
%45 = icmp eq i32 %41, %44
br i1 %45, label %47, label %46
46: ; preds = %38
store i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8** %1
br label %60
47: ; preds = %38
br label %48
48: ; preds = %47
br label %49
49: ; preds = %48
%50 = load i32*, i32** %4
%51 = getelementptr inbounds i32, i32* %50, i64 0
%52 = load i32, i32* %51
%53 = load i32*, i32** %4
%54 = getelementptr inbounds i32, i32* %53, i64 1
%55 = load i32, i32* %54
%56 = icmp eq i32 %52, %55
br i1 %56, label %58, label %57
57: ; preds = %49
store i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8** %1
br label %60
58: ; preds = %49
br label %59
59: ; preds = %58
store i8* null, i8** %1
br label %60
60: ; preds = %59, %57, %46
%61 = load i8*, i8** %1
ret i8* %61
}

LLVM IR (-O2):
@.str = [26 x i8] c"error, rows[0] != rows[1]\00"
@.str.1 = [26 x i8] c"error, cols[0] != cols[1]\00"
define i8* @test_hilbert() {
%1 = tail call i64 @malloc(i32 16)
%2 = inttoptr i64 %1 to i32*
%3 = tail call i64 @malloc(i32 16)
%4 = inttoptr i64 %3 to i32*
store i32 5931, i32* %2
store i32 91204, i32* %4
%5 = load i32, i32* %2
%6 = tail call i64 @xy2d(i32 131072, i32 %5, i32 91204)
%7 = getelementptr inbounds i32, i32* %2, i64 1
%8 = getelementptr inbounds i32, i32* %4, i64 1
%9 = tail call i32 @d2xy(i32 131072, i64 %6, i32* %7, i32* %8)
%10 = load i32, i32* %2
%11 = load i32, i32* %7
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %18
13: ; preds = %0
%14 = load i32, i32* %4
%15 = load i32, i32* %8
%16 = icmp eq i32 %14, %15
%17 = select i1 %16, i8* null, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0)
br label %18
18: ; preds = %13, %0
%19 = phi i8* [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), %0 ], [ %17, %13 ]
ret i8* %19
}