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


x86 assembly (clang, -O0):
<load_char_optim>:
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    1189 <load_char_optim+0x49>
lea    0xe7e(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    123c <load_char_optim+0xfc>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1229 <load_char_optim+0xe9>
mov    -0x1c(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,-0x34(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe3f(%rip),%rsi
lea    -0x2d(%rbp),%rdx
lea    -0x2e(%rbp),%rcx
call   1050 <fscanf@plt>
movsbl -0x2d(%rbp),%eax
sub    $0x30,%eax
movsbl -0x2e(%rbp),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%esi
mov    -0x38(%rbp),%ecx
shl    $0x1,%ecx
shl    %cl,%esi
mov    -0x18(%rbp),%rax
mov    -0x34(%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    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a3 <load_char_optim+0x63>
jmp    122e <load_char_optim+0xee>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1190 <load_char_optim+0x50>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_char_optim>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%rbx
mov    %edx,%ebp
mov    %esi,0x10(%rsp)
lea    0xea2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,0x18(%rsp)
test   %rax,%rax
je     1176 <load_char_optim+0x36>
test   %ebp,%ebp
jg     118a <load_char_optim+0x4a>
jmp    122e <load_char_optim+0xee>
lea    0xe8b(%rip),%rdi
call   1030 <puts@plt>
test   %ebp,%ebp
jle    122e <load_char_optim+0xee>
xor    %edi,%edi
lea    0xe6f(%rip),%rsi
lea    0xe(%rsp),%rdx
lea    0xf(%rsp),%r13
mov    %rbx,0x20(%rsp)
mov    0x20(%rsp),%rbx
jmp    11b7 <load_char_optim+0x77>
nopl   0x0(%rax)
add    $0x1,%edi
cmp    %ebp,%edi
je     122e <load_char_optim+0xee>
cmpl   $0x0,0x10(%rsp)
jle    11b0 <load_char_optim+0x70>
xor    %r12d,%r12d
xor    %r15d,%r15d
mov    %edi,0x14(%rsp)
nopl   0x0(%rax,%rax,1)
mov    %r15d,%r14d
shr    $0x2,%r14d
mov    0x18(%rsp),%rdi
mov    %r13,%rcx
call   1050 <fscanf@plt>
mov    0x14(%rsp),%edi
mov    0x10(%rsp),%r8d
movzbl 0xe(%rsp),%eax
movzbl 0xf(%rsp),%ecx
add    %ecx,%eax
add    $0xa0,%eax
mov    %r12d,%ecx
and    $0x6,%cl
shl    %cl,%eax
imul   %ebp,%r14d
add    %edi,%r14d
movslq %r14d,%rcx
or     %al,(%rbx,%rcx,1)
lea    0xe(%rsp),%rdx
lea    0xde3(%rip),%rsi
add    $0x1,%r15d
add    $0x2,%r12d
cmp    %r15d,%r8d
jne    11d0 <load_char_optim+0x90>
jmp    11b0 <load_char_optim+0x70>
mov    0x18(%rsp),%rdi
call   1040 <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 = [19 x i8] c"Error: open prout\0A\00"
@.str.2 = [6 x i8] c"%c%c \00"
define void @load_char_optim(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 i8
%14 = alloca i8
%15 = alloca i32
%16 = 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
%17 = load i8*, i8** %5
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %11
%19 = load i32*, i32** %11
%20 = icmp ne i32* %19, null
br i1 %20, label %23, label %21
21: ; preds = %4
%22 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %4
store i32 0, i32* %10
br label %24
24: ; preds = %67, %23
%25 = load i32, i32* %10
%26 = load i32, i32* %7
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %70
28: ; preds = %24
store i32 0, i32* %9
br label %29
29: ; preds = %63, %28
%30 = load i32, i32* %9
%31 = load i32, i32* %6
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %66
33: ; preds = %29
%34 = load i32, i32* %9
%35 = sdiv i32 %34, 4
store i32 %35, i32* %15
%36 = load i32, i32* %9
%37 = srem i32 %36, 4
store i32 %37, i32* %16
%38 = load i32*, i32** %11
%39 = call i32 @fscanf(i32* %38, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %13, i8* %14)
%40 = load i8, i8* %13
%41 = sext i8 %40 to i32
%42 = sub nsw i32 %41, 48
%43 = load i8, i8* %14
%44 = sext i8 %43 to i32
%45 = sub nsw i32 %44, 48
%46 = add i32 %42, %45
store i32 %46, i32* %12
%47 = load i32, i32* %12
%48 = load i32, i32* %16
%49 = mul nsw i32 2, %48
%50 = shl i32 %47, %49
%51 = load i8*, i8** %8
%52 = load i32, i32* %15
%53 = load i32, i32* %7
%54 = mul nsw i32 %52, %53
%55 = load i32, i32* %10
%56 = add nsw i32 %54, %55
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %51, i64 %57
%59 = load i8, i8* %58
%60 = zext i8 %59 to i32
%61 = or i32 %60, %50
%62 = trunc i32 %61 to i8
store i8 %62, i8* %58
br label %63
63: ; preds = %33
%64 = load i32, i32* %9
%65 = add nsw i32 %64, 1
store i32 %65, i32* %9
br label %29
66: ; preds = %29
br label %67
67: ; preds = %66
%68 = load i32, i32* %10
%69 = add nsw i32 %68, 1
store i32 %69, i32* %10
br label %24
70: ; preds = %24
%71 = load i32*, i32** %11
%72 = call i32 @fclose(i32* %71)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"%c%c \00"
@str = [18 x i8] c"Error: open prout\00"
define void @load_char_optim(i8* nocapture %0, i32 %1, i32 %2, i8* nocapture %3) {
%5 = alloca i8
%6 = alloca 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 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %11
11: ; preds = %9, %4
%12 = icmp sgt i32 %2, 0
br i1 %12, label %13, label %42
13: ; preds = %11
%14 = icmp sgt i32 %1, 0
br label %15
15: ; preds = %13, %39
%16 = phi i32 [ 0, %13 ], [ %40, %39 ]
br i1 %14, label %17, label %39
17: ; preds = %15, %17
%18 = phi i32 [ %37, %17 ], [ 0, %15 ]
%19 = lshr i32 %18, 2
%20 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %5, i8* %6)
%21 = load i8, i8* %5
%22 = zext i8 %21 to i32
%23 = load i8, i8* %6
%24 = zext i8 %23 to i32
%25 = add nuw nsw i32 %22, 160
%26 = add nuw nsw i32 %25, %24
%27 = shl nuw i32 %18, 1
%28 = and i32 %27, 6
%29 = shl nuw nsw i32 %26, %28
%30 = mul nsw i32 %19, %2
%31 = add nsw i32 %30, %16
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %3, i64 %32
%34 = load i8, i8* %33
%35 = trunc i32 %29 to i8
%36 = or i8 %34, %35
store i8 %36, i8* %33
%37 = add nuw nsw i32 %18, 1
%38 = icmp eq i32 %37, %1
br i1 %38, label %39, label %17
39: ; preds = %17, %15
%40 = add nuw nsw i32 %16, 1
%41 = icmp eq i32 %40, %2
br i1 %41, label %42, label %15
42: ; preds = %39, %11
%43 = call i32 @fclose(i32* %7)
ret void
}