#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(void *);
double *lsd(int *, double *, int, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(void) {
  double *image;
  double *out;
  int x, y, i, j, n;
  int X = 128;
  int Y = 128;
  image = (double *)malloc(X * Y * sizeof(double));
  if (image == NULL) {
    fprintf(stderr, "error: not enough memory\n");
    exit(EXIT_FAILURE);
  }
  for (x = 0; x < X; x++)
    for (y = 0; y < Y; y++)
      image[x + y * X] = x < X / 2 ? 0.0 : 64.0;
  out = lsd(&n, image, X, Y);
  printf("%d line segments found:\n", n);
  for (i = 0; i < n; i++) {
    for (j = 0; j < 7; j++)
      printf("%f ", out[7 * i + j]);
    printf("\n");
  }
  free((void *)image);
  free((void *)out);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x80,-0x30(%rbp)
movl   $0x80,-0x34(%rbp)
mov    -0x30(%rbp),%eax
imul   -0x34(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c3 <main+0x63>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    1264 <main+0x104>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    1251 <main+0xf1>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x30(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x4c(%rbp),%eax
xorps  %xmm0,%xmm0
movsd  0xdf6(%rip),%xmm1
movsd  %xmm1,-0x48(%rbp)
cmp    %ecx,%eax
movsd  %xmm0,-0x40(%rbp)
jl     1226 <main+0xc6>
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%edx
imul   -0x30(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11dd <main+0x7d>
jmp    1256 <main+0xf6>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ca <main+0x6a>
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%edx
mov    -0x34(%rbp),%ecx
lea    -0x2c(%rbp),%rdi
call   1070 <lsd@plt>
mov    %rax,-0x18(%rbp)
mov    -0x2c(%rbp),%esi
lea    0xd9d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    12fb <main+0x19b>
movl   $0x0,-0x28(%rbp)
cmpl   $0x7,-0x28(%rbp)
jge    12df <main+0x17f>
mov    -0x18(%rbp),%rax
imul   $0x7,-0x24(%rbp),%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xd71(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    12a6 <main+0x146>
lea    0xd53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1293 <main+0x133>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    0x2cbc(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    $0x20000,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     12ff <main+0x18f>
mov    %rax,%r15
add    $0xc00,%rax
xor    %ecx,%ecx
movsd  0xe5d(%rip),%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xorps  %xmm1,%xmm1
cmp    $0x40,%rcx
jb     11bc <main+0x4c>
movaps %xmm0,%xmm1
xor    %edx,%edx
xchg   %ax,%ax
movsd  %xmm1,-0xc00(%rax,%rdx,1)
ff ff
movsd  %xmm1,-0x800(%rax,%rdx,1)
ff ff
movsd  %xmm1,-0x400(%rax,%rdx,1)
ff ff
movsd  %xmm1,(%rax,%rdx,1)
add    $0x1000,%rdx
cmp    $0x20000,%rdx
jne    11c0 <main+0x50>
add    $0x1,%rcx
add    $0x8,%rax
cmp    $0x80,%rcx
jne    11b0 <main+0x40>
lea    0xc(%rsp),%rdi
mov    %r15,%rsi
mov    $0x80,%edx
mov    $0x80,%ecx
call   1080 <lsd@plt>
mov    %rax,%r14
mov    0xc(%rsp),%esi
lea    0xdfc(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jle    12d8 <main+0x168>
mov    %r14,%rbx
add    $0x30,%rbx
xor    %r13d,%r13d
lea    0xdf2(%rip),%r12
nopl   0x0(%rax)
movsd  -0x30(%rbx),%xmm0
mov    %r12,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  -0x28(%rbx),%xmm0
mov    %r12,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  -0x20(%rbx),%xmm0
mov    %r12,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  -0x18(%rbx),%xmm0
mov    %r12,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  -0x10(%rbx),%xmm0
mov    %r12,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  -0x8(%rbx),%xmm0
mov    %r12,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  (%rbx),%xmm0
mov    %r12,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
add    $0x1,%r13
movslq 0xc(%rsp),%rax
add    $0x38,%rbx
cmp    %rax,%r13
jl     1250 <main+0xe0>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x2ce1(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2cda(%rip),%rax
mov    (%rax),%edi
lea    0xcf9(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2cbd(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"error: not enough memory\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [25 x i8] c"%d line segments found:\0A\00"
@.str.2 = [4 x i8] c"%f \00"
@.str.3 = [2 x i8] c"\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca double*
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
store i32 128, i32* %9
store i32 128, i32* %10
%11 = load i32, i32* %9
%12 = load i32, i32* %10
%13 = mul nsw i32 %11, %12
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 8
%16 = trunc i64 %15 to i32
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to double*
store double* %18, double** %2
%19 = load double*, double** %2
%20 = icmp eq double* %19, null
br i1 %20, label %21, label %26
21: ; preds = %0
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %0
store i32 0, i32* %4
br label %27
27: ; preds = %55, %26
%28 = load i32, i32* %4
%29 = load i32, i32* %9
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %58
31: ; preds = %27
store i32 0, i32* %5
br label %32
32: ; preds = %51, %31
%33 = load i32, i32* %5
%34 = load i32, i32* %10
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %54
36: ; preds = %32
%37 = load i32, i32* %4
%38 = load i32, i32* %9
%39 = sdiv i32 %38, 2
%40 = icmp slt i32 %37, %39
%41 = zext i1 %40 to i64
%42 = select i1 %40, double 0.000000e+00, double 6.400000e+01
%43 = load double*, double** %2
%44 = load i32, i32* %4
%45 = load i32, i32* %5
%46 = load i32, i32* %9
%47 = mul nsw i32 %45, %46
%48 = add nsw i32 %44, %47
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double, double* %43, i64 %49
store double %42, double* %50
br label %51
51: ; preds = %36
%52 = load i32, i32* %5
%53 = add nsw i32 %52, 1
store i32 %53, i32* %5
br label %32
54: ; preds = %32
br label %55
55: ; preds = %54
%56 = load i32, i32* %4
%57 = add nsw i32 %56, 1
store i32 %57, i32* %4
br label %27
58: ; preds = %27
%59 = load double*, double** %2
%60 = load i32, i32* %9
%61 = load i32, i32* %10
%62 = call double* @lsd(i32* %8, double* %59, i32 %60, i32 %61)
store double* %62, double** %3
%63 = load i32, i32* %8
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %63)
store i32 0, i32* %6
br label %65
65: ; preds = %88, %58
%66 = load i32, i32* %6
%67 = load i32, i32* %8
%68 = icmp slt i32 %66, %67
br i1 %68, label %69, label %91
69: ; preds = %65
store i32 0, i32* %7
br label %70
70: ; preds = %83, %69
%71 = load i32, i32* %7
%72 = icmp slt i32 %71, 7
br i1 %72, label %73, label %86
73: ; preds = %70
%74 = load double*, double** %3
%75 = load i32, i32* %6
%76 = mul nsw i32 7, %75
%77 = load i32, i32* %7
%78 = add nsw i32 %76, %77
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds double, double* %74, i64 %79
%81 = load double, double* %80
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %81)
br label %83
83: ; preds = %73
%84 = load i32, i32* %7
%85 = add nsw i32 %84, 1
store i32 %85, i32* %7
br label %70
86: ; preds = %70
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %88
88: ; preds = %86
%89 = load i32, i32* %6
%90 = add nsw i32 %89, 1
store i32 %90, i32* %6
br label %65
91: ; preds = %65
%92 = load double*, double** %2
%93 = bitcast double* %92 to i8*
%94 = call i32 @free(i8* %93)
%95 = load double*, double** %3
%96 = bitcast double* %95 to i8*
%97 = call i32 @free(i8* %96)
%98 = load i32, i32* @EXIT_SUCCESS
ret i32 %98
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"error: not enough memory\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [25 x i8] c"%d line segments found:\0A\00"
@.str.2 = [4 x i8] c"%f \00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i64 @malloc(i32 131072)
%4 = inttoptr i64 %3 to double*
%5 = icmp eq i64 %3, 0
br i1 %5, label %6, label %11
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %0, %34
%12 = phi i64 [ %35, %34 ], [ 0, %0 ]
%13 = icmp ult i64 %12, 64
%14 = select i1 %13, double 0.000000e+00, double 6.400000e+01
br label %15
15: ; preds = %15, %11
%16 = phi i64 [ 0, %11 ], [ %32, %15 ]
%17 = shl nuw nsw i64 %16, 7
%18 = add nuw nsw i64 %17, %12
%19 = getelementptr inbounds double, double* %4, i64 %18
store double %14, double* %19
%20 = shl i64 %16, 7
%21 = or i64 %20, 128
%22 = add nuw nsw i64 %21, %12
%23 = getelementptr inbounds double, double* %4, i64 %22
store double %14, double* %23
%24 = shl i64 %16, 7
%25 = or i64 %24, 256
%26 = add nuw nsw i64 %25, %12
%27 = getelementptr inbounds double, double* %4, i64 %26
store double %14, double* %27
%28 = shl i64 %16, 7
%29 = or i64 %28, 384
%30 = add nuw nsw i64 %29, %12
%31 = getelementptr inbounds double, double* %4, i64 %30
store double %14, double* %31
%32 = add nuw nsw i64 %16, 4
%33 = icmp eq i64 %32, 128
br i1 %33, label %34, label %15
34: ; preds = %15
%35 = add nuw nsw i64 %12, 1
%36 = icmp eq i64 %35, 128
br i1 %36, label %37, label %11
37: ; preds = %34
%38 = call double* @lsd(i32* %1, double* %4, i32 128, i32 128)
%39 = load i32, i32* %1
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %1
%42 = icmp sgt i32 %41, 0
br i1 %42, label %43, label %78
43: ; preds = %37, %43
%44 = phi i64 [ %74, %43 ], [ 0, %37 ]
%45 = mul nuw nsw i64 %44, 7
%46 = getelementptr inbounds double, double* %38, i64 %45
%47 = load double, double* %46
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %47)
%49 = add nuw nsw i64 %45, 1
%50 = getelementptr inbounds double, double* %38, i64 %49
%51 = load double, double* %50
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %51)
%53 = add nuw nsw i64 %45, 2
%54 = getelementptr inbounds double, double* %38, i64 %53
%55 = load double, double* %54
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %55)
%57 = add nuw nsw i64 %45, 3
%58 = getelementptr inbounds double, double* %38, i64 %57
%59 = load double, double* %58
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %59)
%61 = add nuw nsw i64 %45, 4
%62 = getelementptr inbounds double, double* %38, i64 %61
%63 = load double, double* %62
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %63)
%65 = add nuw nsw i64 %45, 5
%66 = getelementptr inbounds double, double* %38, i64 %65
%67 = load double, double* %66
%68 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %67)
%69 = add nuw nsw i64 %45, 6
%70 = getelementptr inbounds double, double* %38, i64 %69
%71 = load double, double* %70
%72 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %71)
%73 = call i32 @putchar(i32 10)
%74 = add nuw nsw i64 %44, 1
%75 = load i32, i32* %1
%76 = sext i32 %75 to i64
%77 = icmp slt i64 %74, %76
br i1 %77, label %43, label %78
78: ; preds = %43, %37
%79 = inttoptr i64 %3 to i8*
%80 = call i32 @free(i8* %79)
%81 = bitcast double* %38 to i8*
%82 = call i32 @free(i8* %81)
%83 = load i32, i32* @EXIT_SUCCESS
ret i32 %83
}