#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*/ *fopen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, unsigned long);
void file_init(char *grp, unsigned long grp_size, FILE **f) {
  char fname[20];
  unsigned long i;
  for (i = 0; i < grp_size; i++) {
    sprintf(fname, "%s_%03lu.dat", grp, i);
    f[i] = fopen(fname, "w");
  }
}


x86 assembly (clang, -O0):
<file_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1192 <file_init+0x72>
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x38(%rbp),%rcx
lea    0xea3(%rip),%rsi
call   1040 <sprintf@plt>
lea    -0x30(%rbp),%rdi
lea    0xea0(%rip),%rsi
call   1030 <fopen@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    113c <file_init+0x1c>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_init>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %rsi,%rsi
je     117d <file_init+0x5d>
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
xor    %ebx,%ebx
mov    %rsp,%rbp
lea    0xec5(%rip),%r13
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
lea    0xea6(%rip),%rsi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1040 <sprintf@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1030 <fopen@plt>
mov    %rax,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1150 <file_init+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"%s_%03lu.dat\00"
@.str.1 = [2 x i8] c"w\00"
define void @file_init(i8* %0, i64 %1, i32** %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32**
%7 = alloca [20 x i8]
%8 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
store i32** %2, i32*** %6
store i64 0, i64* %8
br label %9
9: ; preds = %23, %3
%10 = load i64, i64* %8
%11 = load i64, i64* %5
%12 = icmp ult i64 %10, %11
br i1 %12, label %13, label %26
13: ; preds = %9
%14 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%15 = load i8*, i8** %4
%16 = load i64, i64* %8
%17 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %15, i64 %16)
%18 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32**, i32*** %6
%21 = load i64, i64* %8
%22 = getelementptr inbounds i32*, i32** %20, i64 %21
store i32* %19, i32** %22
br label %23
23: ; preds = %13
%24 = load i64, i64* %8
%25 = add i64 %24, 1
store i64 %25, i64* %8
br label %9
26: ; preds = %9
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"%s_%03lu.dat\00"
@.str.1 = [2 x i8] c"w\00"
define void @file_init(i8* %0, i64 %1, i32** nocapture writeonly %2) {
%4 = alloca [20 x i8]
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%6 = icmp eq i64 %1, 0
br i1 %6, label %14, label %7
7: ; preds = %3, %7
%8 = phi i64 [ %12, %7 ], [ 0, %3 ]
%9 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %0, i64 %8)
%10 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = getelementptr inbounds i32*, i32** %2, i64 %8
store i32* %10, i32** %11
%12 = add nuw i64 %8, 1
%13 = icmp eq i64 %12, %1
br i1 %13, label %14, label %7
14: ; preds = %7, %3
ret void
}