#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 */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, int *);
void file_read(char *filename) {
  FILE *inputfile;
  int i, j;
  char c, str[10];
  inputfile = fopen(filename, "r");
  if (inputfile) {
    printf("Reading file %s\n", filename);
    j = 0;
    i = 0;
    while ((c = fgetc(inputfile)) != EOF && j < 9) {
      if (c != ' ' && c != '\n') {
        str[j] = c;
        j++;
      } else if (j > 0) {
        str[j + 1] = '\0';
        sscanf(str, "%d", &i);
        printf("%d ", i);
        if (i % 5 == 0)
          printf("\n");
        j = 0;
      }
    }
    fclose(inputfile);
  } else {
    printf("Error: could not open %s for reading\n", filename);
  }
}


x86 assembly (clang, -O0):
<file_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     128b <file_read+0x13b>
mov    -0x8(%rbp),%rsi
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%ecx
mov    0x2e37(%rip),%rax
movsbl (%rax),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x24(%rbp)
je     11cb <file_read+0x7b>
cmpl   $0x9,-0x18(%rbp)
setl   %al
mov    %al,-0x24(%rbp)
mov    -0x24(%rbp),%al
test   $0x1,%al
jne    11db <file_read+0x8b>
jmp    127d <file_read+0x12d>
movsbl -0x19(%rbp),%eax
cmp    $0x20,%eax
je     120e <file_read+0xbe>
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
je     120e <file_read+0xbe>
mov    -0x19(%rbp),%cl
movslq -0x18(%rbp),%rax
mov    %cl,-0x23(%rbp,%rax,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1278 <file_read+0x128>
cmpl   $0x0,-0x18(%rbp)
jle    1273 <file_read+0x123>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x0,-0x23(%rbp,%rax,1)
lea    -0x23(%rbp),%rdi
lea    0xde3(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1060 <sscanf@plt>
mov    -0x14(%rbp),%esi
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    126c <file_read+0x11c>
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x18(%rbp)
jmp    1278 <file_read+0x128>
jmp    119b <file_read+0x4b>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
jmp    129d <file_read+0x14d>
mov    -0x8(%rbp),%rsi
lea    0xd84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_read>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
lea    0xe88(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1263 <file_read+0x103>
mov    %rax,%rbx
lea    0xe72(%rip),%rdi
xor    %ebp,%ebp
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
movl   $0x0,0x8(%rsp)
mov    %rbx,%rdi
call   1060 <fgetc@plt>
mov    0x2e35(%rip),%r15
cmp    (%r15),%al
je     124c <file_read+0xec>
lea    0xe(%rsp),%r14
lea    0x8(%rsp),%r12
lea    0xe49(%rip),%r13
nopl   (%rax)
cmp    $0xa,%al
je     11d8 <file_read+0x78>
cmp    $0x20,%al
jne    1230 <file_read+0xd0>
test   %ebp,%ebp
jle    123a <file_read+0xda>
mov    %ebp,%eax
movb   $0x0,0x1(%rax,%r14,1)
mov    %r14,%rdi
lea    0xe25(%rip),%rsi
mov    %r12,%rdx
call   1070 <sscanf@plt>
mov    0x8(%rsp),%esi
xor    %ebp,%ebp
mov    %r13,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
imul   $0xcccccccd,0x8(%rsp),%eax
cc
add    $0x19999999,%eax
cmp    $0x33333332,%eax
ja     123a <file_read+0xda>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    123a <file_read+0xda>
cs nopw 0x0(%rax,%rax,1)
movslq %ebp,%rcx
mov    %al,0xe(%rsp,%rcx,1)
add    $0x1,%ebp
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    (%r15),%al
je     124c <file_read+0xec>
cmp    $0x9,%ebp
jl     11d0 <file_read+0x70>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdb0(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <printf@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [17 x i8] c"Reading file %s\0A\00"
@EOF = global i8 0
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%d \00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [38 x i8] c"Error: could not open %s for reading\0A\00"
define void @file_read(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca [10 x i8]
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %3
%10 = load i32*, i32** %3
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %65
12: ; preds = %1
%13 = load i8*, i8** %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %13)
store i32 0, i32* %5
store i32 0, i32* %4
br label %15
15: ; preds = %61, %12
%16 = load i32*, i32** %3
%17 = call signext i8 @fgetc(i32* %16)
store i8 %17, i8* %6
%18 = sext i8 %17 to i32
%19 = load i8, i8* @EOF
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %18, %20
br i1 %21, label %22, label %25
22: ; preds = %15
%23 = load i32, i32* %5
%24 = icmp slt i32 %23, 9
br label %25
25: ; preds = %22, %15
%26 = phi i1 [ false, %15 ], [ %24, %22 ]
br i1 %26, label %27, label %62
27: ; preds = %25
%28 = load i8, i8* %6
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 32
br i1 %30, label %31, label %42
31: ; preds = %27
%32 = load i8, i8* %6
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 10
br i1 %34, label %35, label %42
35: ; preds = %31
%36 = load i8, i8* %6
%37 = load i32, i32* %5
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 %38
store i8 %36, i8* %39
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
store i32 %41, i32* %5
br label %61
42: ; preds = %31, %27
%43 = load i32, i32* %5
%44 = icmp sgt i32 %43, 0
br i1 %44, label %45, label %60
45: ; preds = %42
%46 = load i32, i32* %5
%47 = add nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 %48
store i8 0, i8* %49
%50 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%51 = call i32 @sscanf(i8* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%52 = load i32, i32* %4
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %52)
%54 = load i32, i32* %4
%55 = srem i32 %54, 5
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %45
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %59
59: ; preds = %57, %45
store i32 0, i32* %5
br label %60
60: ; preds = %59, %42
br label %61
61: ; preds = %60, %35
br label %15
62: ; preds = %25
%63 = load i32*, i32** %3
%64 = call i32 @fclose(i32* %63)
br label %68
65: ; preds = %1
%66 = load i8*, i8** %2
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i8* %66)
br label %68
68: ; preds = %65, %62
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [17 x i8] c"Reading file %s\0A\00"
@EOF = global i8 0
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%d \00"
@.str.5 = [38 x i8] c"Error: could not open %s for reading\0A\00"
define void @file_read(i8* %0) {
%2 = alloca i32
%3 = alloca [10 x i8]
%4 = bitcast i32* %2 to i8*
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %43, label %8
8: ; preds = %1
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %0)
store i32 0, i32* %2
%10 = call signext i8 @fgetc(i32* %6)
%11 = load i8, i8* @EOF
%12 = icmp eq i8 %10, %11
br i1 %12, label %41, label %13
13: ; preds = %8, %34
%14 = phi i8 [ %36, %34 ], [ %10, %8 ]
%15 = phi i32 [ %35, %34 ], [ 0, %8 ]
switch i8 %14, label %16 [
i8 32, label %20
i8 10, label %20
]
16: ; preds = %13
%17 = sext i32 %15 to i64
%18 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %17
store i8 %14, i8* %18
%19 = add nsw i32 %15, 1
br label %34
20: ; preds = %13, %13
%21 = icmp sgt i32 %15, 0
br i1 %21, label %22, label %34
22: ; preds = %20
%23 = add nuw nsw i32 %15, 1
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %24
store i8 0, i8* %25
%26 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%27 = load i32, i32* %2
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %2
%30 = srem i32 %29, 5
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %22
%33 = call i32 @putchar(i32 10)
br label %34
34: ; preds = %22, %32, %20, %16
%35 = phi i32 [ %19, %16 ], [ %15, %20 ], [ 0, %32 ], [ 0, %22 ]
%36 = call signext i8 @fgetc(i32* %6)
%37 = load i8, i8* @EOF
%38 = icmp ne i8 %36, %37
%39 = icmp slt i32 %35, 9
%40 = select i1 %38, i1 %39, i1 false
br i1 %40, label %13, label %41
41: ; preds = %34, %8
%42 = call i32 @fclose(i32* %6)
br label %45
43: ; preds = %1
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i8* %0)
br label %45
45: ; preds = %43, %41
ret void
}