#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 channel_get_count();
int channel_get_sv_id(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
void schedule_shutdown(void) {
  FILE *f;
  int q;
  f = fopen("priority.txt", "w+");
  for (q = 0; q < channel_get_count(); q++) {
    int sv = channel_get_sv_id(q);
    if (sv > 0)
      fprintf(f, "%i\n", sv);
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<schedule_shutdown>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xea1(%rip),%rdi
lea    0xea7(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1030 <channel_get_count@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jge    11cb <schedule_shutdown+0x7b>
mov    -0xc(%rbp),%edi
call   1070 <channel_get_sv_id@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    11b8 <schedule_shutdown+0x68>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xe5d(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11bd <schedule_shutdown+0x6d>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1176 <schedule_shutdown+0x26>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<schedule_shutdown>:
push   %rbp
push   %r14
push   %rbx
lea    0xea5(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <channel_get_count@plt>
test   %eax,%eax
jle    11a8 <schedule_shutdown+0x58>
lea    0xe94(%rip),%r14
xor    %ebp,%ebp
jmp    118e <schedule_shutdown+0x3e>
add    $0x1,%ebp
xor    %eax,%eax
call   1030 <channel_get_count@plt>
cmp    %eax,%ebp
jge    11a8 <schedule_shutdown+0x58>
mov    %ebp,%edi
call   1070 <channel_get_sv_id@plt>
test   %eax,%eax
jle    1180 <schedule_shutdown+0x30>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1050 <fprintf@plt>
jmp    1180 <schedule_shutdown+0x30>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <fclose@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"priority.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [4 x i8] c"%i\0A\00"
define void @schedule_shutdown() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i32
%4 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %1
store i32 0, i32* %2
br label %5
5: ; preds = %19, %0
%6 = load i32, i32* %2
%7 = call i32 (...) @channel_get_count()
%8 = icmp slt i32 %6, %7
br i1 %8, label %9, label %22
9: ; preds = %5
%10 = load i32, i32* %2
%11 = call i32 @channel_get_sv_id(i32 %10)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i32*, i32** %1
%16 = load i32, i32* %3
%17 = call i32 @fprintf(i32* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %14, %9
br label %19
19: ; preds = %18
%20 = load i32, i32* %2
%21 = add nsw i32 %20, 1
store i32 %21, i32* %2
br label %5
22: ; preds = %5
%23 = load i32*, i32** %1
%24 = call i32 @fclose(i32* %23)
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"priority.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [4 x i8] c"%i\0A\00"
define void @schedule_shutdown() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i32 (...) @channel_get_count()
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %14
4: ; preds = %0, %10
%5 = phi i32 [ %11, %10 ], [ 0, %0 ]
%6 = tail call i32 @channel_get_sv_id(i32 %5)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %6)
br label %10
10: ; preds = %8, %4
%11 = add nuw nsw i32 %5, 1
%12 = tail call i32 (...) @channel_get_count()
%13 = icmp slt i32 %11, %12
br i1 %13, label %4, label %14
14: ; preds = %10, %0
%15 = tail call i32 @fclose(i32* %1)
ret void
}