#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*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int gen_med_hist_out_closes(FILE *fp) {
  char *aux, *streamtype, streamno[5];
  int i;
  for (i = 1; i < 12; i++) {
    fprintf(fp, " CASE ( AUXHIST%d_ALARM )\n", i);
    fprintf(fp,
            "     IF ( grid%%nframes(stream) >= "
            "config_flags%%frames_per_auxhist%d ) THEN\n",
            i);
    fprintf(fp,
            "       CALL close_dataset ( grid%%auxhist%d_oid , config_flags , "
            "n2 )\n",
            i);
    fprintf(fp, "       grid%%auxhist%d_oid = 0\n", i);
    fprintf(fp, "       grid%%nframes(stream) = 0\n");
    fprintf(fp, "     ENDIF\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<gen_med_hist_out_closes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0x24(%rbp)
cmpl   $0xc,-0x24(%rbp)
jge    11b3 <gen_med_hist_out_closes+0xa3>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xec5(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xecb(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xf04(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xf36(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xf44(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xf54(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1123 <gen_med_hist_out_closes+0x13>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_med_hist_out_closes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x1,%ebp
lea    0xf2f(%rip),%r12
lea    0xf6f(%rip),%r13
lea    0xf88(%rip),%r14
lea    0xfa3(%rip),%r15
nop
mov    %rbx,%rdi
lea    0xea6(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %rbx,%rdi
lea    0xeae(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0xb,%esi
mov    $0x1,%edx
mov    %r15,%rdi
mov    %rbx,%rcx
call   1040 <fwrite@plt>
add    $0x1,%ebp
cmp    $0xc,%ebp
jne    1150 <gen_med_hist_out_closes+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c" CASE ( AUXHIST%d_ALARM )\0A\00"
@.str.1 = [78 x i8] c" IF ( grid%%nframes(stream) >= config_flags%%frames_per_auxhist%d ) THEN\0A\00"
@.str.2 = [71 x i8] c" CALL close_dataset ( grid%%auxhist%d_oid , config_flags , n2 )\0A\00"
@.str.3 = [32 x i8] c" grid%%auxhist%d_oid = 0\0A\00"
@.str.4 = [34 x i8] c" grid%%nframes(stream) = 0\0A\00"
@.str.5 = [12 x i8] c" ENDIF\0A\00"
define i32 @gen_med_hist_out_closes(i32* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [5 x i8]
%6 = alloca i32
store i32* %0, i32** %2
store i32 1, i32* %6
br label %7
7: ; preds = %27, %1
%8 = load i32, i32* %6
%9 = icmp slt i32 %8, 12
br i1 %9, label %10, label %30
10: ; preds = %7
%11 = load i32*, i32** %2
%12 = load i32, i32* %6
%13 = call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i32*, i32** %2
%15 = load i32, i32* %6
%16 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = load i32*, i32** %2
%18 = load i32, i32* %6
%19 = call i32 (i32*, i8*, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = load i32*, i32** %2
%21 = load i32, i32* %6
%22 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = load i32*, i32** %2
%24 = call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%25 = load i32*, i32** %2
%26 = call i32 (i32*, i8*, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
br label %27
27: ; preds = %10
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
br label %7
30: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c" CASE ( AUXHIST%d_ALARM )\0A\00"
@.str.1 = [78 x i8] c" IF ( grid%%nframes(stream) >= config_flags%%frames_per_auxhist%d ) THEN\0A\00"
@.str.2 = [71 x i8] c" CALL close_dataset ( grid%%auxhist%d_oid , config_flags , n2 )\0A\00"
@.str.3 = [32 x i8] c" grid%%auxhist%d_oid = 0\0A\00"
@.str.4 = [34 x i8] c" grid%%nframes(stream) = 0\0A\00"
@.str.5 = [12 x i8] c" ENDIF\0A\00"
define i32 @gen_med_hist_out_closes(i32* nocapture %0) {
br label %2
2: ; preds = %1, %2
%3 = phi i32 [ 1, %1 ], [ %10, %2 ]
%4 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%6 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.2, i64 0, i64 0), i32 %3)
%7 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %3)
%8 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%9 = tail call i64 @fwrite(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i64 11, i64 1, i32* %0)
%10 = add nuw nsw i32 %3, 1
%11 = icmp eq i32 %10, 12
br i1 %11, label %12, label %2
12: ; preds = %2
ret i32 0
}