#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 */
scalar_t__ EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, unsigned int *, unsigned int *);
int /*<<< orphan*/ printf(char *, ...);
void read_cluster_map(unsigned int *map, char *map_path) {
  FILE *fp;
  unsigned int document_id, temp_document_id;
  fp = fopen(map_path, "r");
  if (!fp) {
    printf("ERROR: Cluster map file not found: %s", map_path);
    exit(1);
  }
  document_id = 1;
  while (fscanf(fp, "%u %u", &temp_document_id, &map[document_id]) != EOF) {
    if (document_id != temp_document_id) {
      printf("ERROR: How is that even possible?!?");
      exit(1);
    }
    document_id += 1;
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<read_cluster_map>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119b <read_cluster_map+0x4b>
mov    -0x10(%rbp),%rsi
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    -0x1c(%rbp),%eax
shl    $0x2,%rax
add    %rax,%rcx
lea    0xe6d(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1050 <fscanf@plt>
mov    0x2e1d(%rip),%rcx
cmp    (%rcx),%rax
je     1206 <read_cluster_map+0xb6>
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
je     11f8 <read_cluster_map+0xa8>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a2 <read_cluster_map+0x52>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_cluster_map>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe98(%rip),%rsi
mov    %r15,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     1212 <read_cluster_map+0xc2>
mov    %rax,%rbx
lea    0x4(%r14),%rcx
lea    0xea1(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    0x2e4d(%rip),%r13
cmp    0x0(%r13),%rax
je     11e3 <read_cluster_map+0x93>
mov    $0x1,%ebp
lea    0xe7b(%rip),%r15
lea    0x4(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    0x4(%rsp),%ebp
jne    11fa <read_cluster_map+0xaa>
add    $0x1,%ebp
mov    %ebp,%eax
lea    (%r14,%rax,4),%rcx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <fscanf@plt>
cmp    0x0(%r13),%rax
jne    11c0 <read_cluster_map+0x70>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe2d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xde9(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [38 x i8] c"ERROR: Cluster map file not found: %s\00"
@.str.2 = [6 x i8] c"%u %u\00"
@EOF = global i64 0
@.str.3 = [36 x i8] c"ERROR: How is that even possible?!?\00"
define void @read_cluster_map(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %5
%10 = load i32*, i32** %5
%11 = icmp ne i32* %10, null
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
store i32 1, i32* %6
br label %17
17: ; preds = %33, %16
%18 = load i32*, i32** %5
%19 = load i32*, i32** %3
%20 = load i32, i32* %6
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = call i64 @fscanf(i32* %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %7, i32* %22)
%24 = load i64, i64* @EOF
%25 = icmp ne i64 %23, %24
br i1 %25, label %26, label %36
26: ; preds = %17
%27 = load i32, i32* %6
%28 = load i32, i32* %7
%29 = icmp ne i32 %27, %28
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %26
%34 = load i32, i32* %6
%35 = add i32 %34, 1
store i32 %35, i32* %6
br label %17
36: ; preds = %17
%37 = load i32*, i32** %5
%38 = call i32 @fclose(i32* %37)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [38 x i8] c"ERROR: Cluster map file not found: %s\00"
@.str.2 = [6 x i8] c"%u %u\00"
@EOF = global i64 0
@.str.3 = [36 x i8] c"ERROR: How is that even possible?!?\00"
define void @read_cluster_map(i32* %0, i8* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = getelementptr inbounds i32, i32* %0, i64 1
%9 = call i64 @fscanf(i32* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %3, i32* %8)
%10 = load i64, i64* @EOF
%11 = icmp eq i64 %9, %10
br i1 %11, label %29, label %21
12: ; preds = %2
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %21
%16 = zext i32 %25 to i64
%17 = getelementptr inbounds i32, i32* %0, i64 %16
%18 = call i64 @fscanf(i32* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %3, i32* %17)
%19 = load i64, i64* @EOF
%20 = icmp eq i64 %18, %19
br i1 %20, label %29, label %21
21: ; preds = %7, %15
%22 = phi i32 [ %25, %15 ], [ 1, %7 ]
%23 = load i32, i32* %3
%24 = icmp eq i32 %22, %23
%25 = add i32 %22, 1
br i1 %24, label %15, label %26
26: ; preds = %21
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %15, %7
%30 = call i32 @fclose(i32* %5)
ret void
}