#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 */
struct word_tokenizer {
  int dummy;
};
struct hash {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
struct hash *create_hash(int const);
struct word_tokenizer *create_word_tokenizer(char *);
int /*<<< orphan*/ destroy_word_tokenizer(struct word_tokenizer *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ hash_set(struct hash *, char *, void *);
scalar_t__ is_all_whitespace(char *);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
char *read_line(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *wt_next(struct word_tokenizer *);
struct hash *read_map(const char *filename) {
  const int HASH_SIZE = 1000;
  FILE *map_file = fopen(filename, "r");
  if (NULL == map_file) {
    perror(NULL);
    exit(EXIT_FAILURE);
  }
  struct hash *map = create_hash(HASH_SIZE);
  if (NULL == map) {
    perror(NULL);
    exit(EXIT_FAILURE);
  }
  char *line;
  while (NULL != (line = read_line(map_file))) {
    if ('#' == line[0] || is_all_whitespace(line)) {
      free(line);
      continue;
    }
    char *key, *value;
    struct word_tokenizer *wtok = create_word_tokenizer(line);
    if (NULL == wtok) {
      perror(NULL);
      exit(EXIT_FAILURE);
    }
    key = wt_next(wtok);
    if (NULL == key) {
      fprintf(stderr, "Wrong format in line %s - aborting.\n", line);
      exit(EXIT_FAILURE);
    }
    value = wt_next(wtok);
    if (NULL == value) {
      fprintf(stderr, "Wrong format in line %s - aborting.\n", line);
      exit(EXIT_FAILURE);
    }
    if (!hash_set(map, key, (void *)value)) {
      perror(NULL);
      exit(EXIT_FAILURE);
    }
    destroy_word_tokenizer(wtok);
    free(key);
    free(line);
  }
  return map;
}


x86 assembly (clang, -O0):
<read_map>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x3e8,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe22(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    120a <read_map+0x4a>
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <perror@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    $0x3e8,%edi
call   1090 <create_hash@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    123b <read_map+0x7b>
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <perror@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
jmp    1240 <read_map+0x80>
mov    -0x18(%rbp),%rdi
call   1080 <read_line@plt>
mov    %rax,%rcx
mov    %rcx,-0x28(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
je     1391 <read_map+0x1d1>
mov    -0x28(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x23,%eax
cmp    %ecx,%eax
je     1282 <read_map+0xc2>
mov    -0x28(%rbp),%rdi
call   10e0 <is_all_whitespace@plt>
cmp    $0x0,%rax
je     1290 <read_map+0xd0>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    1240 <read_map+0x80>
mov    -0x28(%rbp),%rdi
call   10c0 <create_word_tokenizer@plt>
mov    %rax,-0x40(%rbp)
xor    %eax,%eax
cmp    -0x40(%rbp),%rax
jne    12c0 <read_map+0x100>
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <perror@plt>
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x40(%rbp),%rdi
call   1070 <wt_next@plt>
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
cmp    -0x30(%rbp),%rax
jne    1300 <read_map+0x140>
mov    0x2d00(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xd15(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2cdf(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x40(%rbp),%rdi
call   1070 <wt_next@plt>
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
cmp    -0x38(%rbp),%rax
jne    1340 <read_map+0x180>
mov    0x2cc0(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xcd5(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2c9f(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1050 <hash_set@plt>
cmp    $0x0,%eax
jne    1371 <read_map+0x1b1>
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <perror@plt>
mov    0x2c6e(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x40(%rbp),%rdi
call   1060 <destroy_word_tokenizer@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    1240 <read_map+0x80>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_map>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
lea    0xe30(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     128d <read_map+0xcd>
mov    %rax,%r15
mov    $0x3e8,%edi
call   1090 <create_hash@plt>
test   %rax,%rax
je     128d <read_map+0xcd>
mov    %rax,%r14
mov    %r15,%rdi
call   1080 <read_line@plt>
test   %rax,%rax
je     1296 <read_map+0xd6>
mov    %rax,%rbx
jmp    1238 <read_map+0x78>
mov    %r12,%rdi
call   1060 <destroy_word_tokenizer@plt>
mov    %r13,%rdi
call   1030 <free@plt>
nopl   (%rax)
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1080 <read_line@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1296 <read_map+0xd6>
cmpb   $0x23,(%rbx)
je     1220 <read_map+0x60>
mov    %rbx,%rdi
call   10e0 <is_all_whitespace@plt>
test   %rax,%rax
jne    1220 <read_map+0x60>
mov    %rbx,%rdi
call   10c0 <create_word_tokenizer@plt>
test   %rax,%rax
je     128d <read_map+0xcd>
mov    %rax,%r12
mov    %rax,%rdi
call   1070 <wt_next@plt>
test   %rax,%rax
je     12a3 <read_map+0xe3>
mov    %rax,%r13
mov    %r12,%rdi
call   1070 <wt_next@plt>
test   %rax,%rax
je     12a3 <read_map+0xe3>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %rax,%rdx
call   1050 <hash_set@plt>
test   %eax,%eax
jne    120d <read_map+0x4d>
xor    %edi,%edi
call   10b0 <perror@plt>
jmp    12bb <read_map+0xfb>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
lea    0xd4f(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.hash = type { i32 }
%struct.word_tokenizer = type { i32 }
@.str = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.1 = [37 x i8] c"Wrong format in line %s - aborting.\0A\00"
define %struct.hash* @read_map(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
%5 = alloca %struct.hash*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca %struct.word_tokenizer*
store i8* %0, i8** %2
store i32 1000, i32* %3
%10 = load i8*, i8** %2
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %4
%12 = load i32*, i32** %4
%13 = icmp eq i32* null, %12
br i1 %13, label %14, label %18
14: ; preds = %1
%15 = call i32 @perror(i32* null)
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %1
%19 = call %struct.hash* @create_hash(i32 1000)
store %struct.hash* %19, %struct.hash** %5
%20 = load %struct.hash*, %struct.hash** %5
%21 = icmp eq %struct.hash* null, %20
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = call i32 @perror(i32* null)
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %18
br label %27
27: ; preds = %85, %41, %26
%28 = load i32*, i32** %4
%29 = call i8* @read_line(i32* %28)
store i8* %29, i8** %6
%30 = icmp ne i8* null, %29
br i1 %30, label %31, label %92
31: ; preds = %27
%32 = load i8*, i8** %6
%33 = getelementptr inbounds i8, i8* %32, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 35, %35
br i1 %36, label %41, label %37
37: ; preds = %31
%38 = load i8*, i8** %6
%39 = call i64 @is_all_whitespace(i8* %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %37, %31
%42 = load i8*, i8** %6
%43 = call i32 @free(i8* %42)
br label %27
44: ; preds = %37
%45 = load i8*, i8** %6
%46 = call %struct.word_tokenizer* @create_word_tokenizer(i8* %45)
store %struct.word_tokenizer* %46, %struct.word_tokenizer** %9
%47 = load %struct.word_tokenizer*, %struct.word_tokenizer** %9
%48 = icmp eq %struct.word_tokenizer* null, %47
br i1 %48, label %49, label %53
49: ; preds = %44
%50 = call i32 @perror(i32* null)
%51 = load i32, i32* @EXIT_FAILURE
%52 = call i32 @exit(i32 %51)
unreachable
53: ; preds = %44
%54 = load %struct.word_tokenizer*, %struct.word_tokenizer** %9
%55 = call i8* @wt_next(%struct.word_tokenizer* %54)
store i8* %55, i8** %7
%56 = load i8*, i8** %7
%57 = icmp eq i8* null, %56
br i1 %57, label %58, label %64
58: ; preds = %53
%59 = load i32, i32* @stderr
%60 = load i8*, i8** %6
%61 = call i32 @fprintf(i32 %59, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %60)
%62 = load i32, i32* @EXIT_FAILURE
%63 = call i32 @exit(i32 %62)
unreachable
64: ; preds = %53
%65 = load %struct.word_tokenizer*, %struct.word_tokenizer** %9
%66 = call i8* @wt_next(%struct.word_tokenizer* %65)
store i8* %66, i8** %8
%67 = load i8*, i8** %8
%68 = icmp eq i8* null, %67
br i1 %68, label %69, label %75
69: ; preds = %64
%70 = load i32, i32* @stderr
%71 = load i8*, i8** %6
%72 = call i32 @fprintf(i32 %70, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %71)
%73 = load i32, i32* @EXIT_FAILURE
%74 = call i32 @exit(i32 %73)
unreachable
75: ; preds = %64
%76 = load %struct.hash*, %struct.hash** %5
%77 = load i8*, i8** %7
%78 = load i8*, i8** %8
%79 = call i32 @hash_set(%struct.hash* %76, i8* %77, i8* %78)
%80 = icmp ne i32 %79, 0
br i1 %80, label %85, label %81
81: ; preds = %75
%82 = call i32 @perror(i32* null)
%83 = load i32, i32* @EXIT_FAILURE
%84 = call i32 @exit(i32 %83)
unreachable
85: ; preds = %75
%86 = load %struct.word_tokenizer*, %struct.word_tokenizer** %9
%87 = call i32 @destroy_word_tokenizer(%struct.word_tokenizer* %86)
%88 = load i8*, i8** %7
%89 = call i32 @free(i8* %88)
%90 = load i8*, i8** %6
%91 = call i32 @free(i8* %90)
br label %27
92: ; preds = %27
%93 = load %struct.hash*, %struct.hash** %5
ret %struct.hash* %93
}

LLVM IR (-O2):
%struct.hash = type { i32 }
%struct.word_tokenizer = type { i32 }
@.str = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.1 = [37 x i8] c"Wrong format in line %s - aborting.\0A\00"
define %struct.hash* @read_map(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = tail call i32 @perror(i32* null)
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %1
%9 = tail call %struct.hash* @create_hash(i32 1000)
%10 = icmp eq %struct.hash* %9, null
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = tail call i8* @read_line(i32* %2)
%13 = icmp eq i8* %12, null
br i1 %13, label %62, label %18
14: ; preds = %8
%15 = tail call i32 @perror(i32* null)
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %11, %25
%19 = phi i8* [ %27, %25 ], [ %12, %11 ]
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 35
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = tail call i64 @is_all_whitespace(i8* %19)
%24 = icmp eq i64 %23, 0
br i1 %24, label %29, label %25
25: ; preds = %18, %22, %59
%26 = tail call i32 @free(i8* %19)
%27 = tail call i8* @read_line(i32* %2)
%28 = icmp eq i8* %27, null
br i1 %28, label %62, label %18
29: ; preds = %22
%30 = tail call %struct.word_tokenizer* @create_word_tokenizer(i8* %19)
%31 = icmp eq %struct.word_tokenizer* %30, null
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = tail call i32 @perror(i32* null)
%34 = load i32, i32* @EXIT_FAILURE
%35 = tail call i32 @exit(i32 %34)
unreachable
36: ; preds = %29
%37 = tail call i8* @wt_next(%struct.word_tokenizer* %30)
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %44
39: ; preds = %36
%40 = load i32, i32* @stderr
%41 = tail call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%42 = load i32, i32* @EXIT_FAILURE
%43 = tail call i32 @exit(i32 %42)
unreachable
44: ; preds = %36
%45 = tail call i8* @wt_next(%struct.word_tokenizer* %30)
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %52
47: ; preds = %44
%48 = load i32, i32* @stderr
%49 = tail call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%50 = load i32, i32* @EXIT_FAILURE
%51 = tail call i32 @exit(i32 %50)
unreachable
52: ; preds = %44
%53 = tail call i32 @hash_set(%struct.hash* %9, i8* %37, i8* %45)
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %52
%56 = tail call i32 @perror(i32* null)
%57 = load i32, i32* @EXIT_FAILURE
%58 = tail call i32 @exit(i32 %57)
unreachable
59: ; preds = %52
%60 = tail call i32 @destroy_word_tokenizer(%struct.word_tokenizer* %30)
%61 = tail call i32 @free(i8* %37)
br label %25
62: ; preds = %25, %11
ret %struct.hash* %9
}