#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 atoi(char *);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ cf(int, double *, double *, double *, double *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int n = 10;
  if (argc == 2) {
    n = atoi(argv[1]);
    if (n == 0) {
      printf("Error in command line argument, should be a single nonzero "
             "integer.\n");
      exit(1);
    }
  }
  double *poles_r = (double *)calloc(n, sizeof(double));
  double *poles_i = (double *)calloc(n, sizeof(double));
  double *res_r = (double *)calloc(n, sizeof(double));
  double *res_i = (double *)calloc(n, sizeof(double));
  cf(n, poles_r, poles_i, res_r, res_i);
  printf("Type (%i, %i) best rational function approximant to matrix "
         "exponential.\n",
         n, n);
  printf("poles: \n");
  for (int i = 0; i < n; ++i) {
    printf("%.15e + %.15e i\n", poles_r[i], poles_i[i]);
  }
  printf("\n");
  printf("residuals: \n");
  for (int i = 0; i < n; ++i) {
    printf("%.15e + %.15e i\n", res_r[i], res_i[i]);
  }
  printf("\n");
  free(poles_r);
  free(poles_i);
  free(res_r);
  free(res_i);
  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)
movl   $0xa,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11be <main+0x5e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11b9 <main+0x59>
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11be <main+0x5e>
mov    -0x14(%rbp),%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
call   1040 <cf@plt>
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1285 <main+0x125>
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
lea    0xe27(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1243 <main+0xe3>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12ea <main+0x18a>
mov    -0x30(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x38(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
lea    0xdc2(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    12a8 <main+0x148>
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0xa,%ebp
cmp    $0x2,%edi
jne    11ab <main+0x2b>
mov    0x8(%rsi),%rdi
call   1090 <atoi@plt>
mov    %eax,%ebp
test   %eax,%eax
je     130b <main+0x18b>
mov    %ebp,%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,%r14
mov    %ebp,%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,%rbx
mov    %ebp,%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,%r15
mov    %ebp,%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %r15,%r12
mov    %r15,%rcx
mov    %rax,0x10(%rsp)
mov    %rax,%r8
call   1060 <cf@plt>
lea    0xdfa(%rip),%rdi
mov    %ebp,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe42(%rip),%rdi
call   1050 <puts@plt>
test   %ebp,%ebp
jle    12b5 <main+0x135>
mov    %ebp,0xc(%rsp)
mov    %ebp,%r13d
xor    %r15d,%r15d
lea    0xe13(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
movsd  (%r14,%r15,8),%xmm0
movsd  (%rbx,%r15,8),%xmm1
mov    %rbp,%rdi
mov    $0x2,%al
call   1070 <printf@plt>
add    $0x1,%r15
cmp    %r15,%r13
jne    1240 <main+0xc0>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xdf2(%rip),%rdi
call   1050 <puts@plt>
cmpl   $0x0,0xc(%rsp)
mov    0x10(%rsp),%r15
jle    12d0 <main+0x150>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  (%r12,%rbp,8),%xmm0
movsd  (%r15,%rbp,8),%xmm1
lea    0xda6(%rip),%rdi
mov    $0x2,%al
call   1070 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1290 <main+0x110>
jmp    12d0 <main+0x150>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xd9c(%rip),%rdi
call   1050 <puts@plt>
mov    0x10(%rsp),%r15
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd5c(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [69 x i8] c"Error in command line argument, should be a single nonzero integer.\0A\00"
@.str.1 = [73 x i8] c"Type (%i, %i) best rational function approximant to matrix exponential.\0A\00"
@.str.2 = [9 x i8] c"poles: \0A\00"
@.str.3 = [17 x i8] c"%.15e + %.15e i\0A\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [13 x i8] c"residuals: \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca double*
%8 = alloca double*
%9 = alloca double*
%10 = alloca double*
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 10, i32* %6
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 2
br i1 %14, label %15, label %26
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %15
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %15
br label %26
26: ; preds = %25, %2
%27 = load i32, i32* %6
%28 = call i64 @calloc(i32 %27, i32 8)
%29 = inttoptr i64 %28 to double*
store double* %29, double** %7
%30 = load i32, i32* %6
%31 = call i64 @calloc(i32 %30, i32 8)
%32 = inttoptr i64 %31 to double*
store double* %32, double** %8
%33 = load i32, i32* %6
%34 = call i64 @calloc(i32 %33, i32 8)
%35 = inttoptr i64 %34 to double*
store double* %35, double** %9
%36 = load i32, i32* %6
%37 = call i64 @calloc(i32 %36, i32 8)
%38 = inttoptr i64 %37 to double*
store double* %38, double** %10
%39 = load i32, i32* %6
%40 = load double*, double** %7
%41 = load double*, double** %8
%42 = load double*, double** %9
%43 = load double*, double** %10
%44 = call i32 @cf(i32 %39, double* %40, double* %41, double* %42, double* %43)
%45 = load i32, i32* %6
%46 = load i32, i32* %6
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.1, i64 0, i64 0), i32 %45, i32 %46)
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %11
br label %49
49: ; preds = %65, %26
%50 = load i32, i32* %11
%51 = load i32, i32* %6
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %68
53: ; preds = %49
%54 = load double*, double** %7
%55 = load i32, i32* %11
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds double, double* %54, i64 %56
%58 = load double, double* %57
%59 = load double*, double** %8
%60 = load i32, i32* %11
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds double, double* %59, i64 %61
%63 = load double, double* %62
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), double %58, double %63)
br label %65
65: ; preds = %53
%66 = load i32, i32* %11
%67 = add nsw i32 %66, 1
store i32 %67, i32* %11
br label %49
68: ; preds = %49
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %12
br label %71
71: ; preds = %87, %68
%72 = load i32, i32* %12
%73 = load i32, i32* %6
%74 = icmp slt i32 %72, %73
br i1 %74, label %75, label %90
75: ; preds = %71
%76 = load double*, double** %9
%77 = load i32, i32* %12
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds double, double* %76, i64 %78
%80 = load double, double* %79
%81 = load double*, double** %10
%82 = load i32, i32* %12
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds double, double* %81, i64 %83
%85 = load double, double* %84
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), double %80, double %85)
br label %87
87: ; preds = %75
%88 = load i32, i32* %12
%89 = add nsw i32 %88, 1
store i32 %89, i32* %12
br label %71
90: ; preds = %71
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%92 = load double*, double** %7
%93 = call i32 @free(double* %92)
%94 = load double*, double** %8
%95 = call i32 @free(double* %94)
%96 = load double*, double** %9
%97 = call i32 @free(double* %96)
%98 = load double*, double** %10
%99 = call i32 @free(double* %98)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [73 x i8] c"Type (%i, %i) best rational function approximant to matrix exponential.\0A\00"
@.str.3 = [17 x i8] c"%.15e + %.15e i\0A\00"
@str = [8 x i8] c"poles: \00"
@str.6 = [12 x i8] c"residuals: \00"
@str.7 = [68 x i8] c"Error in command line argument, should be a single nonzero integer.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %12
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @str.7, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %4, %2
%13 = phi i32 [ %7, %4 ], [ 10, %2 ]
%14 = tail call i64 @calloc(i32 %13, i32 8)
%15 = inttoptr i64 %14 to double*
%16 = tail call i64 @calloc(i32 %13, i32 8)
%17 = inttoptr i64 %16 to double*
%18 = tail call i64 @calloc(i32 %13, i32 8)
%19 = inttoptr i64 %18 to double*
%20 = tail call i64 @calloc(i32 %13, i32 8)
%21 = inttoptr i64 %20 to double*
%22 = tail call i32 @cf(i32 %13, double* %15, double* %17, double* %19, double* %21)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([73 x i8], [73 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %13)
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
%25 = icmp sgt i32 %13, 0
br i1 %25, label %26, label %42
26: ; preds = %12
%27 = zext i32 %13 to i64
br label %33
28: ; preds = %33
%29 = tail call i32 @putchar(i32 10)
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.6, i64 0, i64 0))
br i1 %25, label %31, label %45
31: ; preds = %28
%32 = zext i32 %13 to i64
br label %51
33: ; preds = %26, %33
%34 = phi i64 [ 0, %26 ], [ %40, %33 ]
%35 = getelementptr inbounds double, double* %15, i64 %34
%36 = load double, double* %35
%37 = getelementptr inbounds double, double* %17, i64 %34
%38 = load double, double* %37
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), double %36, double %38)
%40 = add nuw nsw i64 %34, 1
%41 = icmp eq i64 %40, %27
br i1 %41, label %28, label %33
42: ; preds = %12
%43 = tail call i32 @putchar(i32 10)
%44 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.6, i64 0, i64 0))
br label %45
45: ; preds = %51, %42, %28
%46 = tail call i32 @putchar(i32 10)
%47 = tail call i32 @free(double* %15)
%48 = tail call i32 @free(double* %17)
%49 = tail call i32 @free(double* %19)
%50 = tail call i32 @free(double* %21)
ret i32 0
51: ; preds = %31, %51
%52 = phi i64 [ 0, %31 ], [ %58, %51 ]
%53 = getelementptr inbounds double, double* %19, i64 %52
%54 = load double, double* %53
%55 = getelementptr inbounds double, double* %21, i64 %52
%56 = load double, double* %55
%57 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), double %54, double %56)
%58 = add nuw nsw i64 %52, 1
%59 = icmp eq i64 %58, %32
br i1 %59, label %45, label %51
}