#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *, char *);
int /*<<< orphan*/ printf(char *, char *);
void parse_supervisor_data(char *charnames[], int charresults[]) {
  char filename[] = "supervisor.txt";
  FILE *fp;
  int i;
  char foo;
  fp = fopen(filename, "r");
  if (fp == NULL) {
    printf("Error opening %s\n", filename);
    printf("File %s needs to be present in the current directory with the "
           "details of training samples and expected outputs\n",
           filename);
    exit(0);
  }
  for (i = 0; i < 52; i++) {
    fscanf(fp, "%s %c\n", charnames[i], &foo);
    charresults[i] = foo - 'A';
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<parse_supervisor_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe99(%rip),%rax
mov    %rax,-0x1f(%rbp)
mov    0xe97(%rip),%eax
mov    %eax,-0x17(%rbp)
mov    0xe91(%rip),%ax
mov    %ax,-0x13(%rbp)
mov    0xe89(%rip),%al
mov    %al,-0x11(%rbp)
lea    -0x1f(%rbp),%rdi
lea    0xe7c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ce <parse_supervisor_data+0x7e>
lea    -0x1f(%rbp),%rsi
lea    0xe5f(%rip),%rdi
call   1040 <printf@plt>
lea    -0x1f(%rbp),%rsi
lea    0xe61(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x34,-0x2c(%rbp)
jge    121f <parse_supervisor_data+0xcf>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe9d(%rip),%rsi
lea    -0x2d(%rbp),%rcx
call   1050 <fscanf@plt>
movsbl -0x2d(%rbp),%edx
sub    $0x41,%edx
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11d5 <parse_supervisor_data+0x85>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_supervisor_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
movabs $0x7478742e726f73,%rax
mov    %rax,0xf(%rsp)
movabs $0x7369767265707573,%rax
76 69 73
mov    %rax,0x8(%rsp)
lea    0xe86(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11ef <parse_supervisor_data+0x9f>
mov    %rax,%rbx
xor    %ebp,%ebp
lea    0xeef(%rip),%r12
lea    0x7(%rsp),%r13
nopl   0x0(%rax)
mov    (%r15,%rbp,8),%rdx
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rcx
call   1050 <fscanf@plt>
movsbl 0x7(%rsp),%eax
add    $0xffffffbf,%eax
mov    %eax,(%r14,%rbp,4)
add    $0x1,%rbp
cmp    $0x34,%rbp
jne    11b0 <parse_supervisor_data+0x60>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe1b(%rip),%rdi
lea    0x8(%rsp),%rbx
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0xe19(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@__const.parse_supervisor_data.filename = [15 x i8] c"supervisor.txt\00"
@.str = [2 x i8] c"r\00"
@.str.1 = [18 x i8] c"Error opening %s\0A\00"
@.str.2 = [112 x i8] c"File %s needs to be present in the current directory with the details of training samples and expected outputs\0A\00"
@.str.3 = [7 x i8] c"%s %c\0A\00"
define void @parse_supervisor_data(i8** %0, i32* %1) {
%3 = alloca i8**
%4 = alloca i32*
%5 = alloca [15 x i8]
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8
store i8** %0, i8*** %3
store i32* %1, i32** %4
%9 = bitcast [15 x i8]* %5 to i8*
%10 = getelementptr inbounds [15 x i8], [15 x i8]* %5, i64 0, i64 0
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %6
%12 = load i32*, i32** %6
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = getelementptr inbounds [15 x i8], [15 x i8]* %5, i64 0, i64 0
%16 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds [15 x i8], [15 x i8]* %5, i64 0, i64 0
%18 = call i32 @printf(i8* getelementptr inbounds ([112 x i8], [112 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %2
store i32 0, i32* %7
br label %21
21: ; preds = %39, %20
%22 = load i32, i32* %7
%23 = icmp slt i32 %22, 52
br i1 %23, label %24, label %42
24: ; preds = %21
%25 = load i32*, i32** %6
%26 = load i8**, i8*** %3
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
%31 = call i32 @fscanf(i32* %25, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %30, i8* %8)
%32 = load i8, i8* %8
%33 = sext i8 %32 to i32
%34 = sub nsw i32 %33, 65
%35 = load i32*, i32** %4
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
store i32 %34, i32* %38
br label %39
39: ; preds = %24
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
br label %21
42: ; preds = %21
%43 = load i32*, i32** %6
%44 = call i32 @fclose(i32* %43)
ret void
}

LLVM IR (-O2):
@__const.parse_supervisor_data.filename = [15 x i8] c"supervisor.txt\00"
@.str = [2 x i8] c"r\00"
@.str.1 = [18 x i8] c"Error opening %s\0A\00"
@.str.2 = [112 x i8] c"File %s needs to be present in the current directory with the details of training samples and expected outputs\0A\00"
@.str.3 = [7 x i8] c"%s %c\0A\00"
define void @parse_supervisor_data(i8** nocapture %0, i32* nocapture writeonly %1) {
%3 = alloca [15 x i8]
%4 = alloca i8
%5 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%10 = call i32 @printf(i8* getelementptr inbounds ([112 x i8], [112 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%11 = call i32 @exit(i32 0)
unreachable
12: ; preds = %2, %12
%13 = phi i64 [ %21, %12 ], [ 0, %2 ]
%14 = getelementptr inbounds i8*, i8** %0, i64 %13
%15 = load i8*, i8** %14
%16 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %15, i8* %4)
%17 = load i8, i8* %4
%18 = sext i8 %17 to i32
%19 = add nsw i32 %18, -65
%20 = getelementptr inbounds i32, i32* %1, i64 %13
store i32 %19, i32* %20
%21 = add nuw nsw i64 %13, 1
%22 = icmp eq i64 %21, 52
br i1 %22, label %23, label %12
23: ; preds = %12
%24 = call i32 @fclose(i32* %6)
ret void
}