#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 /*<<< orphan*/ O_RDONLY;
int open(char *, int /*<<< orphan*/);
int sprintf(char *, char *, int);
int createRDFileInBatch(int fileHandlerArray[], int fileHandlerArraySize) {
  int retValue = 0;
  if (fileHandlerArray != NULL && fileHandlerArraySize > 0) {
    for (int i = 0; i < fileHandlerArraySize; i++) {
      fileHandlerArray[i] = -1;
    }
    for (int i = 0; i < fileHandlerArraySize; i++) {
      char buffer[64];
      int n = sprintf(buffer, "tmp.%03d", i);
      fileHandlerArray[i] = open(buffer, O_RDONLY);
    }
  }
  return retValue;
}


x86 assembly (clang, -O0):
<createRDFileInBatch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11d6 <createRDFileInBatch+0xb6>
cmpl   $0x0,-0xc(%rbp)
jle    11d6 <createRDFileInBatch+0xb6>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    117b <createRDFileInBatch+0x5b>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1152 <createRDFileInBatch+0x32>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d1 <createRDFileInBatch+0xb1>
lea    -0x60(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xe64(%rip),%rsi
call   1040 <sprintf@plt>
mov    %eax,-0x64(%rbp)
lea    -0x60(%rbp),%rdi
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
call   1030 <open@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1182 <createRDFileInBatch+0x62>
jmp    11d6 <createRDFileInBatch+0xb6>
mov    -0x10(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createRDFileInBatch>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
test   %rdi,%rdi
je     11a5 <createRDFileInBatch+0x75>
test   %esi,%esi
jle    11a5 <createRDFileInBatch+0x75>
mov    %rdi,%r14
mov    %esi,%r13d
lea    0x0(,%r13,4),%rdx
mov    $0xff,%esi
call   1030 <memset@plt>
xor    %ebx,%ebx
lea    0xe98(%rip),%r15
mov    %rsp,%r12
mov    0x2e76(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1050 <sprintf@plt>
mov    0x0(%rbp),%esi
mov    %r12,%rdi
call   1040 <open@plt>
mov    %eax,(%r14,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1180 <createRDFileInBatch+0x50>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [9 x i8] c"tmp.%03d\00"
@O_RDONLY = global i32 0
define i32 @createRDFileInBatch(i32* writeonly %0, i32 %1) {
%3 = alloca [64 x i8]
%4 = icmp ne i32* %0, null
%5 = icmp sgt i32 %1, 0
%6 = and i1 %4, %5
br i1 %6, label %7, label %21
7: ; preds = %2
%8 = bitcast i32* %0 to i8*
%9 = zext i32 %1 to i64
%10 = shl nuw nsw i64 %9, 2
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
br label %12
12: ; preds = %7, %12
%13 = phi i64 [ 0, %7 ], [ %19, %12 ]
%14 = trunc i64 %13 to i32
%15 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = load i32, i32* @O_RDONLY
%17 = call i32 @open(i8* %11, i32 %16)
%18 = getelementptr inbounds i32, i32* %0, i64 %13
store i32 %17, i32* %18
%19 = add nuw nsw i64 %13, 1
%20 = icmp eq i64 %19, %9
br i1 %20, label %21, label %12
21: ; preds = %12, %2
ret i32 0
}