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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int sscanf(char *, char *, char *);
int /*<<< orphan*/ strcasecmp(char const *, char *);
scalar_t__ strcasestr(char const *, char *);
bool is_bad_id(const char *s) {
  FILE *fp;
  char buf[80], buf2[80];
  fp = fopen("/home/bbs"
             "/etc/badname0",
             "r");
  if (fp) {
    while (fgets(buf, sizeof(buf), fp) != NULL) {
      if (sscanf(buf, "%s", buf2) != 1)
        continue;
      if (!strcasecmp(s, buf2)) {
        fclose(fp);
        return true;
      }
    }
    fclose(fp);
  }
  fp = fopen("/home/bbs"
             "/etc/badname",
             "r");
  if (fp == 0)
    return false;
  while (fgets(buf, sizeof(buf), fp)) {
    if (sscanf(buf, "%s", buf2) != 1)
      continue;
    if (strcasestr(s, buf2)) {
      fclose(fp);
      return true;
    }
  }
  fclose(fp);
  return false;
}


x86 assembly (clang, -O0):
<is_bad_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe9a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1213 <is_bad_id+0xb3>
jmp    1196 <is_bad_id+0x36>
lea    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x50,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     120a <is_bad_id+0xaa>
lea    -0x70(%rbp),%rdi
lea    -0xc0(%rbp),%rdx
lea    0xe55(%rip),%rsi
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     11d7 <is_bad_id+0x77>
jmp    1196 <is_bad_id+0x36>
mov    -0x10(%rbp),%rdi
lea    -0xc0(%rbp),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    1205 <is_bad_id+0xa5>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    12cb <is_bad_id+0x16b>
jmp    1196 <is_bad_id+0x36>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xe02(%rip),%rdi
lea    0xdf6(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1241 <is_bad_id+0xe1>
movl   $0x0,-0x4(%rbp)
jmp    12cb <is_bad_id+0x16b>
jmp    1246 <is_bad_id+0xe6>
lea    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x50,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     12bb <is_bad_id+0x15b>
lea    -0x70(%rbp),%rdi
lea    -0xc0(%rbp),%rdx
lea    0xda5(%rip),%rsi
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     1287 <is_bad_id+0x127>
jmp    1246 <is_bad_id+0xe6>
mov    -0x10(%rbp),%rdi
lea    -0xc0(%rbp),%rsi
call   1080 <strcasestr@plt>
cmp    $0x0,%rax
je     12b6 <is_bad_id+0x156>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    12cb <is_bad_id+0x16b>
jmp    1246 <is_bad_id+0xe6>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_bad_id>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %rdi,%r14
lea    0xe85(%rip),%rdi
lea    0xe95(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1204 <is_bad_id+0xa4>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x50,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11fc <is_bad_id+0x9c>
lea    0xe6e(%rip),%r15
mov    %rsp,%rbp
lea    0x50(%rsp),%r12
jmp    11d5 <is_bad_id+0x75>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
mov    $0x50,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11fc <is_bad_id+0x9c>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    11c0 <is_bad_id+0x60>
mov    %r14,%rdi
mov    %r12,%rsi
call   1030 <strcasecmp@plt>
test   %eax,%eax
jne    11c0 <is_bad_id+0x60>
jmp    1288 <is_bad_id+0x128>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe11(%rip),%rdi
lea    0xe05(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1298 <is_bad_id+0x138>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x50,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
xor    %r15d,%r15d
test   %rax,%rax
je     128e <is_bad_id+0x12e>
lea    0xddb(%rip),%r12
mov    %rsp,%rbp
lea    0x50(%rsp),%r13
jmp    1265 <is_bad_id+0x105>
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x50,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     128e <is_bad_id+0x12e>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1250 <is_bad_id+0xf0>
mov    %r14,%rdi
mov    %r13,%rsi
call   1080 <strcasestr@plt>
test   %rax,%rax
je     1250 <is_bad_id+0xf0>
mov    $0x1,%r15d
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    129b <is_bad_id+0x13b>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"/home/bbs/etc/badname0\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [22 x i8] c"/home/bbs/etc/badname\00"
define i32 @is_bad_id(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [80 x i8]
%6 = alloca [80 x i8]
store i8* %0, i8** %3
%7 = call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %34
10: ; preds = %1
br label %11
11: ; preds = %30, %21, %10
%12 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%13 = load i32*, i32** %4
%14 = call i32* @fgets(i8* %12, i32 80, i32* %13)
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %31
16: ; preds = %11
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%18 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%19 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = icmp ne i32 %19, 1
br i1 %20, label %21, label %22
21: ; preds = %16
br label %11
22: ; preds = %16
%23 = load i8*, i8** %3
%24 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%25 = call i32 @strcasecmp(i8* %23, i8* %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %22
%28 = load i32*, i32** %4
%29 = call i32 @fclose(i32* %28)
store i32 1, i32* %2
br label %63
30: ; preds = %22
br label %11
31: ; preds = %11
%32 = load i32*, i32** %4
%33 = call i32 @fclose(i32* %32)
br label %34
34: ; preds = %31, %1
%35 = call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %35, i32** %4
%36 = load i32*, i32** %4
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %39
38: ; preds = %34
store i32 0, i32* %2
br label %63
39: ; preds = %34
br label %40
40: ; preds = %59, %50, %39
%41 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%42 = load i32*, i32** %4
%43 = call i32* @fgets(i8* %41, i32 80, i32* %42)
%44 = icmp ne i32* %43, null
br i1 %44, label %45, label %60
45: ; preds = %40
%46 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%47 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%48 = call i32 @sscanf(i8* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %47)
%49 = icmp ne i32 %48, 1
br i1 %49, label %50, label %51
50: ; preds = %45
br label %40
51: ; preds = %45
%52 = load i8*, i8** %3
%53 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%54 = call i64 @strcasestr(i8* %52, i8* %53)
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %51
%57 = load i32*, i32** %4
%58 = call i32 @fclose(i32* %57)
store i32 1, i32* %2
br label %63
59: ; preds = %51
br label %40
60: ; preds = %40
%61 = load i32*, i32** %4
%62 = call i32 @fclose(i32* %61)
store i32 0, i32* %2
br label %63
63: ; preds = %60, %56, %38, %27
%64 = load i32, i32* %2
ret i32 %64
}

LLVM IR (-O2):
@.str = [23 x i8] c"/home/bbs/etc/badname0\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [22 x i8] c"/home/bbs/etc/badname\00"
define i32 @is_bad_id(i8* %0) {
%2 = alloca [80 x i8]
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %22, label %8
8: ; preds = %1
%9 = call i32* @fgets(i8* %4, i32 80, i32* %6)
%10 = icmp eq i32* %9, null
br i1 %10, label %20, label %11
11: ; preds = %8, %14
%12 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%13 = icmp eq i32 %12, 1
br i1 %13, label %17, label %14
14: ; preds = %11, %17
%15 = call i32* @fgets(i8* %4, i32 80, i32* %6)
%16 = icmp eq i32* %15, null
br i1 %16, label %20, label %11
17: ; preds = %11
%18 = call i32 @strcasecmp(i8* %0, i8* %5)
%19 = icmp eq i32 %18, 0
br i1 %19, label %37, label %14
20: ; preds = %14, %8
%21 = call i32 @fclose(i32* %6)
br label %22
22: ; preds = %20, %1
%23 = call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %41, label %25
25: ; preds = %22
%26 = call i32* @fgets(i8* %4, i32 80, i32* %23)
%27 = icmp eq i32* %26, null
br i1 %27, label %37, label %28
28: ; preds = %25, %31
%29 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%30 = icmp eq i32 %29, 1
br i1 %30, label %34, label %31
31: ; preds = %28, %34
%32 = call i32* @fgets(i8* %4, i32 80, i32* %23)
%33 = icmp eq i32* %32, null
br i1 %33, label %37, label %28
34: ; preds = %28
%35 = call i64 @strcasestr(i8* %0, i8* %5)
%36 = icmp eq i64 %35, 0
br i1 %36, label %31, label %37
37: ; preds = %17, %31, %34, %25
%38 = phi i32* [ %23, %25 ], [ %23, %34 ], [ %23, %31 ], [ %6, %17 ]
%39 = phi i32 [ 0, %25 ], [ 0, %31 ], [ 1, %34 ], [ 1, %17 ]
%40 = call i32 @fclose(i32* %38)
br label %41
41: ; preds = %37, %22
%42 = phi i32 [ 0, %22 ], [ %39, %37 ]
ret i32 %42
}