#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 INT_MAX;
int INT_MIN;
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int range(const char *pFname) {
  FILE *fp = fopen(pFname, "r");
  if (fp == NULL)
    return -1;
  int min = INT_MAX;
  int max = INT_MIN;
  char buf[256];
  while ((fgets(buf, sizeof(buf), fp)) != NULL) {
    buf[sizeof(buf) - 1] = '\0';
    int value = atoi(buf);
    min = min > value ? value : min;
    max = max < value ? value : max;
  }
  fclose(fp);
  return max - min;
}


x86 assembly (clang, -O0):
<range>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117a <range+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1242 <range+0x102>
mov    0x2e67(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x100,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1230 <range+0xf0>
movb   $0x0,-0x21(%rbp)
lea    -0x120(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x124(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x124(%rbp),%eax
jle    11e7 <range+0xa7>
mov    -0x124(%rbp),%eax
mov    %eax,-0x128(%rbp)
jmp    11f0 <range+0xb0>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x128(%rbp)
mov    -0x128(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x124(%rbp),%eax
jge    1219 <range+0xd9>
mov    -0x124(%rbp),%eax
mov    %eax,-0x12c(%rbp)
jmp    1222 <range+0xe2>
mov    -0x20(%rbp),%eax
mov    %eax,-0x12c(%rbp)
mov    -0x12c(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    1192 <range+0x52>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<range>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
lea    0xeac(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11cb <range+0x8b>
mov    %rax,%r14
mov    0x2e80(%rip),%rax
mov    (%rax),%ebp
mov    0x2e6f(%rip),%rax
mov    (%rax),%ebx
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11bf <range+0x7f>
mov    %rsp,%r15
nopl   0x0(%rax,%rax,1)
movb   $0x0,0xff(%rsp)
mov    %r15,%rdi
call   1060 <atoi@plt>
cmp    %eax,%ebp
cmovg  %eax,%ebp
cmp    %eax,%ebx
cmovl  %eax,%ebx
mov    %r15,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    1190 <range+0x50>
sub    %ebp,%ebx
mov    %r14,%rdi
call   1030 <fclose@plt>
jmp    11d0 <range+0x90>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@INT_MAX = global i32 0
@INT_MIN = global i32 0
define i32 @range(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [256 x i8]
%8 = alloca i32
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %4
%11 = load i32*, i32** %4
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %14
13: ; preds = %1
store i32 -1, i32* %2
br label %50
14: ; preds = %1
%15 = load i32, i32* @INT_MAX
store i32 %15, i32* %5
%16 = load i32, i32* @INT_MIN
store i32 %16, i32* %6
br label %17
17: ; preds = %42, %14
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%19 = load i32*, i32** %4
%20 = call i32* @fgets(i8* %18, i32 256, i32* %19)
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %44
22: ; preds = %17
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 255
store i8 0, i8* %23
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %8
%26 = load i32, i32* %5
%27 = load i32, i32* %8
%28 = icmp sgt i32 %26, %27
br i1 %28, label %29, label %31
29: ; preds = %22
%30 = load i32, i32* %8
br label %33
31: ; preds = %22
%32 = load i32, i32* %5
br label %33
33: ; preds = %31, %29
%34 = phi i32 [ %30, %29 ], [ %32, %31 ]
store i32 %34, i32* %5
%35 = load i32, i32* %6
%36 = load i32, i32* %8
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = load i32, i32* %8
br label %42
40: ; preds = %33
%41 = load i32, i32* %6
br label %42
42: ; preds = %40, %38
%43 = phi i32 [ %39, %38 ], [ %41, %40 ]
store i32 %43, i32* %6
br label %17
44: ; preds = %17
%45 = load i32*, i32** %4
%46 = call i32 @fclose(i32* %45)
%47 = load i32, i32* %6
%48 = load i32, i32* %5
%49 = sub nsw i32 %47, %48
store i32 %49, i32* %2
br label %50
50: ; preds = %44, %13
%51 = load i32, i32* %2
ret i32 %51
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@INT_MAX = global i32 0
@INT_MIN = global i32 0
define i32 @range(i8* nocapture %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 %28, label %5
5: ; preds = %1
%6 = load i32, i32* @INT_MAX
%7 = load i32, i32* @INT_MIN
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%9 = call i32* @fgets(i8* %8, i32 256, i32* %3)
%10 = icmp eq i32* %9, null
br i1 %10, label %23, label %11
11: ; preds = %5
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 255
br label %13
13: ; preds = %11, %13
%14 = phi i32 [ %7, %11 ], [ %20, %13 ]
%15 = phi i32 [ %6, %11 ], [ %18, %13 ]
store i8 0, i8* %12
%16 = call i32 @atoi(i8* %8)
%17 = icmp sgt i32 %15, %16
%18 = select i1 %17, i32 %16, i32 %15
%19 = icmp slt i32 %14, %16
%20 = select i1 %19, i32 %16, i32 %14
%21 = call i32* @fgets(i8* %8, i32 256, i32* %3)
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %13
23: ; preds = %13, %5
%24 = phi i32 [ %6, %5 ], [ %18, %13 ]
%25 = phi i32 [ %7, %5 ], [ %20, %13 ]
%26 = call i32 @fclose(i32* %3)
%27 = sub nsw i32 %25, %24
br label %28
28: ; preds = %1, %23
%29 = phi i32 [ %27, %23 ], [ -1, %1 ]
ret i32 %29
}