#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*/ enter(int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ print(char *);
int /*<<< orphan*/ printf(char *);
int sscanf(char *, char *, int *);
int strlen(char *);
int main(int argc, char **argv) {
  char buf[500];
  if (argc != 3)
    goto fail;
  FILE *fp = fopen(argv[1], "r");
  if (fp == NULL)
    goto fail;
  int lo, hi;
  hi = -2;
  while (fgets(buf, sizeof(buf), fp) != NULL) {
    int n;
    buf[sizeof(buf) - 1] = 0;
    if (strlen(buf) == sizeof(buf) - 1)
      goto fail;
    if (sscanf(buf, "%x;", &n) != 1)
      goto fail;
    if (n > 0xFFFF)
      break;
    if (n == hi + 1)
      hi = n;
    else {
      if (hi != -2)
        enter(lo, hi);
      lo = hi = n;
    }
  }
  if (hi != -2)
    enter(lo, hi);
  fclose(fp);
  print(argv[2]);
  return 0;
fail:
  printf("Failure.\n");
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11a8 <main+0x28>
jmp    1302 <main+0x182>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe49(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x218(%rbp)
cmpq   $0x0,-0x218(%rbp)
jne    11d6 <main+0x56>
jmp    1302 <main+0x182>
movl   $0xfffffffe,-0x220(%rbp)
ff ff ff
lea    -0x210(%rbp),%rdi
mov    -0x218(%rbp),%rdx
mov    $0x1f4,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     12bf <main+0x13f>
movb   $0x0,-0x1d(%rbp)
lea    -0x210(%rbp),%rdi
call   1040 <strlen@plt>
cltq
cmp    $0x1f3,%rax
jne    1225 <main+0xa5>
jmp    1302 <main+0x182>
lea    -0x210(%rbp),%rdi
lea    0xdcf(%rip),%rsi
lea    -0x224(%rbp),%rdx
call   1090 <sscanf@plt>
cmp    $0x1,%eax
je     124d <main+0xcd>
jmp    1302 <main+0x182>
cmpl   $0xffff,-0x224(%rbp)
jle    1262 <main+0xe2>
jmp    12bf <main+0x13f>
mov    -0x224(%rbp),%eax
mov    -0x220(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jne    128a <main+0x10a>
mov    -0x224(%rbp),%eax
mov    %eax,-0x220(%rbp)
jmp    12ba <main+0x13a>
cmpl   $0xfffffffe,-0x220(%rbp)
je     12a8 <main+0x128>
mov    -0x21c(%rbp),%edi
mov    -0x220(%rbp),%esi
call   1060 <enter@plt>
mov    -0x224(%rbp),%eax
mov    %eax,-0x220(%rbp)
mov    %eax,-0x21c(%rbp)
jmp    11e0 <main+0x60>
cmpl   $0xfffffffe,-0x220(%rbp)
je     12dd <main+0x15d>
mov    -0x21c(%rbp),%edi
mov    -0x220(%rbp),%esi
call   1060 <enter@plt>
mov    -0x218(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <print@plt>
movl   $0x0,-0x4(%rbp)
jmp    1315 <main+0x195>
lea    0xcfd(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
cmp    $0x3,%edi
jne    1270 <main+0xf0>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe58(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1270 <main+0xf0>
mov    %rax,%r15
lea    0x10(%rsp),%rdi
mov    $0x1f4,%esi
mov    %rax,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     129f <main+0x11f>
mov    %rbx,0x8(%rsp)
mov    $0xfffffffe,%ebp
lea    0x10(%rsp),%rbx
jmp    120e <main+0x8e>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12d,%r14d
mov    %rbx,%rdi
mov    $0x1f4,%esi
mov    %r15,%rdx
call   1080 <fgets@plt>
mov    %r13d,%ebp
mov    %r14d,%r12d
test   %rax,%rax
je     1289 <main+0x109>
movb   $0x0,0x203(%rsp)
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x1f3,%eax
je     1270 <main+0xf0>
mov    %rbx,%rdi
lea    0xdd3(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1090 <sscanf@plt>
cmp    $0x1,%eax
jne    1270 <main+0xf0>
mov    0x4(%rsp),%r13d
cmp    $0x10000,%r13d
jge    1283 <main+0x103>
lea    0x1(%rbp),%eax
cmp    %eax,%r13d
je     11f0 <main+0x70>
mov    %r13d,%r14d
cmp    $0xfffffffe,%ebp
je     11f3 <main+0x73>
mov    %r12d,%edi
mov    %ebp,%esi
call   1060 <enter@plt>
mov    0x4(%rsp),%r14d
mov    %r14d,%r13d
jmp    11f3 <main+0x73>
lea    0xd8f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    12b2 <main+0x132>
mov    %r12d,%r14d
mov    %ebp,%r13d
cmp    $0xfffffffe,%r13d
mov    0x8(%rsp),%rbx
je     129f <main+0x11f>
mov    %r14d,%edi
mov    %r13d,%esi
call   1060 <enter@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    0x10(%rbx),%rdi
call   1070 <print@plt>
xor    %eax,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [4 x i8] c"%x;\00"
@.str.2 = [10 x i8] c"Failure.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [500 x i8]
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %14
13: ; preds = %2
br label %75
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %7
%19 = load i32*, i32** %7
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %22
21: ; preds = %14
br label %75
22: ; preds = %14
store i32 -2, i32* %9
br label %23
23: ; preds = %60, %22
%24 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%25 = load i32*, i32** %7
%26 = call i32* @fgets(i8* %24, i32 500, i32* %25)
%27 = icmp ne i32* %26, null
br i1 %27, label %28, label %61
28: ; preds = %23
%29 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 499
store i8 0, i8* %29
%30 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%31 = call i32 @strlen(i8* %30)
%32 = sext i32 %31 to i64
%33 = icmp eq i64 %32, 499
br i1 %33, label %34, label %35
34: ; preds = %28
br label %75
35: ; preds = %28
%36 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%37 = call i32 @sscanf(i8* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %10)
%38 = icmp ne i32 %37, 1
br i1 %38, label %39, label %40
39: ; preds = %35
br label %75
40: ; preds = %35
%41 = load i32, i32* %10
%42 = icmp sgt i32 %41, 65535
br i1 %42, label %43, label %44
43: ; preds = %40
br label %61
44: ; preds = %40
%45 = load i32, i32* %10
%46 = load i32, i32* %9
%47 = add nsw i32 %46, 1
%48 = icmp eq i32 %45, %47
br i1 %48, label %49, label %51
49: ; preds = %44
%50 = load i32, i32* %10
store i32 %50, i32* %9
br label %60
51: ; preds = %44
%52 = load i32, i32* %9
%53 = icmp ne i32 %52, -2
br i1 %53, label %54, label %58
54: ; preds = %51
%55 = load i32, i32* %8
%56 = load i32, i32* %9
%57 = call i32 @enter(i32 %55, i32 %56)
br label %58
58: ; preds = %54, %51
%59 = load i32, i32* %10
store i32 %59, i32* %9
store i32 %59, i32* %8
br label %60
60: ; preds = %58, %49
br label %23
61: ; preds = %43, %23
%62 = load i32, i32* %9
%63 = icmp ne i32 %62, -2
br i1 %63, label %64, label %68
64: ; preds = %61
%65 = load i32, i32* %8
%66 = load i32, i32* %9
%67 = call i32 @enter(i32 %65, i32 %66)
br label %68
68: ; preds = %64, %61
%69 = load i32*, i32** %7
%70 = call i32 @fclose(i32* %69)
%71 = load i8**, i8*** %5
%72 = getelementptr inbounds i8*, i8** %71, i64 2
%73 = load i8*, i8** %72
%74 = call i32 @print(i8* %73)
store i32 0, i32* %3
br label %77
75: ; preds = %39, %34, %21, %13
%76 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %77
77: ; preds = %75, %68
%78 = load i32, i32* %3
ret i32 %78
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [4 x i8] c"%x;\00"
@str = [9 x i8] c"Failure.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [500 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%6 = icmp eq i32 %0, 3
br i1 %6, label %7, label %55
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %55, label %12
12: ; preds = %7
%13 = call i32* @fgets(i8* %5, i32 500, i32* %10)
%14 = icmp eq i32* %13, null
br i1 %14, label %50, label %15
15: ; preds = %12
%16 = bitcast i32* %4 to i8*
%17 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 499
br label %18
18: ; preds = %15, %39
%19 = phi i32 [ -2, %15 ], [ %41, %39 ]
%20 = phi i32 [ undef, %15 ], [ %40, %39 ]
store i8 0, i8* %17
%21 = call i32 @strlen(i8* %5)
%22 = icmp eq i32 %21, 499
br i1 %22, label %38, label %23
23: ; preds = %18
%24 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%25 = icmp eq i32 %24, 1
br i1 %25, label %26, label %38
26: ; preds = %23
%27 = load i32, i32* %4
%28 = icmp sgt i32 %27, 65535
br i1 %28, label %29, label %30
29: ; preds = %26
br label %44
30: ; preds = %26
%31 = add nsw i32 %19, 1
%32 = icmp eq i32 %27, %31
br i1 %32, label %39, label %33
33: ; preds = %30
%34 = icmp eq i32 %19, -2
br i1 %34, label %39, label %35
35: ; preds = %33
%36 = call i32 @enter(i32 %20, i32 %19)
%37 = load i32, i32* %4
br label %39
38: ; preds = %18, %23
br label %55
39: ; preds = %33, %35, %30
%40 = phi i32 [ %20, %30 ], [ %37, %35 ], [ %27, %33 ]
%41 = phi i32 [ %27, %30 ], [ %37, %35 ], [ %27, %33 ]
%42 = call i32* @fgets(i8* %5, i32 500, i32* %10)
%43 = icmp eq i32* %42, null
br i1 %43, label %44, label %18
44: ; preds = %39, %29
%45 = phi i32 [ %20, %29 ], [ %40, %39 ]
%46 = phi i32 [ %19, %29 ], [ %41, %39 ]
%47 = icmp eq i32 %46, -2
br i1 %47, label %50, label %48
48: ; preds = %44
%49 = call i32 @enter(i32 %45, i32 %46)
br label %50
50: ; preds = %12, %48, %44
%51 = call i32 @fclose(i32* %10)
%52 = getelementptr inbounds i8*, i8** %1, i64 2
%53 = load i8*, i8** %52
%54 = call i32 @print(i8* %53)
br label %57
55: ; preds = %38, %7, %2
%56 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %57
57: ; preds = %55, %50
%58 = phi i32 [ 1, %55 ], [ 0, %50 ]
ret i32 %58
}