#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 O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ S_IRWXU;
int open(char *, int, int /*<<< orphan*/);
int sprintf(char *, char *, int);
int createWRFileInBatch(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_CREAT | O_WRONLY | O_TRUNC, S_IRWXU);
    }
  }
  return retValue;
}


x86 assembly (clang, -O0):
<createWRFileInBatch>:
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     11f1 <createWRFileInBatch+0xd1>
cmpl   $0x0,-0xc(%rbp)
jle    11f1 <createWRFileInBatch+0xd1>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    117b <createWRFileInBatch+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 <createWRFileInBatch+0x32>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ec <createWRFileInBatch+0xcc>
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    0x2e49(%rip),%rax
mov    (%rax),%esi
mov    0x2e08(%rip),%rax
or     (%rax),%esi
mov    0x2e2f(%rip),%rax
or     (%rax),%esi
mov    0x2e0e(%rip),%rax
mov    (%rax),%edx
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 <createWRFileInBatch+0x62>
jmp    11f1 <createWRFileInBatch+0xd1>
mov    -0x10(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createWRFileInBatch>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
test   %rdi,%rdi
je     11be <createWRFileInBatch+0x8e>
test   %esi,%esi
jle    11be <createWRFileInBatch+0x8e>
mov    %rdi,%r14
mov    %esi,%r13d
lea    0x0(,%r13,4),%rdx
mov    $0xff,%esi
call   1030 <memset@plt>
xor    %ebx,%ebx
mov    %rsp,%r12
mov    0x2e85(%rip),%rbp
mov    0x2e66(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
lea    0xe76(%rip),%rsi
mov    %ebx,%edx
call   1050 <sprintf@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
mov    0x2e57(%rip),%rax
or     (%rax),%esi
or     0x0(%rbp),%esi
mov    (%r15),%edx
mov    %r12,%rdi
call   1040 <open@plt>
mov    %eax,(%r14,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1180 <createWRFileInBatch+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_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@S_IRWXU = global i32 0
define i32 @createWRFileInBatch(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 %53
12: ; preds = %2
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %53
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 = %49, %28
%30 = load i32, i32* %7
%31 = load i32, i32* %4
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %52
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_CREAT
%39 = load i32, i32* @O_WRONLY
%40 = or i32 %38, %39
%41 = load i32, i32* @O_TRUNC
%42 = or i32 %40, %41
%43 = load i32, i32* @S_IRWXU
%44 = call i32 @open(i8* %37, i32 %42, i32 %43)
%45 = load i32*, i32** %3
%46 = load i32, i32* %7
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %45, i64 %47
store i32 %44, i32* %48
br label %49
49: ; preds = %33
%50 = load i32, i32* %7
%51 = add nsw i32 %50, 1
store i32 %51, i32* %7
br label %29
52: ; preds = %29
br label %53
53: ; preds = %52, %12, %2
%54 = load i32, i32* %5
ret i32 %54
}

LLVM IR (-O2):
@.str = [9 x i8] c"tmp.%03d\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@S_IRWXU = global i32 0
define i32 @createWRFileInBatch(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 %26
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 ], [ %24, %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_CREAT
%17 = load i32, i32* @O_WRONLY
%18 = or i32 %17, %16
%19 = load i32, i32* @O_TRUNC
%20 = or i32 %18, %19
%21 = load i32, i32* @S_IRWXU
%22 = call i32 @open(i8* %11, i32 %20, i32 %21)
%23 = getelementptr inbounds i32, i32* %0, i64 %13
store i32 %22, i32* %23
%24 = add nuw nsw i64 %13, 1
%25 = icmp eq i64 %24, %9
br i1 %25, label %26, label %12
26: ; preds = %12, %2
ret i32 0
}