#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*/ free(double *);
int iterate_kacz(double *, int, int, int, double *, double *);
double *malloc(int);
int /*<<< orphan*/ memcpy(double *, double *, int);
int /*<<< orphan*/ relax_aat(double *, int, int, int, double *, int);
int /*<<< orphan*/ relax_ata(double *, int, int, int, double *, int);
int /*<<< orphan*/ relax_atb(double *, int, int, int, double *, double *);
int kaczmarz(double *A, int m, int n, int stride, double *b, double *x0) {
  double *C, *c;
  int err;
  err = 0;
  C = NULL;
  c = NULL;
  if (m == n) {
    memcpy(x0, b, m * sizeof b[0]);
    if ((err = iterate_kacz(A, m, n, stride, b, x0)) == -1) {
      err = -1;
      goto err_out;
    }
  } else if (m > n) {
    C = malloc(n * n * sizeof C[0]);
    c = malloc(m * sizeof c[0]);
    relax_ata(A, m, n, stride, C, n);
    relax_atb(A, m, n, stride, b, c);
    if ((err = iterate_kacz(C, n, n, n, c, x0)) == -1) {
      err = -1;
      goto err_out;
    }
  } else {
    C = malloc(m * m * sizeof C[0]);
    c = malloc(m * sizeof c[0]);
    relax_aat(A, m, n, stride, C, m);
    if ((err = iterate_kacz(C, m, m, m, b, c)) == -1) {
      err = -1;
      goto err_out;
    }
    relax_atb(A, m, n, stride, c, x0);
  }
err_out:
  if (C != NULL)
    free(C);
  if (c != NULL)
    free(c);
  return err;
}


x86 assembly (clang, -O0):
<kaczmarz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
movl   $0x0,-0x3c(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    11fe <kaczmarz+0x8e>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
call   1060 <memcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%r9
call   1090 <iterate_kacz@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0xffffffff,%eax
jne    11f9 <kaczmarz+0x89>
movl   $0xffffffff,-0x3c(%rbp)
jmp    133b <kaczmarz+0x1cb>
jmp    1336 <kaczmarz+0x1c6>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    12a0 <kaczmarz+0x130>
mov    -0x10(%rbp),%eax
imul   -0x10(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x30(%rbp),%r8
mov    -0x10(%rbp),%r9d
call   1040 <relax_ata@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x20(%rbp),%r8
mov    -0x38(%rbp),%r9
call   1080 <relax_atb@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x38(%rbp),%r8
mov    -0x28(%rbp),%r9
call   1090 <iterate_kacz@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0xffffffff,%eax
jne    129b <kaczmarz+0x12b>
movl   $0xffffffff,-0x3c(%rbp)
jmp    133b <kaczmarz+0x1cb>
jmp    1331 <kaczmarz+0x1c1>
mov    -0xc(%rbp),%eax
imul   -0xc(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x30(%rbp),%r8
mov    -0xc(%rbp),%r9d
call   1050 <relax_aat@plt>
mov    -0x30(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x20(%rbp),%r8
mov    -0x38(%rbp),%r9
call   1090 <iterate_kacz@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0xffffffff,%eax
jne    1317 <kaczmarz+0x1a7>
movl   $0xffffffff,-0x3c(%rbp)
jmp    133b <kaczmarz+0x1cb>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x38(%rbp),%r8
mov    -0x28(%rbp),%r9
call   1080 <relax_atb@plt>
jmp    1336 <kaczmarz+0x1c6>
jmp    133b <kaczmarz+0x1cb>
cmpq   $0x0,-0x30(%rbp)
je     134f <kaczmarz+0x1df>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x38(%rbp)
je     1363 <kaczmarz+0x1f3>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x3c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kaczmarz>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,%r12
mov    %r8,%r14
mov    %ecx,%r13d
mov    %esi,%ebp
mov    %rdi,%r15
cmp    %edx,%esi
jne    11c5 <kaczmarz+0x55>
lea    0x0(,%rbp,8),%edx
mov    %r12,%rdi
mov    %r14,%rsi
call   1060 <memcpy@plt>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %ebp,%edx
mov    %r13d,%ecx
mov    %r14,%r8
mov    %r12,%r9
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <iterate_kacz@plt>
mov    %edx,%ebx
jle    1250 <kaczmarz+0xe0>
mov    %ebx,%edi
imul   %ebx,%edi
shl    $0x3,%edi
call   1070 <malloc@plt>
mov    %r15,0x20(%rsp)
mov    %rax,0x10(%rsp)
lea    0x0(,%rbp,8),%edi
call   1070 <malloc@plt>
mov    %rax,0x8(%rsp)
mov    %r15,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r13d,%ecx
mov    0x10(%rsp),%r15
mov    %r15,%r8
mov    %ebx,%r9d
call   1040 <relax_ata@plt>
mov    0x20(%rsp),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r13d,%ecx
mov    0x8(%rsp),%r13
mov    %r14,%r8
mov    %r13,%r9
call   1080 <relax_atb@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ebx,%edx
mov    %ebx,%ecx
mov    %r13,%r8
mov    %r12,%r9
call   1090 <iterate_kacz@plt>
mov    %eax,%r14d
test   %r15,%r15
jne    12df <kaczmarz+0x16f>
jmp    12e7 <kaczmarz+0x177>
mov    %r12,0x18(%rsp)
lea    0x0(,%rbp,8),%r12d
mov    %r12d,%edi
imul   %ebp,%edi
call   1070 <malloc@plt>
mov    %r13d,0x8(%rsp)
mov    %rax,%r13
mov    %r12d,%edi
call   1070 <malloc@plt>
mov    %rax,%r12
mov    %r15,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    0x8(%rsp),%ecx
mov    %r13,%r8
mov    %ebp,%r9d
call   1050 <relax_aat@plt>
mov    %r13,0x10(%rsp)
mov    %r13,%rdi
mov    %r12,%r13
mov    %ebp,%esi
mov    %ebp,%edx
mov    %ebp,%ecx
mov    %r14,%r8
mov    %r12,%r9
call   1090 <iterate_kacz@plt>
cmp    $0xffffffff,%eax
je     12cf <kaczmarz+0x15f>
mov    %eax,%r14d
mov    %r15,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    0x8(%rsp),%ecx
mov    %r13,%r8
mov    0x18(%rsp),%r9
call   1080 <relax_atb@plt>
jmp    12d5 <kaczmarz+0x165>
mov    $0xffffffff,%r14d
mov    0x10(%rsp),%r15
test   %r15,%r15
je     12e7 <kaczmarz+0x177>
mov    %r15,%rdi
call   1030 <free@plt>
test   %r13,%r13
je     12f4 <kaczmarz+0x184>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r14d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @kaczmarz(double* %0, i32 %1, i32 %2, i32 %3, double* %4, double* %5) {
%7 = alloca double*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca double*
%12 = alloca double*
%13 = alloca double*
%14 = alloca double*
%15 = alloca i32
store double* %0, double** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store double* %4, double** %11
store double* %5, double** %12
store i32 0, i32* %15
store double* null, double** %13
store double* null, double** %14
%16 = load i32, i32* %8
%17 = load i32, i32* %9
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %37
19: ; preds = %6
%20 = load double*, double** %12
%21 = load double*, double** %11
%22 = load i32, i32* %8
%23 = sext i32 %22 to i64
%24 = mul i64 %23, 8
%25 = trunc i64 %24 to i32
%26 = call i32 @memcpy(double* %20, double* %21, i32 %25)
%27 = load double*, double** %7
%28 = load i32, i32* %8
%29 = load i32, i32* %9
%30 = load i32, i32* %10
%31 = load double*, double** %11
%32 = load double*, double** %12
%33 = call i32 @iterate_kacz(double* %27, i32 %28, i32 %29, i32 %30, double* %31, double* %32)
store i32 %33, i32* %15
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %36
35: ; preds = %19
store i32 -1, i32* %15
br label %117
36: ; preds = %19
br label %116
37: ; preds = %6
%38 = load i32, i32* %8
%39 = load i32, i32* %9
%40 = icmp sgt i32 %38, %39
br i1 %40, label %41, label %78
41: ; preds = %37
%42 = load i32, i32* %9
%43 = load i32, i32* %9
%44 = mul nsw i32 %42, %43
%45 = sext i32 %44 to i64
%46 = mul i64 %45, 8
%47 = trunc i64 %46 to i32
%48 = call double* @malloc(i32 %47)
store double* %48, double** %13
%49 = load i32, i32* %8
%50 = sext i32 %49 to i64
%51 = mul i64 %50, 8
%52 = trunc i64 %51 to i32
%53 = call double* @malloc(i32 %52)
store double* %53, double** %14
%54 = load double*, double** %7
%55 = load i32, i32* %8
%56 = load i32, i32* %9
%57 = load i32, i32* %10
%58 = load double*, double** %13
%59 = load i32, i32* %9
%60 = call i32 @relax_ata(double* %54, i32 %55, i32 %56, i32 %57, double* %58, i32 %59)
%61 = load double*, double** %7
%62 = load i32, i32* %8
%63 = load i32, i32* %9
%64 = load i32, i32* %10
%65 = load double*, double** %11
%66 = load double*, double** %14
%67 = call i32 @relax_atb(double* %61, i32 %62, i32 %63, i32 %64, double* %65, double* %66)
%68 = load double*, double** %13
%69 = load i32, i32* %9
%70 = load i32, i32* %9
%71 = load i32, i32* %9
%72 = load double*, double** %14
%73 = load double*, double** %12
%74 = call i32 @iterate_kacz(double* %68, i32 %69, i32 %70, i32 %71, double* %72, double* %73)
store i32 %74, i32* %15
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %77
76: ; preds = %41
store i32 -1, i32* %15
br label %117
77: ; preds = %41
br label %115
78: ; preds = %37
%79 = load i32, i32* %8
%80 = load i32, i32* %8
%81 = mul nsw i32 %79, %80
%82 = sext i32 %81 to i64
%83 = mul i64 %82, 8
%84 = trunc i64 %83 to i32
%85 = call double* @malloc(i32 %84)
store double* %85, double** %13
%86 = load i32, i32* %8
%87 = sext i32 %86 to i64
%88 = mul i64 %87, 8
%89 = trunc i64 %88 to i32
%90 = call double* @malloc(i32 %89)
store double* %90, double** %14
%91 = load double*, double** %7
%92 = load i32, i32* %8
%93 = load i32, i32* %9
%94 = load i32, i32* %10
%95 = load double*, double** %13
%96 = load i32, i32* %8
%97 = call i32 @relax_aat(double* %91, i32 %92, i32 %93, i32 %94, double* %95, i32 %96)
%98 = load double*, double** %13
%99 = load i32, i32* %8
%100 = load i32, i32* %8
%101 = load i32, i32* %8
%102 = load double*, double** %11
%103 = load double*, double** %14
%104 = call i32 @iterate_kacz(double* %98, i32 %99, i32 %100, i32 %101, double* %102, double* %103)
store i32 %104, i32* %15
%105 = icmp eq i32 %104, -1
br i1 %105, label %106, label %107
106: ; preds = %78
store i32 -1, i32* %15
br label %117
107: ; preds = %78
%108 = load double*, double** %7
%109 = load i32, i32* %8
%110 = load i32, i32* %9
%111 = load i32, i32* %10
%112 = load double*, double** %14
%113 = load double*, double** %12
%114 = call i32 @relax_atb(double* %108, i32 %109, i32 %110, i32 %111, double* %112, double* %113)
br label %115
115: ; preds = %107, %77
br label %116
116: ; preds = %115, %36
br label %117
117: ; preds = %116, %106, %76, %35
%118 = load double*, double** %13
%119 = icmp ne double* %118, null
br i1 %119, label %120, label %123
120: ; preds = %117
%121 = load double*, double** %13
%122 = call i32 @free(double* %121)
br label %123
123: ; preds = %120, %117
%124 = load double*, double** %14
%125 = icmp ne double* %124, null
br i1 %125, label %126, label %129
126: ; preds = %123
%127 = load double*, double** %14
%128 = call i32 @free(double* %127)
br label %129
129: ; preds = %126, %123
%130 = load i32, i32* %15
ret i32 %130
}

LLVM IR (-O2):
define i32 @kaczmarz(double* %0, i32 %1, i32 %2, i32 %3, double* %4, double* %5) {
%7 = icmp eq i32 %1, %2
br i1 %7, label %8, label %12
8: ; preds = %6
%9 = shl i32 %1, 3
%10 = tail call i32 @memcpy(double* %5, double* %4, i32 %9)
%11 = tail call i32 @iterate_kacz(double* %0, i32 %1, i32 %1, i32 %3, double* %4, double* %5)
br label %44
12: ; preds = %6
%13 = icmp sgt i32 %1, %2
br i1 %13, label %14, label %23
14: ; preds = %12
%15 = shl i32 %2, 3
%16 = mul i32 %15, %2
%17 = tail call double* @malloc(i32 %16)
%18 = shl i32 %1, 3
%19 = tail call double* @malloc(i32 %18)
%20 = tail call i32 @relax_ata(double* %0, i32 %1, i32 %2, i32 %3, double* %17, i32 %2)
%21 = tail call i32 @relax_atb(double* %0, i32 %1, i32 %2, i32 %3, double* %4, double* %19)
%22 = tail call i32 @iterate_kacz(double* %17, i32 %2, i32 %2, i32 %2, double* %19, double* %5)
br label %33
23: ; preds = %12
%24 = shl i32 %1, 3
%25 = mul i32 %24, %1
%26 = tail call double* @malloc(i32 %25)
%27 = tail call double* @malloc(i32 %24)
%28 = tail call i32 @relax_aat(double* %0, i32 %1, i32 %2, i32 %3, double* %26, i32 %1)
%29 = tail call i32 @iterate_kacz(double* %26, i32 %1, i32 %1, i32 %1, double* %4, double* %27)
%30 = icmp eq i32 %29, -1
br i1 %30, label %33, label %31
31: ; preds = %23
%32 = tail call i32 @relax_atb(double* %0, i32 %1, i32 %2, i32 %3, double* %27, double* %5)
br label %33
33: ; preds = %23, %14, %31
%34 = phi double* [ %17, %14 ], [ %26, %31 ], [ %26, %23 ]
%35 = phi double* [ %19, %14 ], [ %27, %31 ], [ %27, %23 ]
%36 = phi i32 [ %22, %14 ], [ %29, %31 ], [ -1, %23 ]
%37 = icmp eq double* %34, null
br i1 %37, label %40, label %38
38: ; preds = %33
%39 = tail call i32 @free(double* %34)
br label %40
40: ; preds = %38, %33
%41 = icmp eq double* %35, null
br i1 %41, label %44, label %42
42: ; preds = %40
%43 = tail call i32 @free(double* %35)
br label %44
44: ; preds = %8, %42, %40
%45 = phi i32 [ %11, %8 ], [ %36, %42 ], [ %36, %40 ]
ret i32 %45
}