#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*/ WrMessage(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ *tmpfile();
void WrOpenFiles(void) {
  int i;
  int no_files;
  FILE *infiles[90];
  WrMessage("@NUMBER-OPEN-FILES");
  WrMessage("@NUMBER-OPEN-FILES-NO-MACRO");
  no_files = 0;
  for (i = 0; i < 90; i++) {
    infiles[i] = tmpfile();
    if (infiles[i] == NULL) {
      break;
    } else {
      no_files = i + 1;
    }
  }
  if (no_files >= 90) {
    WrMessage("@NUMBER-OPEN-FILES-UNLIMITED");
  } else {
    WrMessage("@NUMBER-OPEN-FILES-LIMITED");
    printf("Number of files opened: %d\n\n", no_files);
  }
  for (i = 0; i < no_files; i++) {
    fclose(infiles[i]);
  }
  return;
}


x86 assembly (clang, -O0):
<WrOpenFiles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2e0,%rsp
lea    0xeae(%rip),%rdi
call   1060 <WrMessage@plt>
lea    0xeb5(%rip),%rdi
call   1060 <WrMessage@plt>
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0x5a,-0x4(%rbp)
jge    11c5 <WrOpenFiles+0x85>
mov    $0x0,%al
call   1050 <tmpfile@plt>
mov    %rax,%rcx
movslq -0x4(%rbp),%rax
mov    %rcx,-0x2e0(%rbp,%rax,8)
ff
movslq -0x4(%rbp),%rax
cmpq   $0x0,-0x2e0(%rbp,%rax,8)
jne    11a9 <WrOpenFiles+0x69>
jmp    11c5 <WrOpenFiles+0x85>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11b7 <WrOpenFiles+0x77>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1171 <WrOpenFiles+0x31>
cmpl   $0x5a,-0x8(%rbp)
jl     11e0 <WrOpenFiles+0xa0>
lea    0xe59(%rip),%rdi
call   1060 <WrMessage@plt>
jmp    11fb <WrOpenFiles+0xbb>
lea    0xe65(%rip),%rdi
call   1060 <WrMessage@plt>
mov    -0x8(%rbp),%esi
lea    0xe71(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    122d <WrOpenFiles+0xed>
movslq -0x4(%rbp),%rax
mov    -0x2e0(%rbp,%rax,8),%rdi
ff
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1202 <WrOpenFiles+0xc2>
add    $0x2e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WrOpenFiles>:
push   %r14
push   %rbx
sub    $0x2d8,%rsp
lea    0xeaf(%rip),%rdi
call   1060 <WrMessage@plt>
lea    0xeb6(%rip),%rdi
call   1060 <WrMessage@plt>
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1050 <tmpfile@plt>
mov    %rax,(%rsp,%r14,8)
test   %rax,%rax
je     119e <WrOpenFiles+0x5e>
add    $0x1,%r14
cmp    $0x5a,%r14
jne    1170 <WrOpenFiles+0x30>
lea    0xe9e(%rip),%rdi
call   1060 <WrMessage@plt>
mov    $0x5a,%r14d
jmp    11be <WrOpenFiles+0x7e>
lea    0xea7(%rip),%rdi
call   1060 <WrMessage@plt>
lea    0xeb6(%rip),%rdi
mov    %r14d,%esi
call   1040 <printf@plt>
test   %r14d,%r14d
je     11d2 <WrOpenFiles+0x92>
xor    %ebx,%ebx
mov    (%rsp,%rbx,8),%rdi
call   1030 <fclose@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    11c0 <WrOpenFiles+0x80>
add    $0x2d8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [19 x i8] c"@NUMBER-OPEN-FILES\00"
@.str.1 = [28 x i8] c"@NUMBER-OPEN-FILES-NO-MACRO\00"
@.str.2 = [29 x i8] c"@NUMBER-OPEN-FILES-UNLIMITED\00"
@.str.3 = [27 x i8] c"@NUMBER-OPEN-FILES-LIMITED\00"
@.str.4 = [29 x i8] c"Number of files opened: %d\0A\0A\00"
define void @WrOpenFiles() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [90 x i32*]
%4 = call i32 @WrMessage(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @WrMessage(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
store i32 0, i32* %1
br label %6
6: ; preds = %24, %0
%7 = load i32, i32* %1
%8 = icmp slt i32 %7, 90
br i1 %8, label %9, label %27
9: ; preds = %6
%10 = call i32* (...) @tmpfile()
%11 = load i32, i32* %1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [90 x i32*], [90 x i32*]* %3, i64 0, i64 %12
store i32* %10, i32** %13
%14 = load i32, i32* %1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [90 x i32*], [90 x i32*]* %3, i64 0, i64 %15
%17 = load i32*, i32** %16
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %20
19: ; preds = %9
br label %27
20: ; preds = %9
%21 = load i32, i32* %1
%22 = add nsw i32 %21, 1
store i32 %22, i32* %2
br label %23
23: ; preds = %20
br label %24
24: ; preds = %23
%25 = load i32, i32* %1
%26 = add nsw i32 %25, 1
store i32 %26, i32* %1
br label %6
27: ; preds = %19, %6
%28 = load i32, i32* %2
%29 = icmp sge i32 %28, 90
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 @WrMessage(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %36
32: ; preds = %27
%33 = call i32 @WrMessage(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%34 = load i32, i32* %2
%35 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %32, %30
store i32 0, i32* %1
br label %37
37: ; preds = %47, %36
%38 = load i32, i32* %1
%39 = load i32, i32* %2
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %50
41: ; preds = %37
%42 = load i32, i32* %1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [90 x i32*], [90 x i32*]* %3, i64 0, i64 %43
%45 = load i32*, i32** %44
%46 = call i32 @fclose(i32* %45)
br label %47
47: ; preds = %41
%48 = load i32, i32* %1
%49 = add nsw i32 %48, 1
store i32 %49, i32* %1
br label %37
50: ; preds = %37
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"@NUMBER-OPEN-FILES\00"
@.str.1 = [28 x i8] c"@NUMBER-OPEN-FILES-NO-MACRO\00"
@.str.2 = [29 x i8] c"@NUMBER-OPEN-FILES-UNLIMITED\00"
@.str.3 = [27 x i8] c"@NUMBER-OPEN-FILES-LIMITED\00"
@.str.4 = [29 x i8] c"Number of files opened: %d\0A\0A\00"
define void @WrOpenFiles() {
%1 = alloca [90 x i32*]
%2 = bitcast [90 x i32*]* %1 to i8*
%3 = tail call i32 @WrMessage(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @WrMessage(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %5
5: ; preds = %0, %10
%6 = phi i64 [ 0, %0 ], [ %11, %10 ]
%7 = tail call i32* (...) @tmpfile()
%8 = getelementptr inbounds [90 x i32*], [90 x i32*]* %1, i64 0, i64 %6
store i32* %7, i32** %8
%9 = icmp eq i32* %7, null
br i1 %9, label %15, label %10
10: ; preds = %5
%11 = add nuw nsw i64 %6, 1
%12 = icmp eq i64 %11, 90
br i1 %12, label %13, label %5
13: ; preds = %10
%14 = tail call i32 @WrMessage(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %20
15: ; preds = %5
%16 = trunc i64 %6 to i32
%17 = tail call i32 @WrMessage(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%18 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%19 = icmp eq i32 %16, 0
br i1 %19, label %30, label %20
20: ; preds = %13, %15
%21 = phi i64 [ 90, %13 ], [ %6, %15 ]
%22 = and i64 %21, 4294967295
br label %23
23: ; preds = %20, %23
%24 = phi i64 [ 0, %20 ], [ %28, %23 ]
%25 = getelementptr inbounds [90 x i32*], [90 x i32*]* %1, i64 0, i64 %24
%26 = load i32*, i32** %25
%27 = tail call i32 @fclose(i32* %26)
%28 = add nuw nsw i64 %24, 1
%29 = icmp eq i64 %28, %22
br i1 %29, label %30, label %23
30: ; preds = %23, %15
ret void
}