#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, unsigned int *);
int /*<<< orphan*/ printf(char *, char *);
void load_char_optim2(char *file, int N, int M, unsigned char *out) {
  int i, j;
  FILE *m_File = NULL;
  unsigned int tmp;
  int ip, ipp, fres;
  m_File = fopen(file, "r");
  if (!m_File)
    printf("Error: open %s.\n", file);
  for (i = 0; i < N; i++) {
    for (j = 0; j < M; j++) {
      ip = i / 4;
      ipp = i % 4;
      fres = fscanf(m_File, "%u ", &tmp);
      if (!fres)
        printf("Error open %s.\n", file);
      if (tmp == 9)
        tmp = 0;
      out[ip * M + j] |= tmp << (2 * ipp);
    }
  }
  fclose(m_File);
}


x86 assembly (clang, -O0):
<load_char_optim2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe97(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    118d <load_char_optim2+0x4d>
mov    -0x8(%rbp),%rsi
lea    0xe7a(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1257 <load_char_optim2+0x117>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1244 <load_char_optim2+0x104>
mov    -0x1c(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,-0x34(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe39(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   1050 <fscanf@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jne    1200 <load_char_optim2+0xc0>
mov    -0x8(%rbp),%rsi
lea    0xe1c(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x9,-0x2c(%rbp)
jne    1211 <load_char_optim2+0xd1>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%esi
mov    -0x34(%rbp),%ecx
shl    $0x1,%ecx
shl    %cl,%esi
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%ecx
imul   -0x10(%rbp),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%edx
or     %esi,%edx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11a7 <load_char_optim2+0x67>
jmp    1249 <load_char_optim2+0x109>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1194 <load_char_optim2+0x54>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_char_optim2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,0x20(%rsp)
mov    %edx,(%rsp)
mov    %esi,%ebx
lea    0xea1(%rip),%rsi
mov    %rdi,0x18(%rsp)
call   1060 <fopen@plt>
mov    %rax,%rbp
test   %rax,%rax
je     117a <load_char_optim2+0x3a>
test   %ebx,%ebx
jg     1193 <load_char_optim2+0x53>
jmp    123f <load_char_optim2+0xff>
lea    0xe81(%rip),%rdi
mov    0x18(%rsp),%rsi
call   1040 <printf@plt>
test   %ebx,%ebx
jle    123f <load_char_optim2+0xff>
mov    (%rsp),%r15d
xor    %eax,%eax
mov    %rax,0x8(%rsp)
lea    0x4(%rsp),%r14
mov    %ebx,0x14(%rsp)
jmp    11c5 <load_char_optim2+0x85>
nopl   0x0(%rax)
mov    0x8(%rsp),%rax
add    $0x1,%eax
mov    0x14(%rsp),%ebx
mov    %rax,0x8(%rsp)
cmp    %ebx,%eax
je     123f <load_char_optim2+0xff>
cmpl   $0x0,(%rsp)
jle    11b0 <load_char_optim2+0x70>
mov    0x8(%rsp),%rcx
mov    %ecx,%eax
shr    $0x2,%eax
imul   (%rsp),%eax
movslq %eax,%r13
add    0x20(%rsp),%r13
lea    (%rcx,%rcx,1),%r12d
and    $0x6,%r12d
xor    %ebx,%ebx
jmp    1203 <load_char_optim2+0xc3>
nopl   (%rax)
mov    %r12d,%ecx
shl    %cl,%eax
or     %al,0x0(%r13,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r15
je     11b0 <load_char_optim2+0x70>
mov    %rbp,%rdi
lea    0xe06(%rip),%rsi
mov    %r14,%rdx
call   1050 <fscanf@plt>
test   %eax,%eax
jne    122a <load_char_optim2+0xea>
lea    0xdf7(%rip),%rdi
mov    0x18(%rsp),%rsi
call   1040 <printf@plt>
mov    0x4(%rsp),%eax
cmp    $0x9,%eax
jne    11f0 <load_char_optim2+0xb0>
movl   $0x0,0x4(%rsp)
xor    %eax,%eax
jmp    11f0 <load_char_optim2+0xb0>
mov    %rbp,%rdi
call   1030 <fclose@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [17 x i8] c"Error: open %s.\0A\00"
@.str.2 = [4 x i8] c"%u \00"
@.str.3 = [16 x i8] c"Error open %s.\0A\00"
define void @load_char_optim2(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
store i32* null, i32** %11
%16 = load i8*, i8** %5
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %11
%18 = load i32*, i32** %11
%19 = icmp ne i32* %18, null
br i1 %19, label %23, label %20
20: ; preds = %4
%21 = load i8*, i8** %5
%22 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %20, %4
store i32 0, i32* %9
br label %24
24: ; preds = %70, %23
%25 = load i32, i32* %9
%26 = load i32, i32* %6
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %73
28: ; preds = %24
store i32 0, i32* %10
br label %29
29: ; preds = %66, %28
%30 = load i32, i32* %10
%31 = load i32, i32* %7
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %69
33: ; preds = %29
%34 = load i32, i32* %9
%35 = sdiv i32 %34, 4
store i32 %35, i32* %13
%36 = load i32, i32* %9
%37 = srem i32 %36, 4
store i32 %37, i32* %14
%38 = load i32*, i32** %11
%39 = call i32 @fscanf(i32* %38, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %12)
store i32 %39, i32* %15
%40 = load i32, i32* %15
%41 = icmp ne i32 %40, 0
br i1 %41, label %45, label %42
42: ; preds = %33
%43 = load i8*, i8** %5
%44 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %43)
br label %45
45: ; preds = %42, %33
%46 = load i32, i32* %12
%47 = icmp eq i32 %46, 9
br i1 %47, label %48, label %49
48: ; preds = %45
store i32 0, i32* %12
br label %49
49: ; preds = %48, %45
%50 = load i32, i32* %12
%51 = load i32, i32* %14
%52 = mul nsw i32 2, %51
%53 = shl i32 %50, %52
%54 = load i8*, i8** %8
%55 = load i32, i32* %13
%56 = load i32, i32* %7
%57 = mul nsw i32 %55, %56
%58 = load i32, i32* %10
%59 = add nsw i32 %57, %58
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %54, i64 %60
%62 = load i8, i8* %61
%63 = zext i8 %62 to i32
%64 = or i32 %63, %53
%65 = trunc i32 %64 to i8
store i8 %65, i8* %61
br label %66
66: ; preds = %49
%67 = load i32, i32* %10
%68 = add nsw i32 %67, 1
store i32 %68, i32* %10
br label %29
69: ; preds = %29
br label %70
70: ; preds = %69
%71 = load i32, i32* %9
%72 = add nsw i32 %71, 1
store i32 %72, i32* %9
br label %24
73: ; preds = %24
%74 = load i32*, i32** %11
%75 = call i32 @fclose(i32* %74)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [17 x i8] c"Error: open %s.\0A\00"
@.str.2 = [4 x i8] c"%u \00"
@.str.3 = [16 x i8] c"Error open %s.\0A\00"
define void @load_char_optim2(i8* %0, i32 %1, i32 %2, i8* nocapture %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %11
11: ; preds = %9, %4
%12 = icmp sgt i32 %1, 0
br i1 %12, label %13, label %47
13: ; preds = %11
%14 = icmp sgt i32 %2, 0
%15 = zext i32 %2 to i64
br label %16
16: ; preds = %13, %44
%17 = phi i32 [ 0, %13 ], [ %45, %44 ]
br i1 %14, label %18, label %44
18: ; preds = %16
%19 = lshr i32 %17, 2
%20 = shl nuw i32 %17, 1
%21 = and i32 %20, 6
%22 = mul nsw i32 %19, %2
%23 = sext i32 %22 to i64
br label %24
24: ; preds = %18, %34
%25 = phi i64 [ 0, %18 ], [ %42, %34 ]
%26 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %30
30: ; preds = %28, %24
%31 = load i32, i32* %5
%32 = icmp eq i32 %31, 9
br i1 %32, label %33, label %34
33: ; preds = %30
store i32 0, i32* %5
br label %34
34: ; preds = %33, %30
%35 = phi i32 [ 0, %33 ], [ %31, %30 ]
%36 = shl i32 %35, %21
%37 = add nsw i64 %25, %23
%38 = getelementptr inbounds i8, i8* %3, i64 %37
%39 = load i8, i8* %38
%40 = trunc i32 %36 to i8
%41 = or i8 %39, %40
store i8 %41, i8* %38
%42 = add nuw nsw i64 %25, 1
%43 = icmp eq i64 %42, %15
br i1 %43, label %44, label %24
44: ; preds = %34, %16
%45 = add nuw nsw i32 %17, 1
%46 = icmp eq i32 %45, %1
br i1 %46, label %47, label %16
47: ; preds = %44, %11
%48 = call i32 @fclose(i32* %7)
ret void
}