#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*/ abort();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ generate_records(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  srand(time(NULL));
  int n = 5;
  int i;
  for (i = 1; i <= n; ++i) {
    char file_name[32];
    sprintf(file_name, "d%d", i);
    FILE *strm = fopen(file_name, "w");
    if (strm == NULL)
      abort();
    generate_records(i, strm);
    fclose(strm);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
movl   $0x5,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1205 <main+0x95>
lea    -0x30(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe49(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x30(%rbp),%rdi
lea    0xe3d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11e2 <main+0x72>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0xc(%rbp),%edi
mov    -0x38(%rbp),%rsi
call   1070 <generate_records@plt>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    119d <main+0x2d>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
lea    0xe76(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x1,%edx
call   1090 <sprintf@plt>
lea    0xe63(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     12e6 <main+0x176>
mov    %rax,%rbx
mov    $0x1,%edi
mov    %rax,%rsi
call   1070 <generate_records@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe2f(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x2,%edx
call   1090 <sprintf@plt>
lea    0xe1c(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     12e6 <main+0x176>
mov    %rax,%rbx
mov    $0x2,%edi
mov    %rax,%rsi
call   1070 <generate_records@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xde8(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x3,%edx
call   1090 <sprintf@plt>
lea    0xdd5(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     12e6 <main+0x176>
mov    %rax,%rbx
mov    $0x3,%edi
mov    %rax,%rsi
call   1070 <generate_records@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xda1(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x4,%edx
call   1090 <sprintf@plt>
lea    0xd8e(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     12e6 <main+0x176>
mov    %rax,%rbx
mov    $0x4,%edi
mov    %rax,%rsi
call   1070 <generate_records@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xd5e(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x5,%edx
call   1090 <sprintf@plt>
lea    0xd4b(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     12e6 <main+0x176>
mov    %rax,%rbx
mov    $0x5,%edi
mov    %rax,%rsi
call   1070 <generate_records@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"d%d\00"
@.str.1 = [2 x i8] c"w\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [32 x i8]
%5 = alloca i32*
store i32 0, i32* %1
%6 = call i32 @time(i32* null)
%7 = call i32 @srand(i32 %6)
store i32 5, i32* %2
store i32 1, i32* %3
br label %8
8: ; preds = %28, %0
%9 = load i32, i32* %3
%10 = load i32, i32* %2
%11 = icmp sle i32 %9, %10
br i1 %11, label %12, label %31
12: ; preds = %8
%13 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%14 = load i32, i32* %3
%15 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %5
%18 = load i32*, i32** %5
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = call i32 (...) @abort()
unreachable
22: ; preds = %12
%23 = load i32, i32* %3
%24 = load i32*, i32** %5
%25 = call i32 @generate_records(i32 %23, i32* %24)
%26 = load i32*, i32** %5
%27 = call i32 @fclose(i32* %26)
br label %28
28: ; preds = %22
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 1
store i32 %30, i32* %3
br label %8
31: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"d%d\00"
@.str.1 = [2 x i8] c"w\00"
define i32 @main() {
%1 = alloca [32 x i8]
%2 = tail call i32 @time(i32* null)
%3 = tail call i32 @srand(i32 %2)
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%5 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 1)
%6 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %28, %22, %16, %10, %0
%9 = tail call i32 (...) @abort()
unreachable
10: ; preds = %0
%11 = tail call i32 @generate_records(i32 1, i32* %6)
%12 = tail call i32 @fclose(i32* %6)
%13 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 2)
%14 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %8, label %16
16: ; preds = %10
%17 = tail call i32 @generate_records(i32 2, i32* %14)
%18 = tail call i32 @fclose(i32* %14)
%19 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%20 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %8, label %22
22: ; preds = %16
%23 = tail call i32 @generate_records(i32 3, i32* %20)
%24 = tail call i32 @fclose(i32* %20)
%25 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 4)
%26 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %8, label %28
28: ; preds = %22
%29 = tail call i32 @generate_records(i32 4, i32* %26)
%30 = tail call i32 @fclose(i32* %26)
%31 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 5)
%32 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%33 = icmp eq i32* %32, null
br i1 %33, label %8, label %34
34: ; preds = %28
%35 = tail call i32 @generate_records(i32 5, i32* %32)
%36 = tail call i32 @fclose(i32* %32)
ret i32 0
}