#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*/ linebuf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ error1(char *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int read_id_list(char id[][10], char fname[]) {
  FILE *fp_list;
  char linebuf[200];
  int n = 0;
  if ((fp_list = fopen(fname, "rb")) == NULL)
    error1("Can't open idlist.txt");
  n = 0;
  while (fgets(linebuf, sizeof(linebuf), fp_list) != NULL) {
    if (linebuf[0] == '#')
      continue;
    else if (linebuf[0] == '\n')
      continue;
    else if (strncmp(linebuf, "$END", strlen("$END")) == 0) {
      break;
    }
    if (linebuf[strlen(linebuf) - 1] == '\n')
      linebuf[strlen(linebuf) - 1] = '\0';
    strcpy(id[n], linebuf);
    n++;
    if (n >= 121)
      error1("Number of ID is too large");
  }
  return n;
}


x86 assembly (clang, -O0):
<read_id_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0xe4(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11a7 <read_id_list+0x47>
lea    0xe61(%rip),%rdi
call   1080 <error1@plt>
movl   $0x0,-0xe4(%rbp)
lea    -0xe0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0xc8,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     12c8 <read_id_list+0x168>
movsbl -0xe0(%rbp),%eax
cmp    $0x23,%eax
jne    11e5 <read_id_list+0x85>
jmp    11b1 <read_id_list+0x51>
movsbl -0xe0(%rbp),%eax
cmp    $0xa,%eax
jne    11fa <read_id_list+0x9a>
jmp    11b1 <read_id_list+0x51>
lea    -0xe0(%rbp),%rax
mov    %rax,-0xf0(%rbp)
lea    0xe0a(%rip),%rdi
call   1050 <strlen@plt>
mov    -0xf0(%rbp),%rdi
mov    %eax,%edx
lea    0xdf5(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1238 <read_id_list+0xd8>
jmp    12c8 <read_id_list+0x168>
jmp    123d <read_id_list+0xdd>
jmp    1242 <read_id_list+0xe2>
lea    -0xe0(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0xe0(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    127d <read_id_list+0x11d>
lea    -0xe0(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0xe0(%rbp,%rax,1)
mov    -0x8(%rbp),%rdi
movslq -0xe4(%rbp),%rax
imul   $0xa,%rax,%rax
add    %rax,%rdi
lea    -0xe0(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0xe4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xe4(%rbp)
cmpl   $0x79,-0xe4(%rbp)
jl     12c3 <read_id_list+0x163>
lea    0xd60(%rip),%rdi
call   1080 <error1@plt>
jmp    11b1 <read_id_list+0x51>
mov    -0xe4(%rbp),%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_id_list>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc8,%rsp
mov    %rsi,%rax
mov    %rdi,%r14
lea    0xe82(%rip),%rsi
mov    %rax,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    119a <read_id_list+0x3a>
lea    0xe6e(%rip),%rdi
call   1080 <error1@plt>
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0xc8,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
xor    %r15d,%r15d
test   %rax,%rax
je     1250 <read_id_list+0xf0>
lea    0xe59(%rip),%r13
lea    0xe57(%rip),%rbp
jmp    11e5 <read_id_list+0x85>
add    $0x1,%r15
nopl   (%rax)
mov    %r12,%rdi
mov    $0xc8,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1250 <read_id_list+0xf0>
movzbl (%rsp),%eax
cmp    $0x23,%al
je     11d0 <read_id_list+0x70>
cmp    $0xa,%al
je     11d0 <read_id_list+0x70>
mov    %r13,%rdi
call   1050 <strlen@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1250 <read_id_list+0xf0>
mov    %r12,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%r12,1)
jne    122d <read_id_list+0xcd>
mov    %r12,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r12,1)
lea    (%r15,%r15,4),%rax
lea    (%r14,%rax,2),%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
cmp    $0x78,%r15
jb     11c9 <read_id_list+0x69>
mov    %rbp,%rdi
call   1080 <error1@plt>
jmp    11c9 <read_id_list+0x69>
mov    %r15d,%eax
add    $0xc8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [22 x i8] c"Can't open idlist.txt\00"
@.str.2 = [5 x i8] c"$END\00"
@.str.3 = [26 x i8] c"Number of ID is too large\00"
define i32 @read_id_list([10 x i8]* %0, i8* %1) {
%3 = alloca [10 x i8]*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [200 x i8]
%7 = alloca i32
store [10 x i8]* %0, [10 x i8]** %3
store i8* %1, i8** %4
store i32 0, i32* %7
%8 = load i8*, i8** %4
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %5
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @error1(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
store i32 0, i32* %7
br label %14
14: ; preds = %68, %30, %24, %13
%15 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%16 = load i32*, i32** %5
%17 = call i32* @fgets(i8* %15, i32 200, i32* %16)
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %69
19: ; preds = %14
%20 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 35
br i1 %23, label %24, label %25
24: ; preds = %19
br label %14
25: ; preds = %19
%26 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 10
br i1 %29, label %30, label %31
30: ; preds = %25
br label %14
31: ; preds = %25
%32 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%33 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%34 = call i64 @strncmp(i8* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %31
br label %69
37: ; preds = %31
br label %38
38: ; preds = %37
br label %39
39: ; preds = %38
%40 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%41 = call i32 @strlen(i8* %40)
%42 = sub nsw i32 %41, 1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 10
br i1 %47, label %48, label %54
48: ; preds = %39
%49 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%50 = call i32 @strlen(i8* %49)
%51 = sub nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 %52
store i8 0, i8* %53
br label %54
54: ; preds = %48, %39
%55 = load [10 x i8]*, [10 x i8]** %3
%56 = load i32, i32* %7
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [10 x i8], [10 x i8]* %55, i64 %57
%59 = getelementptr inbounds [10 x i8], [10 x i8]* %58, i64 0, i64 0
%60 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%61 = call i32 @strcpy(i8* %59, i8* %60)
%62 = load i32, i32* %7
%63 = add nsw i32 %62, 1
store i32 %63, i32* %7
%64 = load i32, i32* %7
%65 = icmp sge i32 %64, 121
br i1 %65, label %66, label %68
66: ; preds = %54
%67 = call i32 @error1(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %68
68: ; preds = %66, %54
br label %14
69: ; preds = %36, %14
%70 = load i32, i32* %7
ret i32 %70
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [22 x i8] c"Can't open idlist.txt\00"
@.str.2 = [5 x i8] c"$END\00"
@.str.3 = [26 x i8] c"Number of ID is too large\00"
define i32 @read_id_list([10 x i8]* %0, i8* nocapture %1) {
%3 = alloca [200 x i8]
%4 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @error1(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %7, %2
%10 = call i32* @fgets(i8* %4, i32 200, i32* %5)
%11 = icmp eq i32* %10, null
br i1 %11, label %50, label %12
12: ; preds = %9, %42
%13 = phi i64 [ %38, %42 ], [ 0, %9 ]
br label %14
14: ; preds = %12, %16
%15 = load i8, i8* %4
switch i8 %15, label %19 [
i8 35, label %16
i8 10, label %16
]
16: ; preds = %14, %14
%17 = call i32* @fgets(i8* %4, i32 200, i32* %5)
%18 = icmp eq i32* %17, null
br i1 %18, label %45, label %14
19: ; preds = %14
%20 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%21 = call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %47, label %23
23: ; preds = %19
%24 = call i32 @strlen(i8* %4)
%25 = add nsw i32 %24, -1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 10
br i1 %29, label %30, label %35
30: ; preds = %23
%31 = call i32 @strlen(i8* %4)
%32 = add nsw i32 %31, -1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 %33
store i8 0, i8* %34
br label %35
35: ; preds = %30, %23
%36 = getelementptr inbounds [10 x i8], [10 x i8]* %0, i64 %13, i64 0
%37 = call i32 @strcpy(i8* %36, i8* %4)
%38 = add nuw i64 %13, 1
%39 = icmp ugt i64 %13, 119
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = call i32 @error1(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %42
42: ; preds = %40, %35
%43 = call i32* @fgets(i8* %4, i32 200, i32* %5)
%44 = icmp eq i32* %43, null
br i1 %44, label %47, label %12
45: ; preds = %16
%46 = trunc i64 %13 to i32
br label %50
47: ; preds = %42, %19
%48 = phi i64 [ %13, %19 ], [ %38, %42 ]
%49 = trunc i64 %48 to i32
br label %50
50: ; preds = %47, %45, %9
%51 = phi i32 [ 0, %9 ], [ %46, %45 ], [ %49, %47 ]
ret i32 %51
}