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

/* Variables and functions */
int /*<<< orphan*/ clean(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ log_event(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ regions_add(char *, int /*<<< orphan*/);
int /*<<< orphan*/ regions_clear();
size_t strlen(char *);
void regions_load(const char *filename) {
  char line[1024];
  size_t len;
  FILE *in;
  if (!(in = fopen(filename, "r")))
    return;
  regions_clear();
  while (fgets(line, sizeof(line), in)) {
    len = strlen(line);
    if (line[len - 1] == '\n') {
      if (line[len - 2] == '\r')
        line[len - 2] = '\0';
      else
        line[len - 1] = '\0';
    }
    if (line[0] == '\0')
      continue;
    clean(line);
    if (!regions_add(line, 0))
      log_event(0, "WARNING: Duplicate region found: %s", line);
  }
  fclose(in);
}


x86 assembly (clang, -O0):
<regions_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe66(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x420(%rbp)
cmp    $0x0,%rax
jne    11b5 <regions_load+0x35>
jmp    12b7 <regions_load+0x137>
mov    $0x0,%al
call   1040 <regions_clear@plt>
lea    -0x410(%rbp),%rdi
mov    -0x420(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     12ab <regions_load+0x12b>
lea    -0x410(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x418(%rbp)
mov    -0x418(%rbp),%rax
sub    $0x1,%rax
movsbl -0x410(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    1259 <regions_load+0xd9>
mov    -0x418(%rbp),%rax
sub    $0x2,%rax
movsbl -0x410(%rbp,%rax,1),%eax
ff
cmp    $0xd,%eax
jne    1241 <regions_load+0xc1>
mov    -0x418(%rbp),%rax
sub    $0x2,%rax
movb   $0x0,-0x410(%rbp,%rax,1)
jmp    1254 <regions_load+0xd4>
mov    -0x418(%rbp),%rax
sub    $0x1,%rax
movb   $0x0,-0x410(%rbp,%rax,1)
jmp    1259 <regions_load+0xd9>
movsbl -0x410(%rbp),%eax
cmp    $0x0,%eax
jne    126e <regions_load+0xee>
jmp    11bc <regions_load+0x3c>
lea    -0x410(%rbp),%rdi
call   1080 <clean@plt>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
call   1070 <regions_add@plt>
cmp    $0x0,%eax
jne    12a6 <regions_load+0x126>
lea    -0x410(%rbp),%rdx
xor    %edi,%edi
lea    0xd61(%rip),%rsi
call   1090 <log_event@plt>
jmp    11bc <regions_load+0x3c>
mov    -0x420(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<regions_load>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
lea    0xe6d(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1240 <regions_load+0xc0>
mov    %rax,%r14
xor    %eax,%eax
call   1040 <regions_clear@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1238 <regions_load+0xb8>
lea    0xe38(%rip),%r15
jmp    11e5 <regions_load+0x65>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1238 <regions_load+0xb8>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    120d <regions_load+0x8d>
lea    (%rax,%rbx,1),%rcx
add    $0xffffffffffffffff,%rcx
cmpb   $0xd,-0x2(%rax,%rbx,1)
lea    -0x2(%rax,%rbx,1),%rax
cmovne %rcx,%rax
movb   $0x0,(%rax)
cmpb   $0x0,(%rsp)
je     11d0 <regions_load+0x50>
mov    %rbx,%rdi
call   1080 <clean@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <regions_add@plt>
test   %eax,%eax
jne    11d0 <regions_load+0x50>
xor    %edi,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1090 <log_event@plt>
jmp    11d0 <regions_load+0x50>
mov    %r14,%rdi
call   1030 <fclose@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [36 x i8] c"WARNING: Duplicate region found: %s\00"
define void @regions_load(i8* %0) {
%2 = alloca i8*
%3 = alloca [1024 x i8]
%4 = alloca i64
%5 = alloca i32*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %5
%8 = icmp ne i32* %7, null
br i1 %8, label %10, label %9
9: ; preds = %1
br label %61
10: ; preds = %1
%11 = call i32 (...) @regions_clear()
br label %12
12: ; preds = %57, %47, %10
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%14 = load i32*, i32** %5
%15 = call i64 @fgets(i8* %13, i32 1024, i32* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %58
17: ; preds = %12
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%19 = call i64 @strlen(i8* %18)
store i64 %19, i64* %4
%20 = load i64, i64* %4
%21 = sub i64 %20, 1
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 10
br i1 %25, label %26, label %42
26: ; preds = %17
%27 = load i64, i64* %4
%28 = sub i64 %27, 2
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 13
br i1 %32, label %33, label %37
33: ; preds = %26
%34 = load i64, i64* %4
%35 = sub i64 %34, 2
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %35
store i8 0, i8* %36
br label %41
37: ; preds = %26
%38 = load i64, i64* %4
%39 = sub i64 %38, 1
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %39
store i8 0, i8* %40
br label %41
41: ; preds = %37, %33
br label %42
42: ; preds = %41, %17
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %42
br label %12
48: ; preds = %42
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%50 = call i32 @clean(i8* %49)
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%52 = call i32 @regions_add(i8* %51, i32 0)
%53 = icmp ne i32 %52, 0
br i1 %53, label %57, label %54
54: ; preds = %48
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%56 = call i32 @log_event(i32 0, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %55)
br label %57
57: ; preds = %54, %48
br label %12
58: ; preds = %12
%59 = load i32*, i32** %5
%60 = call i32 @fclose(i32* %59)
br label %61
61: ; preds = %58, %9
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [36 x i8] c"WARNING: Duplicate region found: %s\00"
define void @regions_load(i8* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %36, label %6
6: ; preds = %1
%7 = tail call i32 (...) @regions_clear()
%8 = call i64 @fgets(i8* %3, i32 1024, i32* %4)
%9 = icmp eq i64 %8, 0
br i1 %9, label %34, label %10
10: ; preds = %6, %31
%11 = call i64 @strlen(i8* %3)
%12 = add i64 %11, -1
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 10
br i1 %15, label %16, label %22
16: ; preds = %10
%17 = add i64 %11, -2
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 13
%21 = select i1 %20, i8* %18, i8* %13
store i8 0, i8* %21
br label %22
22: ; preds = %16, %10
%23 = load i8, i8* %3
%24 = icmp eq i8 %23, 0
br i1 %24, label %31, label %25
25: ; preds = %22
%26 = call i32 @clean(i8* %3)
%27 = call i32 @regions_add(i8* %3, i32 0)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = call i32 @log_event(i32 0, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %31
31: ; preds = %25, %29, %22
%32 = call i64 @fgets(i8* %3, i32 1024, i32* %4)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %10
34: ; preds = %31, %6
%35 = call i32 @fclose(i32* %4)
br label %36
36: ; preds = %1, %34
ret void
}