#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *open_file(char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, int *, int *);
int read_windows(char *filename, int *windows) {
  FILE *infile;
  char buf[20000];
  int start, end, count;
  infile = open_file(filename, "r");
  count = 0;
  while ((fgets(buf, 20000, infile) != NULL) && buf[0] != '\0') {
    sscanf(buf, "%d %d", &start, &end);
    windows[count] = end - start + 1;
    count++;
  }
  return count;
}


x86 assembly (clang, -O0):
<read_windows>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4e50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb2(%rip),%rsi
call   1030 <open_file@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x4e4c(%rbp)
lea    -0x4e40(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x4e20,%esi
call   1040 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x4e4d(%rbp)
je     119e <read_windows+0x6e>
movsbl -0x4e40(%rbp),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x4e4d(%rbp)
mov    -0x4e4d(%rbp),%al
test   $0x1,%al
jne    11b1 <read_windows+0x81>
jmp    1203 <read_windows+0xd3>
lea    -0x4e40(%rbp),%rdi
lea    0xe43(%rip),%rsi
lea    -0x4e44(%rbp),%rdx
lea    -0x4e48(%rbp),%rcx
call   1050 <sscanf@plt>
mov    -0x4e48(%rbp),%edx
sub    -0x4e44(%rbp),%edx
add    $0x1,%edx
mov    -0x10(%rbp),%rax
movslq -0x4e4c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x4e4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4e4c(%rbp)
jmp    1161 <read_windows+0x31>
mov    -0x4e4c(%rbp),%eax
add    $0x4e50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_windows>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4e38,%rsp
mov    %rsi,%r14
lea    0xeb5(%rip),%rsi
call   1030 <open_file@plt>
mov    %rax,%r15
lea    0x10(%rsp),%rdi
mov    $0x4e20,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     11d4 <read_windows+0xa4>
cmpb   $0x0,0x10(%rsp)
je     11d4 <read_windows+0xa4>
xor    %ebx,%ebx
lea    0x10(%rsp),%r13
lea    0xc(%rsp),%rbp
lea    0x8(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13,%rdi
lea    0xe68(%rip),%rsi
mov    %rbp,%rdx
mov    %r12,%rcx
call   1050 <sscanf@plt>
mov    0x8(%rsp),%eax
sub    0xc(%rsp),%eax
add    $0x1,%eax
mov    %eax,(%r14,%rbx,4)
add    $0x1,%rbx
mov    %r13,%rdi
mov    $0x4e20,%esi
mov    %r15,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11d4 <read_windows+0xa4>
cmpb   $0x0,0x10(%rsp)
jne    1190 <read_windows+0x60>
mov    %ebx,%eax
add    $0x4e38,%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 = [6 x i8] c"%d %d\00"
define i32 @read_windows(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [20000 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
%10 = load i8*, i8** %3
%11 = call i32* @open_file(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %5
store i32 0, i32* %9
br label %12
12: ; preds = %24, %2
%13 = getelementptr inbounds [20000 x i8], [20000 x i8]* %6, i64 0, i64 0
%14 = load i32*, i32** %5
%15 = call i32* @fgets(i8* %13, i32 20000, i32* %14)
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %22
17: ; preds = %12
%18 = getelementptr inbounds [20000 x i8], [20000 x i8]* %6, i64 0, i64 0
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 0
br label %22
22: ; preds = %17, %12
%23 = phi i1 [ false, %12 ], [ %21, %17 ]
br i1 %23, label %24, label %37
24: ; preds = %22
%25 = getelementptr inbounds [20000 x i8], [20000 x i8]* %6, i64 0, i64 0
%26 = call i32 @sscanf(i8* %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %7, i32* %8)
%27 = load i32, i32* %8
%28 = load i32, i32* %7
%29 = sub nsw i32 %27, %28
%30 = add nsw i32 %29, 1
%31 = load i32*, i32** %4
%32 = load i32, i32* %9
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
store i32 %30, i32* %34
%35 = load i32, i32* %9
%36 = add nsw i32 %35, 1
store i32 %36, i32* %9
br label %12
37: ; preds = %22
%38 = load i32, i32* %9
ret i32 %38
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [6 x i8] c"%d %d\00"
define i32 @read_windows(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca [20000 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = getelementptr inbounds [20000 x i8], [20000 x i8]* %3, i64 0, i64 0
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = tail call i32* @open_file(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = call i32* @fgets(i8* %6, i32 20000, i32* %9)
%11 = icmp ne i32* %10, null
%12 = load i8, i8* %6
%13 = icmp ne i8 %12, 0
%14 = select i1 %11, i1 %13, i1 false
br i1 %14, label %15, label %31
15: ; preds = %2, %15
%16 = phi i64 [ %23, %15 ], [ 0, %2 ]
%17 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %4, i32* %5)
%18 = load i32, i32* %5
%19 = load i32, i32* %4
%20 = add i32 %18, 1
%21 = sub i32 %20, %19
%22 = getelementptr inbounds i32, i32* %1, i64 %16
store i32 %21, i32* %22
%23 = add nuw i64 %16, 1
%24 = call i32* @fgets(i8* %6, i32 20000, i32* %9)
%25 = icmp ne i32* %24, null
%26 = load i8, i8* %6
%27 = icmp ne i8 %26, 0
%28 = select i1 %25, i1 %27, i1 false
br i1 %28, label %15, label %29
29: ; preds = %15
%30 = trunc i64 %23 to i32
br label %31
31: ; preds = %29, %2
%32 = phi i32 [ 0, %2 ], [ %30, %29 ]
ret i32 %32
}