#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ fresnl(double, double *, double *);
scalar_t__ malloc(unsigned int const);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ write_data_as_json(int /*<<< orphan*/ *, double *, double *,
                                      unsigned int const);
void generate(double *x, const unsigned int len, const char *name) {
  unsigned int i;
  double *C;
  double S;
  FILE *f;
  C = (double *)malloc(len * sizeof(double));
  if (C == NULL) {
    printf("Error allocating memory.\n");
    exit(1);
  }
  for (i = 0; i < len; i++) {
    fresnl(x[i], &S, C + i);
  }
  f = fopen(name, "w");
  if (f == NULL) {
    printf("Error opening file.\n");
    exit(1);
  }
  write_data_as_json(f, x, C, len);
  fclose(f);
  free(C);
}


x86 assembly (clang, -O0):
<generate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x3,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c6 <generate+0x46>
lea    0xe49(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    120a <generate+0x8a>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%eax
shl    $0x3,%rax
add    %rax,%rsi
lea    -0x30(%rbp),%rdi
call   1060 <fresnl@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11cd <generate+0x4d>
mov    -0x18(%rbp),%rdi
lea    0xe05(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    123f <generate+0xbf>
lea    0xdec(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0xc(%rbp),%ecx
call   1070 <write_data_as_json@plt>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,0x8(%rsp)
mov    %esi,%r14d
mov    %rdi,%r15
lea    0x0(,%r14,8),%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1234 <generate+0xb4>
mov    %rax,%rbx
test   %r14d,%r14d
je     11eb <generate+0x6b>
mov    %r14d,%ebp
shl    $0x3,%rbp
xor    %r12d,%r12d
lea    0x10(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
movsd  (%r15,%r12,1),%xmm0
lea    (%rbx,%r12,1),%rsi
mov    %r13,%rdi
call   1060 <fresnl@plt>
add    $0x8,%r12
cmp    %r12,%rbp
jne    11d0 <generate+0x50>
lea    0xe0e(%rip),%rsi
mov    0x8(%rsp),%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     123d <generate+0xbd>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r14d,%ecx
call   1070 <write_data_as_json@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xddb(%rip),%rdi
jmp    1244 <generate+0xc4>
lea    0xdbe(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"Error allocating memory.\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [21 x i8] c"Error opening file.\0A\00"
define void @generate(double* %0, i32 %1, i8* %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca double*
%9 = alloca double
%10 = alloca i32*
store double* %0, double** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%11 = load i32, i32* %5
%12 = zext i32 %11 to i64
%13 = mul i64 %12, 8
%14 = trunc i64 %13 to i32
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to double*
store double* %16, double** %8
%17 = load double*, double** %8
%18 = icmp eq double* %17, null
br i1 %18, label %19, label %22
19: ; preds = %3
%20 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %3
store i32 0, i32* %7
br label %23
23: ; preds = %38, %22
%24 = load i32, i32* %7
%25 = load i32, i32* %5
%26 = icmp ult i32 %24, %25
br i1 %26, label %27, label %41
27: ; preds = %23
%28 = load double*, double** %4
%29 = load i32, i32* %7
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds double, double* %28, i64 %30
%32 = load double, double* %31
%33 = load double*, double** %8
%34 = load i32, i32* %7
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds double, double* %33, i64 %35
%37 = call i32 @fresnl(double %32, double* %9, double* %36)
br label %38
38: ; preds = %27
%39 = load i32, i32* %7
%40 = add i32 %39, 1
store i32 %40, i32* %7
br label %23
41: ; preds = %23
%42 = load i8*, i8** %6
%43 = call i32* @fopen(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %43, i32** %10
%44 = load i32*, i32** %10
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %49
46: ; preds = %41
%47 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %41
%50 = load i32*, i32** %10
%51 = load double*, double** %4
%52 = load double*, double** %8
%53 = load i32, i32* %5
%54 = call i32 @write_data_as_json(i32* %50, double* %51, double* %52, i32 %53)
%55 = load i32*, i32** %10
%56 = call i32 @fclose(i32* %55)
%57 = load double*, double** %8
%58 = call i32 @free(double* %57)
ret void
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"w\00"
@str = [20 x i8] c"Error opening file.\00"
@str.3 = [25 x i8] c"Error allocating memory.\00"
define void @generate(double* %0, i32 %1, i8* nocapture %2) {
%4 = alloca double
%5 = bitcast double* %4 to i8*
%6 = shl i32 %1, 3
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to double*
%9 = icmp eq i64 %7, 0
br i1 %9, label %14, label %10
10: ; preds = %3
%11 = icmp eq i32 %1, 0
br i1 %11, label %25, label %12
12: ; preds = %10
%13 = zext i32 %1 to i64
br label %17
14: ; preds = %3
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.3, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %12, %17
%18 = phi i64 [ 0, %12 ], [ %23, %17 ]
%19 = getelementptr inbounds double, double* %0, i64 %18
%20 = load double, double* %19
%21 = getelementptr inbounds double, double* %8, i64 %18
%22 = call i32 @fresnl(double %20, double* %4, double* %21)
%23 = add nuw nsw i64 %18, 1
%24 = icmp eq i64 %23, %13
br i1 %24, label %25, label %17
25: ; preds = %17, %10
%26 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %25
%32 = call i32 @write_data_as_json(i32* %26, double* %0, double* %8, i32 %1)
%33 = call i32 @fclose(i32* %26)
%34 = call i32 @free(double* %8)
ret void
}