#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*/ KAPI_save_as_header_int(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ KAPI_save_as_header_int_list(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int strlen(char *);
void KAPI_save_as_header_int_array(FILE *fp, int *pint,
                                   int number_of_elements) {
  int i;
  FILE *fpTmp = fp;
  fwrite("{", sizeof(char), 1, fpTmp);
  for (i = 0; i < number_of_elements - 1; i++)
    KAPI_save_as_header_int_list(fp, pint[i]);
  KAPI_save_as_header_int(fp, pint[i]);
  fwrite("}\n", sizeof(char), strlen("}\n"), fpTmp);
}


x86 assembly (clang, -O0):
<KAPI_save_as_header_int_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
lea    0xe9a(%rip),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1060 <fwrite@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11ac <KAPI_save_as_header_int_array+0x6c>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1050 <KAPI_save_as_header_int_list@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1179 <KAPI_save_as_header_int_array+0x39>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1040 <KAPI_save_as_header_int@plt>
lea    0xe3b(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%edx
mov    -0x20(%rbp),%rcx
lea    0xe29(%rip),%rdi
mov    $0x1,%esi
call   1060 <fwrite@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<KAPI_save_as_header_int_array>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%r14
mov    $0x7b,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
cmp    $0x2,%ebp
jl     1197 <KAPI_save_as_header_int_array+0x47>
add    $0xffffffff,%ebp
mov    %ebp,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    (%r15,%rbx,4),%esi
mov    %r14,%rdi
call   1060 <KAPI_save_as_header_int_list@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1180 <KAPI_save_as_header_int_array+0x30>
jmp    1199 <KAPI_save_as_header_int_array+0x49>
xor    %ebp,%ebp
mov    (%r15,%rbp,4),%esi
mov    %r14,%rdi
call   1050 <KAPI_save_as_header_int@plt>
lea    0xe54(%rip),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r14,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <fwrite@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"{\00"
@.str.1 = [3 x i8] c"}\0A\00"
define void @KAPI_save_as_header_int_array(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%9 = load i32*, i32** %4
store i32* %9, i32** %8
%10 = load i32*, i32** %8
%11 = call i32 @fwrite(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1, i32 1, i32* %10)
store i32 0, i32* %7
br label %12
12: ; preds = %25, %3
%13 = load i32, i32* %7
%14 = load i32, i32* %6
%15 = sub nsw i32 %14, 1
%16 = icmp slt i32 %13, %15
br i1 %16, label %17, label %28
17: ; preds = %12
%18 = load i32*, i32** %4
%19 = load i32*, i32** %5
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = load i32, i32* %22
%24 = call i32 @KAPI_save_as_header_int_list(i32* %18, i32 %23)
br label %25
25: ; preds = %17
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
store i32 %27, i32* %7
br label %12
28: ; preds = %12
%29 = load i32*, i32** %4
%30 = load i32*, i32** %5
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
%34 = load i32, i32* %33
%35 = call i32 @KAPI_save_as_header_int(i32* %29, i32 %34)
%36 = call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%37 = load i32*, i32** %8
%38 = call i32 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 %36, i32* %37)
ret void
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"}\0A\00"
define void @KAPI_save_as_header_int_array(i32* %0, i32* nocapture %1, i32 %2) {
%4 = tail call i32 @fputc(i32 123, i32* %0)
%5 = add i32 %2, -1
%6 = icmp sgt i32 %2, 1
br i1 %6, label %7, label %18
7: ; preds = %3
%8 = zext i32 %5 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %14, %9 ]
%11 = getelementptr inbounds i32, i32* %1, i64 %10
%12 = load i32, i32* %11
%13 = tail call i32 @KAPI_save_as_header_int_list(i32* %0, i32 %12)
%14 = add nuw nsw i64 %10, 1
%15 = icmp eq i64 %14, %8
br i1 %15, label %16, label %9
16: ; preds = %9
%17 = zext i32 %5 to i64
br label %18
18: ; preds = %3, %16
%19 = phi i64 [ %17, %16 ], [ 0, %3 ]
%20 = getelementptr inbounds i32, i32* %1, i64 %19
%21 = load i32, i32* %20
%22 = tail call i32 @KAPI_save_as_header_int(i32* %0, i32 %21)
%23 = tail call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%24 = tail call i32 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 %23, i32* %0)
ret void
}