#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 */
scalar_t__ append_range(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
int append_ranges_in_file(const char *filename) {
  FILE *fp = fopen(filename, "r");
  if (!fp) {
    fprintf(stderr, "Error: Can not open range file '%s'\n", filename);
    return 1;
  }
  while (!feof(fp)) {
    char buf[256];
    if (!fgets(buf, sizeof(buf), fp))
      break;
    if (append_range(buf)) {
      fclose(fp);
      return 1;
    }
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<append_ranges_in_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe86(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b3 <append_ranges_in_file+0x53>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe60(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1239 <append_ranges_in_file+0xd9>
jmp    11b8 <append_ranges_in_file+0x58>
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11d6 <append_ranges_in_file+0x76>
jmp    1229 <append_ranges_in_file+0xc9>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x100,%esi
call   1040 <fgets@plt>
cmp    $0x0,%eax
jne    11f9 <append_ranges_in_file+0x99>
jmp    1229 <append_ranges_in_file+0xc9>
lea    -0x120(%rbp),%rdi
call   1080 <append_range@plt>
cmp    $0x0,%rax
je     1224 <append_ranges_in_file+0xc4>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1239 <append_ranges_in_file+0xd9>
jmp    11b8 <append_ranges_in_file+0x58>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_ranges_in_file>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%r14
lea    0xe8c(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1199 <append_ranges_in_file+0x39>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     11c1 <append_ranges_in_file+0x61>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    11b6 <append_ranges_in_file+0x56>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    0xe59(%rip),%rsi
mov    %r14,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %eax,%eax
je     118d <append_ranges_in_file+0x2d>
mov    %r14,%rdi
call   1080 <append_range@plt>
test   %rax,%rax
jne    11ff <append_ranges_in_file+0x9f>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     11d0 <append_ranges_in_file+0x70>
jmp    118d <append_ranges_in_file+0x2d>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11b1 <append_ranges_in_file+0x51>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [37 x i8] c"Error: Can not open range file '%s'\0A\00"
define i32 @append_ranges_in_file(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [256 x i8]
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = icmp ne i32* %8, null
br i1 %9, label %14, label %10
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %3
%13 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %12)
store i32 1, i32* %2
br label %37
14: ; preds = %1
br label %15
15: ; preds = %33, %14
%16 = load i32*, i32** %4
%17 = call i32 @feof(i32* %16)
%18 = icmp ne i32 %17, 0
%19 = xor i1 %18, true
br i1 %19, label %20, label %34
20: ; preds = %15
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%22 = load i32*, i32** %4
%23 = call i32 @fgets(i8* %21, i32 256, i32* %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %20
br label %34
26: ; preds = %20
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%28 = call i64 @append_range(i8* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i32*, i32** %4
%32 = call i32 @fclose(i32* %31)
store i32 1, i32* %2
br label %37
33: ; preds = %26
br label %15
34: ; preds = %25, %15
%35 = load i32*, i32** %4
%36 = call i32 @fclose(i32* %35)
store i32 0, i32* %2
br label %37
37: ; preds = %34, %30, %10
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [37 x i8] c"Error: Can not open range file '%s'\0A\00"
define i32 @append_ranges_in_file(i8* %0) {
%2 = alloca [256 x i8]
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %10, label %5
5: ; preds = %1
%6 = call i32 @feof(i32* %3)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %25
8: ; preds = %5
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
br label %13
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %27
13: ; preds = %8, %22
%14 = call i32 @fgets(i8* %9, i32 256, i32* %3)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %13
br label %25
17: ; preds = %13
%18 = call i64 @append_range(i8* %9)
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = call i32 @fclose(i32* %3)
br label %27
22: ; preds = %17
%23 = call i32 @feof(i32* %3)
%24 = icmp eq i32 %23, 0
br i1 %24, label %13, label %25
25: ; preds = %22, %5, %16
%26 = call i32 @fclose(i32* %3)
br label %27
27: ; preds = %20, %25, %10
%28 = phi i32 [ 0, %25 ], [ 1, %10 ], [ 1, %20 ]
ret i32 %28
}