#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printf(char *, ...);
void fprint_int_array(int *arr, int size, FILE *fp, int op) {
  int i = 0;
  while (i < size) {
    fprintf(fp, "%d", arr[i]);
    if (++i != size)
      fprintf(fp, ",");
  }
  fclose(fp);
  if (op == 1) {
    i = 0;
    while (i < size) {
      printf("%d", arr[i]);
      if (++i != size)
        printf(",");
    }
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<fprint_int_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    119f <fprint_int_array+0x6f>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe91(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
cmp    -0xc(%rbp),%eax
je     119a <fprint_int_array+0x6a>
mov    -0x18(%rbp),%rdi
lea    0xe70(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    114d <fprint_int_array+0x1d>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x1,-0x1c(%rbp)
jne    1208 <fprint_int_array+0xd8>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1203 <fprint_int_array+0xd3>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
cmp    -0xc(%rbp),%eax
je     11fe <fprint_int_array+0xce>
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11b9 <fprint_int_array+0x89>
jmp    1208 <fprint_int_array+0xd8>
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fprint_int_array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbp
test   %esi,%esi
jle    120b <fprint_int_array+0xbb>
mov    %rdi,%rbx
mov    %ecx,0x4(%rsp)
mov    %esi,(%rsp)
mov    %esi,%r13d
lea    -0x1(%r13),%r14
xor    %r12d,%r12d
jmp    1185 <fprint_int_array+0x35>
nopl   0x0(%rax)
cmp    %r12,%r13
je     11b5 <fprint_int_array+0x65>
mov    %r12,%r15
mov    (%rbx,%r12,4),%edx
mov    %rbp,%rdi
lea    0xe6a(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
add    $0x1,%r12
cmp    %r15,%r14
je     1180 <fprint_int_array+0x30>
mov    $0x2c,%edi
mov    %rbp,%rsi
call   1060 <fputc@plt>
jmp    1180 <fprint_int_array+0x30>
mov    %rbx,%r12
mov    %rbp,%rdi
call   1040 <fclose@plt>
cmpl   $0x1,0x4(%rsp)
jne    1213 <fprint_int_array+0xc3>
cmpl   $0x0,(%rsp)
jle    1213 <fprint_int_array+0xc3>
lea    -0x1(%r13),%r15
lea    0xe28(%rip),%r14
xor    %ebx,%ebx
jmp    11e5 <fprint_int_array+0x95>
nopl   0x0(%rax)
cmp    %rbx,%r13
je     1213 <fprint_int_array+0xc3>
mov    %rbx,%rbp
mov    (%r12,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbp,%r15
je     11e0 <fprint_int_array+0x90>
mov    $0x2c,%edi
call   1030 <putchar@plt>
jmp    11e0 <fprint_int_array+0x90>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [2 x i8] c",\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @fprint_int_array(i32* %0, i32 %1, i32* %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32 %3, i32* %8
store i32 0, i32* %9
br label %10
10: ; preds = %29, %4
%11 = load i32, i32* %9
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %30
14: ; preds = %10
%15 = load i32*, i32** %7
%16 = load i32*, i32** %5
%17 = load i32, i32* %9
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
%20 = load i32, i32* %19
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %9
%23 = add nsw i32 %22, 1
store i32 %23, i32* %9
%24 = load i32, i32* %6
%25 = icmp ne i32 %23, %24
br i1 %25, label %26, label %29
26: ; preds = %14
%27 = load i32*, i32** %7
%28 = call i32 (i32*, i8*, ...) @fprintf(i32* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %26, %14
br label %10
30: ; preds = %10
%31 = load i32*, i32** %7
%32 = call i32 @fclose(i32* %31)
%33 = load i32, i32* %8
%34 = icmp eq i32 %33, 1
br i1 %34, label %35, label %55
35: ; preds = %30
store i32 0, i32* %9
br label %36
36: ; preds = %53, %35
%37 = load i32, i32* %9
%38 = load i32, i32* %6
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %54
40: ; preds = %36
%41 = load i32*, i32** %5
%42 = load i32, i32* %9
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
%45 = load i32, i32* %44
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %45)
%47 = load i32, i32* %9
%48 = add nsw i32 %47, 1
store i32 %48, i32* %9
%49 = load i32, i32* %6
%50 = icmp ne i32 %48, %49
br i1 %50, label %51, label %53
51: ; preds = %40
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %53
53: ; preds = %51, %40
br label %36
54: ; preds = %36
br label %55
55: ; preds = %54, %30
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define void @fprint_int_array(i32* nocapture %0, i32 %1, i32* nocapture %2, i32 %3) {
%5 = icmp sgt i32 %1, 0
br i1 %5, label %8, label %6
6: ; preds = %4
%7 = tail call i32 @fclose(i32* %2)
br label %38
8: ; preds = %4
%9 = zext i32 %1 to i64
br label %10
10: ; preds = %8, %19
%11 = phi i64 [ 0, %8 ], [ %15, %19 ]
%12 = getelementptr inbounds i32, i32* %0, i64 %11
%13 = load i32, i32* %12
%14 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = add nuw nsw i64 %11, 1
%16 = icmp eq i64 %15, %9
br i1 %16, label %19, label %17
17: ; preds = %10
%18 = tail call i32 @fputc(i32 44, i32* %2)
br label %19
19: ; preds = %17, %10
%20 = icmp eq i64 %15, %9
br i1 %20, label %21, label %10
21: ; preds = %19
%22 = tail call i32 @fclose(i32* %2)
%23 = icmp eq i32 %3, 1
%24 = and i1 %23, %5
br i1 %24, label %25, label %38
25: ; preds = %21
%26 = zext i32 %1 to i64
br label %27
27: ; preds = %25, %36
%28 = phi i64 [ 0, %25 ], [ %32, %36 ]
%29 = getelementptr inbounds i32, i32* %0, i64 %28
%30 = load i32, i32* %29
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %30)
%32 = add nuw nsw i64 %28, 1
%33 = icmp eq i64 %32, %26
br i1 %33, label %36, label %34
34: ; preds = %27
%35 = tail call i32 @putchar(i32 44)
br label %36
36: ; preds = %34, %27
%37 = icmp eq i64 %32, %26
br i1 %37, label %38, label %27
38: ; preds = %36, %6, %21
%39 = tail call i32 @putchar(i32 10)
ret void
}