#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 int64_t;

/* Variables and functions */
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, int, double);
int /*<<< orphan*/ strcat(char *, char *);
char *csv(int64_t *arr1, double *arr2, int64_t size) {
  int64_t line_size = 20 + 1 + 20 + 1;
  char *to_return = malloc(line_size * size * sizeof(char));
  char line[line_size];
  for (int64_t i = 0; i < size; i++) {
    sprintf(line, "%li,%f\n", arr1[i], arr2[i]);
    strcat(to_return, line);
  }
  return to_return;
}


x86 assembly (clang, -O0):
<csv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x2a,-0x18(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%eax
imul   %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d8 <csv+0xa8>
mov    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe48(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x40(%rbp),%rsi
mov    -0x20(%rbp),%rdi
call   1040 <strcat@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1189 <csv+0x59>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<csv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
imul   $0x2a,%edx,%edi
call   1030 <malloc@plt>
mov    %rax,%r13
test   %ebx,%ebx
jle    118d <csv+0x5d>
mov    %ebx,%ebp
xor    %r12d,%r12d
mov    %rsp,%rbx
nopl   (%rax)
mov    (%r15,%r12,4),%edx
movsd  (%r14,%r12,8),%xmm0
mov    %rbx,%rdi
lea    0xe8c(%rip),%rsi
call   1050 <sprintf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1040 <strcat@plt>
add    $0x1,%r12
cmp    %r12,%rbp
jne    1160 <csv+0x30>
mov    %r13,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%li,%f\0A\00"
define i8* @csv(i32* %0, double* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
store i32* %0, i32** %4
store double* %1, double** %5
store i32 %2, i32* %6
store i32 42, i32* %7
%12 = load i32, i32* %7
%13 = load i32, i32* %6
%14 = mul nsw i32 %12, %13
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 1
%17 = trunc i64 %16 to i32
%18 = call i8* @malloc(i32 %17)
store i8* %18, i8** %8
%19 = load i32, i32* %7
%20 = zext i32 %19 to i64
%21 = call i8* @llvm.stacksave()
store i8* %21, i8** %9
%22 = alloca i8, i64 %20
store i64 %20, i64* %10
store i32 0, i32* %11
br label %23
23: ; preds = %41, %3
%24 = load i32, i32* %11
%25 = load i32, i32* %6
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %44
27: ; preds = %23
%28 = load i32*, i32** %4
%29 = load i32, i32* %11
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
%32 = load i32, i32* %31
%33 = load double*, double** %5
%34 = load i32, i32* %11
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double, double* %33, i64 %35
%37 = load double, double* %36
%38 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %32, double %37)
%39 = load i8*, i8** %8
%40 = call i32 @strcat(i8* %39, i8* %22)
br label %41
41: ; preds = %27
%42 = load i32, i32* %11
%43 = add nsw i32 %42, 1
store i32 %43, i32* %11
br label %23
44: ; preds = %23
%45 = load i8*, i8** %8
%46 = load i8*, i8** %9
ret i8* %45
}

LLVM IR (-O2):
@.str = [8 x i8] c"%li,%f\0A\00"
define i8* @csv(i32* nocapture %0, double* nocapture %1, i32 %2) {
%4 = mul nsw i32 %2, 42
%5 = tail call i8* @malloc(i32 %4)
%6 = alloca [42 x i8]
%7 = getelementptr inbounds [42 x i8], [42 x i8]* %6, i64 0, i64 0
%8 = icmp sgt i32 %2, 0
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = zext i32 %2 to i64
br label %12
11: ; preds = %12, %3
ret i8* %5
12: ; preds = %9, %12
%13 = phi i64 [ 0, %9 ], [ %20, %12 ]
%14 = getelementptr inbounds i32, i32* %0, i64 %13
%15 = load i32, i32* %14
%16 = getelementptr inbounds double, double* %1, i64 %13
%17 = load double, double* %16
%18 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %15, double %17)
%19 = call i32 @strcat(i8* %5, i8* %7)
%20 = add nuw nsw i64 %13, 1
%21 = icmp eq i64 %20, %10
br i1 %21, label %11, label %12
}