#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*/ close(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ *open_file(char *, char *);
int *ignored_channels(char *filename, int nchans) {
  int i, idx, *ignore;
  FILE *ignfile;
  ignore = (int *)malloc(nchans * sizeof(int));
  for (i = 0; i < nchans; i++)
    ignore[i] = 0;
  ignfile = open_file(filename, "r");
  while (1) {
    fscanf(ignfile, "%d", &idx);
    if (feof(ignfile))
      break;
    idx--;
    if ((idx >= 0) && (idx < nchans))
      ignore[idx] = 1;
  }
  close(ignfile);
  return (ignore);
}


x86 assembly (clang, -O0):
<ignored_channels>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a2 <ignored_channels+0x52>
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1179 <ignored_channels+0x29>
mov    -0x8(%rbp),%rdi
lea    0xe53(%rip),%rsi
call   1030 <open_file@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe41(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <fscanf@plt>
mov    -0x28(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     11e2 <ignored_channels+0x92>
jmp    1215 <ignored_channels+0xc5>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     1210 <ignored_channels+0xc0>
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1210 <ignored_channels+0xc0>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
jmp    11b6 <ignored_channels+0x66>
mov    -0x28(%rbp),%rdi
call   1050 <close@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ignored_channels>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r15d
mov    %rdi,%rbx
lea    0x0(,%r15,4),%edi
call   1080 <malloc@plt>
mov    %rax,%r14
test   %r15d,%r15d
jle    1199 <ignored_channels+0x39>
mov    %r15d,%edx
shl    $0x2,%rdx
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
lea    0xe60(%rip),%rsi
mov    %rbx,%rdi
call   1030 <open_file@plt>
mov    %rax,%rbx
lea    0xe50(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %rax,%rax
je     11e5 <ignored_channels+0x85>
mov    %rbx,%rdi
call   1060 <close@plt>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe16(%rip),%r12
lea    0xc(%rsp),%r13
jmp    121b <ignored_channels+0xbb>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %rax,%rax
jne    11cc <ignored_channels+0x6c>
mov    0xc(%rsp),%ecx
lea    -0x1(%rcx),%eax
mov    %eax,0xc(%rsp)
test   %ecx,%ecx
jle    1200 <ignored_channels+0xa0>
cmp    %r15d,%ecx
jg     1200 <ignored_channels+0xa0>
mov    %eax,%eax
movl   $0x1,(%r14,%rax,4)
jmp    1200 <ignored_channels+0xa0>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
define i32* @ignored_channels(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = load i32, i32* %4
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 4
%12 = trunc i64 %11 to i32
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i32*
store i32* %14, i32** %7
store i32 0, i32* %5
br label %15
15: ; preds = %24, %2
%16 = load i32, i32* %5
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %27
19: ; preds = %15
%20 = load i32*, i32** %7
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
store i32 0, i32* %23
br label %24
24: ; preds = %19
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %15
27: ; preds = %15
%28 = load i8*, i8** %3
%29 = call i32* @open_file(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %29, i32** %8
br label %30
30: ; preds = %27, %51
%31 = load i32*, i32** %8
%32 = call i32 @fscanf(i32* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%33 = load i32*, i32** %8
%34 = call i64 @feof(i32* %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %30
br label %52
37: ; preds = %30
%38 = load i32, i32* %6
%39 = add nsw i32 %38, -1
store i32 %39, i32* %6
%40 = load i32, i32* %6
%41 = icmp sge i32 %40, 0
br i1 %41, label %42, label %51
42: ; preds = %37
%43 = load i32, i32* %6
%44 = load i32, i32* %4
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %51
46: ; preds = %42
%47 = load i32*, i32** %7
%48 = load i32, i32* %6
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32, i32* %47, i64 %49
store i32 1, i32* %50
br label %51
51: ; preds = %46, %42, %37
br label %30
52: ; preds = %36
%53 = load i32*, i32** %8
%54 = call i32 @close(i32* %53)
%55 = load i32*, i32** %7
ret i32* %55
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
define i32* @ignored_channels(i8* %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = shl i32 %1, 2
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i32*
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = inttoptr i64 %6 to i8*
%11 = zext i32 %1 to i64
%12 = shl nuw nsw i64 %11, 2
br label %13
13: ; preds = %9, %2
%14 = tail call i32* @open_file(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @fscanf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%16 = call i64 @feof(i32* %14)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %31
18: ; preds = %13, %27
%19 = load i32, i32* %3
%20 = add nsw i32 %19, -1
store i32 %20, i32* %3
%21 = icmp slt i32 %19, 1
%22 = icmp sgt i32 %19, %1
%23 = or i1 %21, %22
br i1 %23, label %27, label %24
24: ; preds = %18
%25 = zext i32 %20 to i64
%26 = getelementptr inbounds i32, i32* %7, i64 %25
store i32 1, i32* %26
br label %27
27: ; preds = %24, %18
%28 = call i32 @fscanf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%29 = call i64 @feof(i32* %14)
%30 = icmp eq i64 %29, 0
br i1 %30, label %18, label %31
31: ; preds = %27, %13
%32 = call i32 @close(i32* %14)
ret i32* %7
}