#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int config_read(FILE *f, int n, int *joymap) {
  for (int i = 0; !feof(f) && i < n; i++) {
    char c;
    fread(&c, sizeof(char), 1, f);
    switch (c) {
    case 'a':
      joymap[i] = (0x1);
      break;
    case 'q':
      joymap[i] = (0x1 << 1);
      break;
    case 'w':
      joymap[i] = (0x1 << 2);
      break;
    case 'e':
      joymap[i] = (0x1 << 3);
      break;
    case 'd':
      joymap[i] = (0x1 << 4);
      break;
    case 'c':
      joymap[i] = (0x1 << 5);
      break;
    case 'x':
      joymap[i] = (0x1 << 6);
      break;
    case 'z':
      joymap[i] = (0x1 << 7);
      break;
    case '1':
      joymap[i] = (0x1 << 9);
      break;
    case '3':
      joymap[i] = (0x1 << 8);
      break;
    case ' ':
    case '\r':
    case '\n':
      joymap[i] = 0x0;
      break;
    default:
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<config_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x26(%rbp)
jne    115f <config_read+0x3f>
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
setl   %al
mov    %al,-0x26(%rbp)
mov    -0x26(%rbp),%al
test   $0x1,%al
jne    116f <config_read+0x4f>
jmp    12a8 <config_read+0x188>
mov    -0x10(%rbp),%rcx
lea    -0x25(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
movsbl -0x25(%rbp),%eax
add    $0xfffffff6,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x70,%eax
ja     1289 <config_read+0x169>
mov    -0x30(%rbp),%rax
lea    0xe5c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
jmp    1295 <config_read+0x175>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movl   $0x2,(%rax,%rcx,4)
jmp    1295 <config_read+0x175>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movl   $0x4,(%rax,%rcx,4)
jmp    1295 <config_read+0x175>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movl   $0x8,(%rax,%rcx,4)
jmp    1295 <config_read+0x175>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movl   $0x10,(%rax,%rcx,4)
jmp    1295 <config_read+0x175>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movl   $0x20,(%rax,%rcx,4)
jmp    1295 <config_read+0x175>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movl   $0x40,(%rax,%rcx,4)
jmp    1295 <config_read+0x175>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movl   $0x80,(%rax,%rcx,4)
jmp    1295 <config_read+0x175>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movl   $0x200,(%rax,%rcx,4)
jmp    1295 <config_read+0x175>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movl   $0x100,(%rax,%rcx,4)
jmp    1295 <config_read+0x175>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
jmp    1295 <config_read+0x175>
movl   $0xffffffff,-0x4(%rbp)
jmp    12af <config_read+0x18f>
jmp    129a <config_read+0x17a>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    113a <config_read+0x1a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<config_read>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %esi,%r15d
mov    %rdi,%rbp
call   1040 <feof@plt>
xor    %ecx,%ecx
test   %eax,%eax
jne    1213 <config_read+0xf3>
test   %r15d,%r15d
jle    1213 <config_read+0xf3>
mov    %r15d,%r13d
mov    $0x1,%ebx
lea    0xea5(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    $0x1,%r15d
lea    0x7(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1030 <fread@plt>
movsbl 0x7(%rsp),%eax
add    $0xfffffff6,%eax
cmp    $0x70,%eax
ja     1224 <config_read+0x104>
movslq (%r14,%rax,4),%rax
add    %r14,%rax
jmp    *%rax
xor    %r15d,%r15d
jmp    11f0 <config_read+0xd0>
mov    $0x200,%r15d
jmp    11f0 <config_read+0xd0>
mov    $0x100,%r15d
jmp    11f0 <config_read+0xd0>
mov    $0x20,%r15d
jmp    11f0 <config_read+0xd0>
mov    $0x10,%r15d
jmp    11f0 <config_read+0xd0>
mov    $0x8,%r15d
jmp    11f0 <config_read+0xd0>
mov    $0x2,%r15d
jmp    11f0 <config_read+0xd0>
mov    $0x4,%r15d
jmp    11f0 <config_read+0xd0>
mov    $0x40,%r15d
jmp    11f0 <config_read+0xd0>
mov    $0x80,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15d,-0x4(%r12,%rbx,4)
mov    %rbp,%rdi
call   1040 <feof@plt>
test   %eax,%eax
jne    1211 <config_read+0xf1>
lea    0x1(%rbx),%rax
cmp    %r13,%rbx
mov    %rax,%rbx
jb     1160 <config_read+0x40>
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%ecx
jmp    1213 <config_read+0xf3>

LLVM IR (-O0):
define i32 @config_read(i32* %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i8
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32 0, i32* %8
br label %10
10: ; preds = %82, %3
%11 = load i32*, i32** %5
%12 = call i32 @feof(i32* %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %10
%15 = load i32, i32* %8
%16 = load i32, i32* %6
%17 = icmp slt i32 %15, %16
br label %18
18: ; preds = %14, %10
%19 = phi i1 [ false, %10 ], [ %17, %14 ]
br i1 %19, label %20, label %85
20: ; preds = %18
%21 = load i32*, i32** %5
%22 = call i32 @fread(i8* %9, i32 1, i32 1, i32* %21)
%23 = load i8, i8* %9
%24 = sext i8 %23 to i32
switch i32 %24, label %80 [
i32 97, label %25
i32 113, label %30
i32 119, label %35
i32 101, label %40
i32 100, label %45
i32 99, label %50
i32 120, label %55
i32 122, label %60
i32 49, label %65
i32 51, label %70
i32 32, label %75
i32 13, label %75
i32 10, label %75
]
25: ; preds = %20
%26 = load i32*, i32** %7
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
store i32 1, i32* %29
br label %81
30: ; preds = %20
%31 = load i32*, i32** %7
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
store i32 2, i32* %34
br label %81
35: ; preds = %20
%36 = load i32*, i32** %7
%37 = load i32, i32* %8
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %36, i64 %38
store i32 4, i32* %39
br label %81
40: ; preds = %20
%41 = load i32*, i32** %7
%42 = load i32, i32* %8
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
store i32 8, i32* %44
br label %81
45: ; preds = %20
%46 = load i32*, i32** %7
%47 = load i32, i32* %8
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %46, i64 %48
store i32 16, i32* %49
br label %81
50: ; preds = %20
%51 = load i32*, i32** %7
%52 = load i32, i32* %8
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %51, i64 %53
store i32 32, i32* %54
br label %81
55: ; preds = %20
%56 = load i32*, i32** %7
%57 = load i32, i32* %8
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i32, i32* %56, i64 %58
store i32 64, i32* %59
br label %81
60: ; preds = %20
%61 = load i32*, i32** %7
%62 = load i32, i32* %8
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i32, i32* %61, i64 %63
store i32 128, i32* %64
br label %81
65: ; preds = %20
%66 = load i32*, i32** %7
%67 = load i32, i32* %8
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i32, i32* %66, i64 %68
store i32 512, i32* %69
br label %81
70: ; preds = %20
%71 = load i32*, i32** %7
%72 = load i32, i32* %8
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i32, i32* %71, i64 %73
store i32 256, i32* %74
br label %81
75: ; preds = %20, %20, %20
%76 = load i32*, i32** %7
%77 = load i32, i32* %8
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i32, i32* %76, i64 %78
store i32 0, i32* %79
br label %81
80: ; preds = %20
store i32 -1, i32* %4
br label %86
81: ; preds = %75, %70, %65, %60, %55, %50, %45, %40, %35, %30, %25
br label %82
82: ; preds = %81
%83 = load i32, i32* %8
%84 = add nsw i32 %83, 1
store i32 %84, i32* %8
br label %10
85: ; preds = %18
store i32 0, i32* %4
br label %86
86: ; preds = %85, %80
%87 = load i32, i32* %4
ret i32 %87
}

LLVM IR (-O2):
define i32 @config_read(i32* nocapture %0, i32 %1, i32* nocapture writeonly %2) {
%4 = alloca i8
%5 = tail call i32 @feof(i32* %0)
%6 = icmp eq i32 %5, 0
%7 = icmp sgt i32 %1, 0
%8 = and i1 %6, %7
br i1 %8, label %9, label %35
9: ; preds = %3
%10 = zext i32 %1 to i64
br label %11
11: ; preds = %9, %26
%12 = phi i64 [ 0, %9 ], [ %29, %26 ]
%13 = call i32 @fread(i8* %4, i32 1, i32 1, i32* %0)
%14 = load i8, i8* %4
%15 = sext i8 %14 to i32
switch i32 %15, label %34 [
i32 97, label %26
i32 113, label %16
i32 119, label %17
i32 101, label %18
i32 100, label %19
i32 99, label %20
i32 120, label %21
i32 122, label %22
i32 49, label %23
i32 51, label %24
i32 32, label %25
i32 13, label %25
i32 10, label %25
]
16: ; preds = %11
br label %26
17: ; preds = %11
br label %26
18: ; preds = %11
br label %26
19: ; preds = %11
br label %26
20: ; preds = %11
br label %26
21: ; preds = %11
br label %26
22: ; preds = %11
br label %26
23: ; preds = %11
br label %26
24: ; preds = %11
br label %26
25: ; preds = %11, %11, %11
br label %26
26: ; preds = %11, %16, %17, %18, %19, %20, %21, %22, %23, %24, %25
%27 = phi i32 [ 2, %16 ], [ 4, %17 ], [ 8, %18 ], [ 16, %19 ], [ 32, %20 ], [ 64, %21 ], [ 128, %22 ], [ 512, %23 ], [ 256, %24 ], [ 0, %25 ], [ 1, %11 ]
%28 = getelementptr inbounds i32, i32* %2, i64 %12
store i32 %27, i32* %28
%29 = add nuw nsw i64 %12, 1
%30 = tail call i32 @feof(i32* %0)
%31 = icmp eq i32 %30, 0
%32 = icmp ult i64 %29, %10
%33 = select i1 %31, i1 %32, i1 false
br i1 %33, label %11, label %35
34: ; preds = %11
br label %35
35: ; preds = %26, %3, %34
%36 = phi i32 [ -1, %34 ], [ 0, %3 ], [ 0, %26 ]
ret i32 %36
}