#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 float sift_keypoint_std;

/* Variables and functions */
int /*<<< orphan*/ free(float *);
scalar_t__ malloc(int);
float rand();
float *sift_compute_points(float *, int, int, int *);
int /*<<< orphan*/ sift_write_to_file(char *, float *, int);
int main(void) {
  int w = 512;
  int h = 512;
  float *x = (float *)malloc(w * h * sizeof(float));
  for (int i = 0; i < w * h; i++)
    x[i] = rand();
  int n;
  struct sift_keypoint_std *k = sift_compute_points(x, w, h, &n);
  sift_write_to_file("/dev/stdout", k, n);
  free(k);
  free(x);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x200,-0x8(%rbp)
movl   $0x200,-0xc(%rbp)
mov    -0x8(%rbp),%eax
imul   -0xc(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x8(%rbp),%ecx
imul   -0xc(%rbp),%ecx
cmp    %ecx,%eax
jge    11c0 <main+0x70>
mov    $0x0,%al
call   1070 <rand@plt>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118c <main+0x3c>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    -0x20(%rbp),%rcx
call   1040 <sift_compute_points@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%edx
lea    0xe1b(%rip),%rdi
call   1060 <sift_write_to_file@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0x100000,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <rand@plt>
movss  %xmm0,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    $0x40000,%rbx
jne    1170 <main+0x20>
lea    0xc(%rsp),%rcx
mov    %r15,%rdi
mov    $0x200,%esi
mov    $0x200,%edx
call   1040 <sift_compute_points@plt>
mov    %rax,%r14
mov    0xc(%rsp),%edx
lea    0xe51(%rip),%rdi
mov    %rax,%rsi
call   1060 <sift_write_to_file@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sift_keypoint_std = type opaque
@.str = [12 x i8] c"/dev/stdout\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca float*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.sift_keypoint_std*
store i32 0, i32* %1
store i32 512, i32* %2
store i32 512, i32* %3
%8 = load i32, i32* %2
%9 = load i32, i32* %3
%10 = mul nsw i32 %8, %9
%11 = sext i32 %10 to i64
%12 = mul i64 %11, 4
%13 = trunc i64 %12 to i32
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to float*
store float* %15, float** %4
store i32 0, i32* %5
br label %16
16: ; preds = %28, %0
%17 = load i32, i32* %5
%18 = load i32, i32* %2
%19 = load i32, i32* %3
%20 = mul nsw i32 %18, %19
%21 = icmp slt i32 %17, %20
br i1 %21, label %22, label %31
22: ; preds = %16
%23 = call float (...) @rand()
%24 = load float*, float** %4
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds float, float* %24, i64 %26
store float %23, float* %27
br label %28
28: ; preds = %22
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %16
31: ; preds = %16
%32 = load float*, float** %4
%33 = load i32, i32* %2
%34 = load i32, i32* %3
%35 = call float* @sift_compute_points(float* %32, i32 %33, i32 %34, i32* %6)
%36 = bitcast float* %35 to %struct.sift_keypoint_std*
store %struct.sift_keypoint_std* %36, %struct.sift_keypoint_std** %7
%37 = load %struct.sift_keypoint_std*, %struct.sift_keypoint_std** %7
%38 = bitcast %struct.sift_keypoint_std* %37 to float*
%39 = load i32, i32* %6
%40 = call i32 @sift_write_to_file(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), float* %38, i32 %39)
%41 = load %struct.sift_keypoint_std*, %struct.sift_keypoint_std** %7
%42 = bitcast %struct.sift_keypoint_std* %41 to float*
%43 = call i32 @free(float* %42)
%44 = load float*, float** %4
%45 = call i32 @free(float* %44)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/stdout\00"
define i32 @main() {
%1 = alloca i32
%2 = tail call i64 @malloc(i32 1048576)
%3 = inttoptr i64 %2 to float*
br label %11
4: ; preds = %11
%5 = bitcast i32* %1 to i8*
%6 = call float* @sift_compute_points(float* %3, i32 512, i32 512, i32* %1)
%7 = load i32, i32* %1
%8 = call i32 @sift_write_to_file(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), float* %6, i32 %7)
%9 = call i32 @free(float* %6)
%10 = call i32 @free(float* %3)
ret i32 0
11: ; preds = %0, %11
%12 = phi i64 [ 0, %0 ], [ %15, %11 ]
%13 = tail call float (...) @rand()
%14 = getelementptr inbounds float, float* %3, i64 %12
store float %13, float* %14
%15 = add nuw nsw i64 %12, 1
%16 = icmp eq i64 %15, 262144
br i1 %16, label %4, label %11
}