#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*/ pdoubledifferencexalpha(double *, double *, double,
                                           unsigned long);
int /*<<< orphan*/ pdoublesumcexalpha(double *, double *, double,
                                      unsigned long);
double pdoublexpdouble(double *, double *, unsigned long);
void kernel_perceptron(double **weightVectors, unsigned long C,
                       double **learnSamples, unsigned long numLearnSamples,
                       double learnFactor, double margin,
                       unsigned int dimensions) {
  unsigned long m;
  unsigned long n;
  unsigned long i;
  unsigned long j;
  double g;
  char error = 0;
  do {
    m = 0;
    for (n = 1; n <= numLearnSamples - 1; n++) {
      i = learnSamples[n][1];
      g = pdoublexpdouble(weightVectors[n], learnSamples[n], dimensions);
      error = 0;
      for (j = 1; j <= C; j++) {
        if (j != i) {
          if (pdoublexpdouble(weightVectors[j], learnSamples[n],
                              numLearnSamples) +
                  margin >
              g) {
            pdoubledifferencexalpha(weightVectors[j], learnSamples[n],
                                    learnFactor, numLearnSamples);
            error = 1;
          }
        }
        if (error == 1)
          pdoublesumcexalpha(weightVectors[i], learnSamples[n], learnFactor,
                             numLearnSamples);
        else
          m += 1;
      }
    }
  } while (m < numLearnSamples);
}


x86 assembly (clang, -O0):
<kernel_perceptron>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movsd  %xmm0,-0x28(%rbp)
movsd  %xmm1,-0x30(%rbp)
mov    %r8d,-0x34(%rbp)
movb   $0x0,-0x61(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x1,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
ja     12d9 <kernel_perceptron+0x1a9>
mov    -0x18(%rbp),%rax
mov    -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsd  0x8(%rax),%xmm0
movaps %xmm0,%xmm1
cvttsd2si %xmm1,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
movsd  0xe59(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rcx
and    %rdx,%rcx
or     %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rax
mov    -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x34(%rbp),%eax
mov    %eax,%edx
call   1050 <pdoublexpdouble@plt>
movsd  %xmm0,-0x60(%rbp)
movb   $0x0,-0x61(%rbp)
movq   $0x1,-0x58(%rbp)
mov    -0x58(%rbp),%rax
cmp    -0x10(%rbp),%rax
ja     12c3 <kernel_perceptron+0x193>
mov    -0x58(%rbp),%rax
cmp    -0x50(%rbp),%rax
je     1269 <kernel_perceptron+0x139>
mov    -0x8(%rbp),%rax
mov    -0x58(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rax
mov    -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <pdoublexpdouble@plt>
addsd  -0x30(%rbp),%xmm0
ucomisd -0x60(%rbp),%xmm0
jbe    1264 <kernel_perceptron+0x134>
mov    -0x8(%rbp),%rax
mov    -0x58(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rax
mov    -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
movsd  -0x28(%rbp),%xmm0
mov    -0x20(%rbp),%rdx
call   1040 <pdoubledifferencexalpha@plt>
movb   $0x1,-0x61(%rbp)
jmp    1269 <kernel_perceptron+0x139>
movsbl -0x61(%rbp),%eax
cmp    $0x1,%eax
jne    12a1 <kernel_perceptron+0x171>
mov    -0x8(%rbp),%rax
mov    -0x50(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rax
mov    -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
movsd  -0x28(%rbp),%xmm0
mov    -0x20(%rbp),%rdx
call   1030 <pdoublesumcexalpha@plt>
jmp    12ad <kernel_perceptron+0x17d>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    12b2 <kernel_perceptron+0x182>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    11ed <kernel_perceptron+0xbd>
jmp    12c8 <kernel_perceptron+0x198>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    116a <kernel_perceptron+0x3a>
jmp    12de <kernel_perceptron+0x1ae>
mov    -0x40(%rbp),%rax
cmp    -0x20(%rbp),%rax
jb     115a <kernel_perceptron+0x2a>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kernel_perceptron>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
movsd  %xmm1,0x30(%rsp)
movsd  %xmm0,0x18(%rsp)
mov    %rdx,%r12
mov    %rsi,0x20(%rsp)
mov    %rdi,%rbx
mov    %rcx,(%rsp)
lea    -0x1(%rcx),%rax
mov    %rax,0x10(%rsp)
mov    %r8d,%eax
mov    %rax,0x28(%rsp)
jmp    1186 <kernel_perceptron+0x56>
nopl   0x0(%rax)
xor    %eax,%eax
mov    %rax,0x8(%rsp)
mov    0x8(%rsp),%rax
cmp    (%rsp),%rax
jae    1282 <kernel_perceptron+0x152>
cmpq   $0x0,0x10(%rsp)
je     1170 <kernel_perceptron+0x40>
mov    $0x1,%ebp
xor    %eax,%eax
mov    %rax,0x8(%rsp)
jmp    11ab <kernel_perceptron+0x7b>
nopl   0x0(%rax)
add    $0x1,%rbp
cmp    0x10(%rsp),%rbp
ja     1177 <kernel_perceptron+0x47>
mov    (%r12,%rbp,8),%rsi
movsd  0x8(%rsi),%xmm0
movapd %xmm0,0x40(%rsp)
subsd  0xe3e(%rip),%xmm0
movapd %xmm0,0x50(%rsp)
mov    (%rbx,%rbp,8),%rdi
mov    0x28(%rsp),%rdx
call   1050 <pdoublexpdouble@plt>
movsd  %xmm0,0x38(%rsp)
cmpq   $0x0,0x20(%rsp)
je     11a0 <kernel_perceptron+0x70>
cvttsd2si 0x40(%rsp),%rax
mov    %rax,%rcx
sar    $0x3f,%rcx
cvttsd2si 0x50(%rsp),%r13
and    %rcx,%r13
or     %rax,%r13
mov    $0x1,%r15d
xor    %r14d,%r14d
jmp    1250 <kernel_perceptron+0x120>
nopw   0x0(%rax,%rax,1)
mov    (%rbx,%r15,8),%rdi
mov    (%r12,%rbp,8),%rsi
movsd  0x18(%rsp),%xmm0
mov    (%rsp),%rdx
call   1040 <pdoubledifferencexalpha@plt>
mov    (%rbx,%r13,8),%rdi
mov    (%r12,%rbp,8),%rsi
movsd  0x18(%rsp),%xmm0
mov    (%rsp),%rdx
call   1030 <pdoublesumcexalpha@plt>
mov    $0x1,%r14b
add    $0x1,%r15
cmp    0x20(%rsp),%r15
ja     11a0 <kernel_perceptron+0x70>
cmp    %r15,%r13
je     1274 <kernel_perceptron+0x144>
mov    (%rbx,%r15,8),%rdi
mov    (%r12,%rbp,8),%rsi
mov    (%rsp),%rdx
call   1050 <pdoublexpdouble@plt>
addsd  0x30(%rsp),%xmm0
ucomisd 0x38(%rsp),%xmm0
ja     1210 <kernel_perceptron+0xe0>
cmp    $0x1,%r14b
je     1227 <kernel_perceptron+0xf7>
addq   $0x1,0x8(%rsp)
jmp    1241 <kernel_perceptron+0x111>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @kernel_perceptron(double** %0, i64 %1, double** %2, i64 %3, double %4, double %5, i32 %6) {
%8 = alloca double**
%9 = alloca i64
%10 = alloca double**
%11 = alloca i64
%12 = alloca double
%13 = alloca double
%14 = alloca i32
%15 = alloca i64
%16 = alloca i64
%17 = alloca i64
%18 = alloca i64
%19 = alloca double
%20 = alloca i8
store double** %0, double*** %8
store i64 %1, i64* %9
store double** %2, double*** %10
store i64 %3, i64* %11
store double %4, double* %12
store double %5, double* %13
store i32 %6, i32* %14
store i8 0, i8* %20
br label %21
21: ; preds = %110, %7
store i64 0, i64* %15
store i64 1, i64* %16
br label %22
22: ; preds = %106, %21
%23 = load i64, i64* %16
%24 = load i64, i64* %11
%25 = sub i64 %24, 1
%26 = icmp ule i64 %23, %25
br i1 %26, label %27, label %109
27: ; preds = %22
%28 = load double**, double*** %10
%29 = load i64, i64* %16
%30 = getelementptr inbounds double*, double** %28, i64 %29
%31 = load double*, double** %30
%32 = getelementptr inbounds double, double* %31, i64 1
%33 = load double, double* %32
%34 = fptoui double %33 to i64
store i64 %34, i64* %17
%35 = load double**, double*** %8
%36 = load i64, i64* %16
%37 = getelementptr inbounds double*, double** %35, i64 %36
%38 = load double*, double** %37
%39 = load double**, double*** %10
%40 = load i64, i64* %16
%41 = getelementptr inbounds double*, double** %39, i64 %40
%42 = load double*, double** %41
%43 = load i32, i32* %14
%44 = zext i32 %43 to i64
%45 = call double @pdoublexpdouble(double* %38, double* %42, i64 %44)
store double %45, double* %19
store i8 0, i8* %20
store i64 1, i64* %18
br label %46
46: ; preds = %102, %27
%47 = load i64, i64* %18
%48 = load i64, i64* %9
%49 = icmp ule i64 %47, %48
br i1 %49, label %50, label %105
50: ; preds = %46
%51 = load i64, i64* %18
%52 = load i64, i64* %17
%53 = icmp ne i64 %51, %52
br i1 %53, label %54, label %82
54: ; preds = %50
%55 = load double**, double*** %8
%56 = load i64, i64* %18
%57 = getelementptr inbounds double*, double** %55, i64 %56
%58 = load double*, double** %57
%59 = load double**, double*** %10
%60 = load i64, i64* %16
%61 = getelementptr inbounds double*, double** %59, i64 %60
%62 = load double*, double** %61
%63 = load i64, i64* %11
%64 = call double @pdoublexpdouble(double* %58, double* %62, i64 %63)
%65 = load double, double* %13
%66 = fadd double %64, %65
%67 = load double, double* %19
%68 = fcmp ogt double %66, %67
br i1 %68, label %69, label %81
69: ; preds = %54
%70 = load double**, double*** %8
%71 = load i64, i64* %18
%72 = getelementptr inbounds double*, double** %70, i64 %71
%73 = load double*, double** %72
%74 = load double**, double*** %10
%75 = load i64, i64* %16
%76 = getelementptr inbounds double*, double** %74, i64 %75
%77 = load double*, double** %76
%78 = load double, double* %12
%79 = load i64, i64* %11
%80 = call i32 @pdoubledifferencexalpha(double* %73, double* %77, double %78, i64 %79)
store i8 1, i8* %20
br label %81
81: ; preds = %69, %54
br label %82
82: ; preds = %81, %50
%83 = load i8, i8* %20
%84 = sext i8 %83 to i32
%85 = icmp eq i32 %84, 1
br i1 %85, label %86, label %98
86: ; preds = %82
%87 = load double**, double*** %8
%88 = load i64, i64* %17
%89 = getelementptr inbounds double*, double** %87, i64 %88
%90 = load double*, double** %89
%91 = load double**, double*** %10
%92 = load i64, i64* %16
%93 = getelementptr inbounds double*, double** %91, i64 %92
%94 = load double*, double** %93
%95 = load double, double* %12
%96 = load i64, i64* %11
%97 = call i32 @pdoublesumcexalpha(double* %90, double* %94, double %95, i64 %96)
br label %101
98: ; preds = %82
%99 = load i64, i64* %15
%100 = add i64 %99, 1
store i64 %100, i64* %15
br label %101
101: ; preds = %98, %86
br label %102
102: ; preds = %101
%103 = load i64, i64* %18
%104 = add i64 %103, 1
store i64 %104, i64* %18
br label %46
105: ; preds = %46
br label %106
106: ; preds = %105
%107 = load i64, i64* %16
%108 = add i64 %107, 1
store i64 %108, i64* %16
br label %22
109: ; preds = %22
br label %110
110: ; preds = %109
%111 = load i64, i64* %15
%112 = load i64, i64* %11
%113 = icmp ult i64 %111, %112
br i1 %113, label %21, label %114
114: ; preds = %110
ret void
}

LLVM IR (-O2):
define void @kernel_perceptron(double** nocapture %0, i64 %1, double** nocapture %2, i64 %3, double %4, double %5, i32 %6) {
%8 = add i64 %3, -1
%9 = icmp eq i64 %8, 0
%10 = zext i32 %6 to i64
%11 = icmp eq i64 %1, 0
br label %12
12: ; preds = %59, %7
br i1 %9, label %59, label %13
13: ; preds = %12, %55
%14 = phi i64 [ %56, %55 ], [ 0, %12 ]
%15 = phi i64 [ %57, %55 ], [ 1, %12 ]
%16 = getelementptr inbounds double*, double** %2, i64 %15
%17 = load double*, double** %16
%18 = getelementptr inbounds double, double* %17, i64 1
%19 = load double, double* %18
%20 = fptoui double %19 to i64
%21 = getelementptr inbounds double*, double** %0, i64 %15
%22 = load double*, double** %21
%23 = tail call double @pdoublexpdouble(double* %22, double* %17, i64 %10)
br i1 %11, label %55, label %24
24: ; preds = %13
%25 = getelementptr inbounds double*, double** %0, i64 %20
br label %26
26: ; preds = %24, %50
%27 = phi i8 [ 0, %24 ], [ %51, %50 ]
%28 = phi i64 [ %14, %24 ], [ %52, %50 ]
%29 = phi i64 [ 1, %24 ], [ %53, %50 ]
%30 = icmp eq i64 %29, %20
br i1 %30, label %42, label %31
31: ; preds = %26
%32 = getelementptr inbounds double*, double** %0, i64 %29
%33 = load double*, double** %32
%34 = load double*, double** %16
%35 = tail call double @pdoublexpdouble(double* %33, double* %34, i64 %3)
%36 = fadd double %35, %5
%37 = fcmp ogt double %36, %23
br i1 %37, label %38, label %42
38: ; preds = %31
%39 = load double*, double** %32
%40 = load double*, double** %16
%41 = tail call i32 @pdoubledifferencexalpha(double* %39, double* %40, double %4, i64 %3)
br label %44
42: ; preds = %31, %26
%43 = icmp eq i8 %27, 1
br i1 %43, label %44, label %48
44: ; preds = %38, %42
%45 = load double*, double** %25
%46 = load double*, double** %16
%47 = tail call i32 @pdoublesumcexalpha(double* %45, double* %46, double %4, i64 %3)
br label %50
48: ; preds = %42
%49 = add i64 %28, 1
br label %50
50: ; preds = %44, %48
%51 = phi i8 [ 1, %44 ], [ %27, %48 ]
%52 = phi i64 [ %28, %44 ], [ %49, %48 ]
%53 = add i64 %29, 1
%54 = icmp ugt i64 %53, %1
br i1 %54, label %55, label %26
55: ; preds = %50, %13
%56 = phi i64 [ %14, %13 ], [ %52, %50 ]
%57 = add i64 %15, 1
%58 = icmp ugt i64 %57, %8
br i1 %58, label %59, label %13
59: ; preds = %55, %12
%60 = phi i64 [ 0, %12 ], [ %56, %55 ]
%61 = icmp ult i64 %60, %3
br i1 %61, label %12, label %62
62: ; preds = %59
ret void
}