#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*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
void writePgmPictureBinary(char *fileNameBase, char *nameFile, char *mode,
                           int **imageMatrix, char *magicNumber, int idim,
                           int jdim, int dynamic) {
  int row = 0;
  int column = 0;
  unsigned char line[jdim];
  FILE *file;
  file = fopen(nameFile, mode);
  if (file != NULL) {
    fprintf(file, "%s@n", magicNumber);
    fprintf(file, "# This a binary image from %s@n", fileNameBase);
    fprintf(
        file,
        "# It is automatic created by Delmas Pierre Binarisation Program@n");
    fprintf(file, "%d %d@n", idim, jdim);
    fprintf(file, "%d@n", dynamic);
    for (row = 0; row < idim; row++) {
      for (column = 0; column < jdim; column++) {
        line[column] = (unsigned char)imageMatrix[row][column];
      }
      fwrite(line, sizeof(unsigned char), jdim, file);
    }
    fclose(file);
  }
}


x86 assembly (clang, -O0):
<writePgmPictureBinary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    0x10(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
je     12a1 <writePgmPictureBinary+0x161>
mov    -0x50(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xe56(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe25(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x50(%rbp),%rdi
lea    0xe33(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x50(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    0x10(%rbp),%ecx
lea    0xe5d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x50(%rbp),%rdi
mov    0x18(%rbp),%edx
lea    0xe4b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1298 <writePgmPictureBinary+0x158>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    0x10(%rbp),%eax
jge    1275 <writePgmPictureBinary+0x135>
mov    -0x58(%rbp),%rax
mov    -0x20(%rbp),%rcx
movslq -0x30(%rbp),%rdx
mov    (%rcx,%rdx,8),%rcx
movslq -0x34(%rbp),%rdx
mov    (%rcx,%rdx,4),%ecx
mov    %cl,%dl
movslq -0x34(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    123b <writePgmPictureBinary+0xfb>
mov    -0x58(%rbp),%rdi
mov    0x10(%rbp),%edx
mov    -0x50(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fwrite@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1228 <writePgmPictureBinary+0xe8>
mov    -0x50(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writePgmPictureBinary>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9d,%r14d
mov    %r8,%r13
mov    %rcx,-0x50(%rbp)
mov    %rdi,-0x30(%rbp)
mov    0x18(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x10(%rbp),%r15d
mov    %rsp,%rbx
lea    0xf(%r15),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsi,%rdi
mov    %rdx,%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     13a5 <writePgmPictureBinary+0x265>
mov    %rax,%r12
lea    0xe93(%rip),%rsi
mov    %rax,%rdi
mov    %r13,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xe64(%rip),%rsi
mov    %r12,%rdi
mov    -0x30(%rbp),%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xe6f(%rip),%rdi
mov    $0x41,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1060 <fwrite@plt>
lea    0xe98(%rip),%rsi
mov    %r12,%rdi
mov    %r14d,%edx
mov    %r15d,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xe84(%rip),%rsi
mov    %r12,%rdi
mov    -0x38(%rbp),%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
test   %r14d,%r14d
jle    138f <writePgmPictureBinary+0x24f>
mov    %r14d,%r13d
mov    %r15d,%eax
and    $0xfffffff8,%eax
mov    %rax,-0x38(%rbp)
add    $0xfffffffffffffff8,%rax
mov    %rax,-0x30(%rbp)
mov    %rax,%rcx
shr    $0x3,%rcx
add    $0x1,%rcx
mov    %rcx,%rax
mov    %rcx,-0x48(%rbp)
and    $0xfffffffffffffffe,%rcx
mov    %rcx,-0x40(%rbp)
xor    %r14d,%r14d
movdqa 0xdbf(%rip),%xmm2
jmp    1278 <writePgmPictureBinary+0x138>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %r12,%rcx
call   1060 <fwrite@plt>
movdqa 0xd95(%rip),%xmm2
add    $0x1,%r14
cmp    %r13,%r14
je     138f <writePgmPictureBinary+0x24f>
test   %r15d,%r15d
jle    1250 <writePgmPictureBinary+0x110>
mov    -0x50(%rbp),%rax
mov    (%rax,%r14,8),%rax
cmp    $0x8,%r15d
jae    12a0 <writePgmPictureBinary+0x160>
xor    %ecx,%ecx
jmp    1370 <writePgmPictureBinary+0x230>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmpq   $0x0,-0x30(%rbp)
je     1385 <writePgmPictureBinary+0x245>
mov    -0x40(%rbp),%rdx
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movdqu (%rax,%rcx,4),%xmm0
movdqu 0x10(%rax,%rcx,4),%xmm1
pand   %xmm2,%xmm0
packuswb %xmm0,%xmm0
packuswb %xmm0,%xmm0
pand   %xmm2,%xmm1
packuswb %xmm1,%xmm1
packuswb %xmm1,%xmm1
movd   %xmm0,(%rbx,%rcx,1)
movd   %xmm1,0x4(%rbx,%rcx,1)
movdqu 0x20(%rax,%rcx,4),%xmm0
movdqu 0x30(%rax,%rcx,4),%xmm1
pand   %xmm2,%xmm0
packuswb %xmm0,%xmm0
packuswb %xmm0,%xmm0
pand   %xmm2,%xmm1
packuswb %xmm1,%xmm1
packuswb %xmm1,%xmm1
movd   %xmm0,0x8(%rbx,%rcx,1)
movd   %xmm1,0xc(%rbx,%rcx,1)
add    $0x10,%rcx
add    $0xfffffffffffffffe,%rdx
jne    12c0 <writePgmPictureBinary+0x180>
testb  $0x1,-0x48(%rbp)
je     135c <writePgmPictureBinary+0x21c>
movdqu (%rax,%rcx,4),%xmm0
movdqu 0x10(%rax,%rcx,4),%xmm1
pand   %xmm2,%xmm0
packuswb %xmm0,%xmm0
packuswb %xmm0,%xmm0
pand   %xmm2,%xmm1
packuswb %xmm1,%xmm1
packuswb %xmm1,%xmm1
movd   %xmm0,(%rbx,%rcx,1)
movd   %xmm1,0x4(%rbx,%rcx,1)
mov    -0x38(%rbp),%rdx
mov    %rdx,%rcx
cmp    %r15,%rdx
je     1250 <writePgmPictureBinary+0x110>
nopl   0x0(%rax)
movzbl (%rax,%rcx,4),%edx
mov    %dl,(%rbx,%rcx,1)
add    $0x1,%rcx
cmp    %rcx,%r15
jne    1370 <writePgmPictureBinary+0x230>
jmp    1250 <writePgmPictureBinary+0x110>
xor    %ecx,%ecx
testb  $0x1,-0x48(%rbp)
jne    132e <writePgmPictureBinary+0x1ee>
jmp    135c <writePgmPictureBinary+0x21c>
mov    %r12,%rdi
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s@n\00"
@.str.1 = [32 x i8] c"# This a binary image from %s@n\00"
@.str.2 = [66 x i8] c"# It is automatic created by Delmas Pierre Binarisation Program@n\00"
@.str.3 = [8 x i8] c"%d %d@n\00"
@.str.4 = [5 x i8] c"%d@n\00"
define void @writePgmPictureBinary(i8* %0, i8* %1, i8* %2, i32** %3, i8* %4, i32 %5, i32 %6, i32 %7) {
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32**
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i8*
%20 = alloca i64
%21 = alloca i32*
store i8* %0, i8** %9
store i8* %1, i8** %10
store i8* %2, i8** %11
store i32** %3, i32*** %12
store i8* %4, i8** %13
store i32 %5, i32* %14
store i32 %6, i32* %15
store i32 %7, i32* %16
store i32 0, i32* %17
store i32 0, i32* %18
%22 = load i32, i32* %15
%23 = zext i32 %22 to i64
%24 = call i8* @llvm.stacksave()
store i8* %24, i8** %19
%25 = alloca i8, i64 %23
store i64 %23, i64* %20
%26 = load i8*, i8** %10
%27 = load i8*, i8** %11
%28 = call i32* @fopen(i8* %26, i8* %27)
store i32* %28, i32** %21
%29 = load i32*, i32** %21
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %83
31: ; preds = %8
%32 = load i32*, i32** %21
%33 = load i8*, i8** %13
%34 = call i32 (i32*, i8*, ...) @fprintf(i32* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %33)
%35 = load i32*, i32** %21
%36 = load i8*, i8** %9
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %35, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %36)
%38 = load i32*, i32** %21
%39 = call i32 (i32*, i8*, ...) @fprintf(i32* %38, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0))
%40 = load i32*, i32** %21
%41 = load i32, i32* %14
%42 = load i32, i32* %15
%43 = call i32 (i32*, i8*, ...) @fprintf(i32* %40, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %41, i32 %42)
%44 = load i32*, i32** %21
%45 = load i32, i32* %16
%46 = call i32 (i32*, i8*, ...) @fprintf(i32* %44, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %45)
store i32 0, i32* %17
br label %47
47: ; preds = %77, %31
%48 = load i32, i32* %17
%49 = load i32, i32* %14
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %80
51: ; preds = %47
store i32 0, i32* %18
br label %52
52: ; preds = %70, %51
%53 = load i32, i32* %18
%54 = load i32, i32* %15
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %73
56: ; preds = %52
%57 = load i32**, i32*** %12
%58 = load i32, i32* %17
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i32*, i32** %57, i64 %59
%61 = load i32*, i32** %60
%62 = load i32, i32* %18
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i32, i32* %61, i64 %63
%65 = load i32, i32* %64
%66 = trunc i32 %65 to i8
%67 = load i32, i32* %18
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %25, i64 %68
store i8 %66, i8* %69
br label %70
70: ; preds = %56
%71 = load i32, i32* %18
%72 = add nsw i32 %71, 1
store i32 %72, i32* %18
br label %52
73: ; preds = %52
%74 = load i32, i32* %15
%75 = load i32*, i32** %21
%76 = call i32 @fwrite(i8* %25, i32 1, i32 %74, i32* %75)
br label %77
77: ; preds = %73
%78 = load i32, i32* %17
%79 = add nsw i32 %78, 1
store i32 %79, i32* %17
br label %47
80: ; preds = %47
%81 = load i32*, i32** %21
%82 = call i32 @fclose(i32* %81)
br label %83
83: ; preds = %80, %8
%84 = load i8*, i8** %19
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s@n\00"
@.str.1 = [32 x i8] c"# This a binary image from %s@n\00"
@.str.2 = [66 x i8] c"# It is automatic created by Delmas Pierre Binarisation Program@n\00"
@.str.3 = [8 x i8] c"%d %d@n\00"
@.str.4 = [5 x i8] c"%d@n\00"
define void @writePgmPictureBinary(i8* %0, i8* nocapture %1, i8* nocapture %2, i32** nocapture %3, i8* %4, i32 %5, i32 %6, i32 %7) {
%9 = zext i32 %6 to i64
%10 = alloca i8, i64 %9
%11 = tail call i32* @fopen(i8* %1, i8* %2)
%12 = icmp eq i32* %11, null
br i1 %12, label %103, label %13
13: ; preds = %8
%14 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %4)
%15 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%16 = tail call i64 bitcast (i32 (i8*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0), i64 65, i64 1, i32* %11)
%17 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %5, i32 %6)
%18 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %7)
%19 = icmp sgt i32 %5, 0
br i1 %19, label %20, label %101
20: ; preds = %13
%21 = icmp sgt i32 %6, 0
%22 = zext i32 %5 to i64
%23 = and i64 %9, 4294967288
%24 = add nsw i64 %23, -8
%25 = lshr exact i64 %24, 3
%26 = add nuw nsw i64 %25, 1
%27 = icmp ult i32 %6, 8
%28 = and i64 %9, 4294967288
%29 = and i64 %26, 1
%30 = icmp eq i64 %24, 0
%31 = and i64 %26, 4611686018427387902
%32 = icmp eq i64 %29, 0
%33 = icmp eq i64 %28, %9
br label %34
34: ; preds = %20, %97
%35 = phi i64 [ 0, %20 ], [ %99, %97 ]
br i1 %21, label %36, label %97
36: ; preds = %34
%37 = getelementptr inbounds i32*, i32** %3, i64 %35
%38 = load i32*, i32** %37
br i1 %27, label %87, label %39
39: ; preds = %36
br i1 %30, label %71, label %40
40: ; preds = %39, %40
%41 = phi i64 [ %68, %40 ], [ 0, %39 ]
%42 = phi i64 [ %69, %40 ], [ 0, %39 ]
%43 = getelementptr inbounds i32, i32* %38, i64 %41
%44 = bitcast i32* %43 to <4 x i32>*
%45 = load <4 x i32>, <4 x i32>* %44
%46 = getelementptr inbounds i32, i32* %43, i64 4
%47 = bitcast i32* %46 to <4 x i32>*
%48 = load <4 x i32>, <4 x i32>* %47
%49 = trunc <4 x i32> %45 to <4 x i8>
%50 = trunc <4 x i32> %48 to <4 x i8>
%51 = getelementptr inbounds i8, i8* %10, i64 %41
%52 = bitcast i8* %51 to <4 x i8>*
store <4 x i8> %49, <4 x i8>* %52
%53 = getelementptr inbounds i8, i8* %51, i64 4
%54 = bitcast i8* %53 to <4 x i8>*
store <4 x i8> %50, <4 x i8>* %54
%55 = or i64 %41, 8
%56 = getelementptr inbounds i32, i32* %38, i64 %55
%57 = bitcast i32* %56 to <4 x i32>*
%58 = load <4 x i32>, <4 x i32>* %57
%59 = getelementptr inbounds i32, i32* %56, i64 4
%60 = bitcast i32* %59 to <4 x i32>*
%61 = load <4 x i32>, <4 x i32>* %60
%62 = trunc <4 x i32> %58 to <4 x i8>
%63 = trunc <4 x i32> %61 to <4 x i8>
%64 = getelementptr inbounds i8, i8* %10, i64 %55
%65 = bitcast i8* %64 to <4 x i8>*
store <4 x i8> %62, <4 x i8>* %65
%66 = getelementptr inbounds i8, i8* %64, i64 4
%67 = bitcast i8* %66 to <4 x i8>*
store <4 x i8> %63, <4 x i8>* %67
%68 = add nuw i64 %41, 16
%69 = add i64 %42, 2
%70 = icmp eq i64 %69, %31
br i1 %70, label %71, label %40
71: ; preds = %40, %39
%72 = phi i64 [ 0, %39 ], [ %68, %40 ]
br i1 %32, label %86, label %73
73: ; preds = %71
%74 = getelementptr inbounds i32, i32* %38, i64 %72
%75 = bitcast i32* %74 to <4 x i32>*
%76 = load <4 x i32>, <4 x i32>* %75
%77 = getelementptr inbounds i32, i32* %74, i64 4
%78 = bitcast i32* %77 to <4 x i32>*
%79 = load <4 x i32>, <4 x i32>* %78
%80 = trunc <4 x i32> %76 to <4 x i8>
%81 = trunc <4 x i32> %79 to <4 x i8>
%82 = getelementptr inbounds i8, i8* %10, i64 %72
%83 = bitcast i8* %82 to <4 x i8>*
store <4 x i8> %80, <4 x i8>* %83
%84 = getelementptr inbounds i8, i8* %82, i64 4
%85 = bitcast i8* %84 to <4 x i8>*
store <4 x i8> %81, <4 x i8>* %85
br label %86
86: ; preds = %71, %73
br i1 %33, label %97, label %87
87: ; preds = %36, %86
%88 = phi i64 [ 0, %36 ], [ %28, %86 ]
br label %89
89: ; preds = %87, %89
%90 = phi i64 [ %95, %89 ], [ %88, %87 ]
%91 = getelementptr inbounds i32, i32* %38, i64 %90
%92 = load i32, i32* %91
%93 = trunc i32 %92 to i8
%94 = getelementptr inbounds i8, i8* %10, i64 %90
store i8 %93, i8* %94
%95 = add nuw nsw i64 %90, 1
%96 = icmp eq i64 %95, %9
br i1 %96, label %97, label %89
97: ; preds = %89, %86, %34
%98 = call i32 @fwrite(i8* %10, i32 1, i32 %6, i32* %11)
%99 = add nuw nsw i64 %35, 1
%100 = icmp eq i64 %99, %22
br i1 %100, label %101, label %34
101: ; preds = %97, %13
%102 = tail call i32 @fclose(i32* %11)
br label %103
103: ; preds = %101, %8
ret void
}