#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*/ fatal_error(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(float *);
float *io_png_read_f32_gray(char *, size_t *, size_t *);
float *sift_compute_features(float *, size_t, size_t, int *);
int /*<<< orphan*/ sift_write_to_file(char *, float *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc != 2) {
    fprintf(stderr, "usage:\n./sift_basic image.png\n");
    return -1;
  }
  size_t w, h;
  float *x = io_png_read_f32_gray(argv[1], &w, &h);
  if (!x)
    fatal_error("File \"%s\" not found.", argv[1]);
  for (int i = 0; i < w * h; i++)
    x[i] /= 256.;
  int n;
  struct sift_keypoint_std *k = sift_compute_features(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    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a1 <main+0x41>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe78(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126f <main+0x10f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1070 <io_png_read_f32_gray@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11d9 <main+0x79>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe53(%rip),%rdi
call   1050 <fatal_error@plt>
movl   $0x0,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
mov    -0x18(%rbp),%rcx
imul   -0x20(%rbp),%rcx
cmp    %rcx,%rax
jae    122a <main+0xca>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdf1(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11e0 <main+0x80>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1080 <sift_compute_features@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%edx
lea    0xdeb(%rip),%rdi
call   1060 <sift_write_to_file@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    11c1 <main+0x61>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1070 <io_png_read_f32_gray@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    119a <main+0x3a>
mov    0x8(%r14),%rsi
lea    0xe9e(%rip),%rdi
call   1050 <fatal_error@plt>
mov    0x10(%rsp),%rsi
mov    0x8(%rsp),%rdx
mov    %rdx,%r9
imul   %rsi,%r9
test   %r9,%r9
je     1297 <main+0x137>
cmp    $0x8,%r9
jae    11e0 <main+0x80>
xor    %ecx,%ecx
jmp    1276 <main+0x116>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
lea    0xe43(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    12cc <main+0x16c>
mov    %r9,%rcx
and    $0xfffffffffffffff8,%rcx
lea    -0x8(%rcx),%rax
mov    %rax,%r8
shr    $0x3,%r8
add    $0x1,%r8
test   %rax,%rax
je     12d4 <main+0x174>
mov    %r8,%rax
and    $0xfffffffffffffffe,%rax
xor    %edi,%edi
movaps 0xdf1(%rip),%xmm0
nop
movups (%rbx,%rdi,4),%xmm1
movups 0x10(%rbx,%rdi,4),%xmm2
movups 0x20(%rbx,%rdi,4),%xmm3
movups 0x30(%rbx,%rdi,4),%xmm4
mulps  %xmm0,%xmm1
mulps  %xmm0,%xmm2
movups %xmm1,(%rbx,%rdi,4)
movups %xmm2,0x10(%rbx,%rdi,4)
mulps  %xmm0,%xmm3
mulps  %xmm0,%xmm4
movups %xmm3,0x20(%rbx,%rdi,4)
movups %xmm4,0x30(%rbx,%rdi,4)
add    $0x10,%rdi
add    $0xfffffffffffffffe,%rax
jne    1210 <main+0xb0>
test   $0x1,%r8b
je     1271 <main+0x111>
movups (%rbx,%rdi,4),%xmm0
movups 0x10(%rbx,%rdi,4),%xmm1
movaps 0xd9e(%rip),%xmm2
mulps  %xmm2,%xmm0
mulps  %xmm2,%xmm1
movups %xmm0,(%rbx,%rdi,4)
movups %xmm1,0x10(%rbx,%rdi,4)
cmp    %rcx,%r9
je     1297 <main+0x137>
movss  0xd92(%rip),%xmm0
xchg   %ax,%ax
movss  (%rbx,%rcx,4),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,(%rbx,%rcx,4)
add    $0x1,%rcx
cmp    %rcx,%r9
jne    1280 <main+0x120>
lea    0x4(%rsp),%rcx
mov    %rbx,%rdi
call   1080 <sift_compute_features@plt>
mov    %rax,%r14
mov    0x4(%rsp),%edx
lea    0xd96(%rip),%rdi
mov    %rax,%rsi
call   1060 <sift_write_to_file@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
xor    %edi,%edi
test   $0x1,%r8b
jne    1252 <main+0xf2>
jmp    1271 <main+0x111>

LLVM IR (-O0):
%struct.sift_keypoint_std = type opaque
@stderr = global i32 0
@.str = [31 x i8] c"usage:\0A./sift_basic image.png\0A\00"
@.str.1 = [21 x i8] c"File \22%s\22 not found.\00"
@.str.2 = [12 x i8] c"/dev/stdout\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca float*
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.sift_keypoint_std*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %64
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call float* @io_png_read_f32_gray(i8* %20, i64* %6, i64* %7)
store float* %21, float** %8
%22 = load float*, float** %8
%23 = icmp ne float* %22, null
br i1 %23, label %29, label %24
24: ; preds = %17
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @fatal_error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %24, %17
store i32 0, i32* %9
br label %30
30: ; preds = %46, %29
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = load i64, i64* %6
%34 = load i64, i64* %7
%35 = mul i64 %33, %34
%36 = icmp ult i64 %32, %35
br i1 %36, label %37, label %49
37: ; preds = %30
%38 = load float*, float** %8
%39 = load i32, i32* %9
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds float, float* %38, i64 %40
%42 = load float, float* %41
%43 = fpext float %42 to double
%44 = fdiv double %43, 2.560000e+02
%45 = fptrunc double %44 to float
store float %45, float* %41
br label %46
46: ; preds = %37
%47 = load i32, i32* %9
%48 = add nsw i32 %47, 1
store i32 %48, i32* %9
br label %30
49: ; preds = %30
%50 = load float*, float** %8
%51 = load i64, i64* %6
%52 = load i64, i64* %7
%53 = call float* @sift_compute_features(float* %50, i64 %51, i64 %52, i32* %10)
%54 = bitcast float* %53 to %struct.sift_keypoint_std*
store %struct.sift_keypoint_std* %54, %struct.sift_keypoint_std** %11
%55 = load %struct.sift_keypoint_std*, %struct.sift_keypoint_std** %11
%56 = bitcast %struct.sift_keypoint_std* %55 to float*
%57 = load i32, i32* %10
%58 = call i32 @sift_write_to_file(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), float* %56, i32 %57)
%59 = load %struct.sift_keypoint_std*, %struct.sift_keypoint_std** %11
%60 = bitcast %struct.sift_keypoint_std* %59 to float*
%61 = call i32 @free(float* %60)
%62 = load float*, float** %8
%63 = call i32 @free(float* %62)
store i32 0, i32* %3
br label %64
64: ; preds = %49, %14
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"usage:\0A./sift_basic image.png\0A\00"
@.str.1 = [21 x i8] c"File \22%s\22 not found.\00"
@.str.2 = [12 x i8] c"/dev/stdout\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%6 = icmp eq i32 %0, 2
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %95
10: ; preds = %2
%11 = bitcast i64* %3 to i8*
%12 = bitcast i64* %4 to i8*
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = call float* @io_png_read_f32_gray(i8* %14, i64* %3, i64* %4)
%16 = icmp eq float* %15, null
br i1 %16, label %17, label %20
17: ; preds = %10
%18 = load i8*, i8** %13
%19 = call i32 @fatal_error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %17, %10
%21 = load i64, i64* %3
%22 = load i64, i64* %4
%23 = mul i64 %22, %21
%24 = icmp eq i64 %23, 0
br i1 %24, label %81, label %25
25: ; preds = %20
%26 = icmp ult i64 %23, 8
br i1 %26, label %79, label %27
27: ; preds = %25
%28 = and i64 %23, -8
%29 = add i64 %28, -8
%30 = lshr exact i64 %29, 3
%31 = add nuw nsw i64 %30, 1
%32 = and i64 %31, 1
%33 = icmp eq i64 %29, 0
br i1 %33, label %63, label %34
34: ; preds = %27
%35 = and i64 %31, 4611686018427387902
br label %36
36: ; preds = %36, %34
%37 = phi i64 [ 0, %34 ], [ %60, %36 ]
%38 = phi i64 [ 0, %34 ], [ %61, %36 ]
%39 = getelementptr inbounds float, float* %15, i64 %37
%40 = bitcast float* %39 to <4 x float>*
%41 = load <4 x float>, <4 x float>* %40
%42 = getelementptr inbounds float, float* %39, i64 4
%43 = bitcast float* %42 to <4 x float>*
%44 = load <4 x float>, <4 x float>* %43
%45 = fmul <4 x float> %41, <float 3.906250e-03, float 3.906250e-03, float 3.906250e-03, float 3.906250e-03>
%46 = fmul <4 x float> %44, <float 3.906250e-03, float 3.906250e-03, float 3.906250e-03, float 3.906250e-03>
%47 = bitcast float* %39 to <4 x float>*
store <4 x float> %45, <4 x float>* %47
%48 = bitcast float* %42 to <4 x float>*
store <4 x float> %46, <4 x float>* %48
%49 = or i64 %37, 8
%50 = getelementptr inbounds float, float* %15, i64 %49
%51 = bitcast float* %50 to <4 x float>*
%52 = load <4 x float>, <4 x float>* %51
%53 = getelementptr inbounds float, float* %50, i64 4
%54 = bitcast float* %53 to <4 x float>*
%55 = load <4 x float>, <4 x float>* %54
%56 = fmul <4 x float> %52, <float 3.906250e-03, float 3.906250e-03, float 3.906250e-03, float 3.906250e-03>
%57 = fmul <4 x float> %55, <float 3.906250e-03, float 3.906250e-03, float 3.906250e-03, float 3.906250e-03>
%58 = bitcast float* %50 to <4 x float>*
store <4 x float> %56, <4 x float>* %58
%59 = bitcast float* %53 to <4 x float>*
store <4 x float> %57, <4 x float>* %59
%60 = add nuw i64 %37, 16
%61 = add i64 %38, 2
%62 = icmp eq i64 %61, %35
br i1 %62, label %63, label %36
63: ; preds = %36, %27
%64 = phi i64 [ 0, %27 ], [ %60, %36 ]
%65 = icmp eq i64 %32, 0
br i1 %65, label %77, label %66
66: ; preds = %63
%67 = getelementptr inbounds float, float* %15, i64 %64
%68 = bitcast float* %67 to <4 x float>*
%69 = load <4 x float>, <4 x float>* %68
%70 = getelementptr inbounds float, float* %67, i64 4
%71 = bitcast float* %70 to <4 x float>*
%72 = load <4 x float>, <4 x float>* %71
%73 = fmul <4 x float> %69, <float 3.906250e-03, float 3.906250e-03, float 3.906250e-03, float 3.906250e-03>
%74 = fmul <4 x float> %72, <float 3.906250e-03, float 3.906250e-03, float 3.906250e-03, float 3.906250e-03>
%75 = bitcast float* %67 to <4 x float>*
store <4 x float> %73, <4 x float>* %75
%76 = bitcast float* %70 to <4 x float>*
store <4 x float> %74, <4 x float>* %76
br label %77
77: ; preds = %63, %66
%78 = icmp eq i64 %23, %28
br i1 %78, label %81, label %79
79: ; preds = %25, %77
%80 = phi i64 [ 0, %25 ], [ %28, %77 ]
br label %88
81: ; preds = %88, %77, %20
%82 = bitcast i32* %5 to i8*
%83 = call float* @sift_compute_features(float* %15, i64 %21, i64 %22, i32* %5)
%84 = load i32, i32* %5
%85 = call i32 @sift_write_to_file(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), float* %83, i32 %84)
%86 = call i32 @free(float* %83)
%87 = call i32 @free(float* %15)
br label %95
88: ; preds = %79, %88
%89 = phi i64 [ %93, %88 ], [ %80, %79 ]
%90 = getelementptr inbounds float, float* %15, i64 %89
%91 = load float, float* %90
%92 = fmul float %91, 3.906250e-03
store float %92, float* %90
%93 = add nuw nsw i64 %89, 1
%94 = icmp eq i64 %93, %23
br i1 %94, label %81, label %88
95: ; preds = %81, %7
%96 = phi i32 [ -1, %7 ], [ 0, %81 ]
ret i32 %96
}