#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*/ close(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *, ...);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int);
int /*<<< orphan*/ write(int, char *, int);
void streamFile(char *name, int *descriptor) {
  char buffer[256];
  int lignes, colonnes, magic, i = 0;
  char c;
  close(descriptor[0]);
  FILE *fichier = NULL;
  fichier = fopen(name, "r+");
  fgetc(fichier);
  fscanf(fichier, "%d", &magic);
  fscanf(fichier, "%d %d", &colonnes, &lignes);
  sprintf(buffer, "(%d,%d:%d)", magic, lignes, colonnes);
  write(descriptor[1], buffer, 256);
  do {
    c = fgetc(fichier);
    if (c == '#') {
      while (c != '\n')
        c = fgetc(fichier);
    }
    if (c == '0' || c == '1') {
      buffer[i] = c;
      i++;
    }
  } while (c != EOF);
  write(descriptor[1], buffer, 256);
  close(descriptor[1]);
  fclose(fichier);
}


x86 assembly (clang, -O0):
<streamFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x120(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1070 <close@plt>
movq   $0x0,-0x130(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x130(%rbp)
mov    -0x130(%rbp),%rdi
call   1060 <fgetc@plt>
mov    -0x130(%rbp),%rdi
lea    0xe32(%rip),%rsi
lea    -0x11c(%rbp),%rdx
mov    $0x0,%al
call   1050 <fscanf@plt>
mov    -0x130(%rbp),%rdi
lea    0xe13(%rip),%rsi
lea    -0x118(%rbp),%rdx
lea    -0x114(%rbp),%rcx
mov    $0x0,%al
call   1050 <fscanf@plt>
lea    -0x110(%rbp),%rdi
mov    -0x11c(%rbp),%edx
mov    -0x114(%rbp),%ecx
mov    -0x118(%rbp),%r8d
lea    0xde3(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1030 <write@plt>
mov    -0x130(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x121(%rbp)
movsbl -0x121(%rbp),%eax
cmp    $0x23,%eax
jne    1296 <streamFile+0x126>
jmp    126a <streamFile+0xfa>
movsbl -0x121(%rbp),%eax
cmp    $0xa,%eax
je     1291 <streamFile+0x121>
mov    -0x130(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x121(%rbp)
jmp    126a <streamFile+0xfa>
jmp    1296 <streamFile+0x126>
movsbl -0x121(%rbp),%eax
cmp    $0x30,%eax
je     12b6 <streamFile+0x146>
movsbl -0x121(%rbp),%eax
cmp    $0x31,%eax
jne    12d9 <streamFile+0x169>
mov    -0x121(%rbp),%cl
movslq -0x120(%rbp),%rax
mov    %cl,-0x110(%rbp,%rax,1)
mov    -0x120(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x120(%rbp)
jmp    12de <streamFile+0x16e>
movsbl -0x121(%rbp),%eax
mov    0x2cfc(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1243 <streamFile+0xd3>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1030 <write@plt>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1070 <close@plt>
mov    -0x130(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<streamFile>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rsi),%edi
call   1070 <close@plt>
lea    0xe6e(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <fgetc@plt>
lea    0xe5a(%rip),%rsi
xor    %r12d,%r12d
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <fscanf@plt>
lea    0xe3e(%rip),%rsi
lea    0x8(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <fscanf@plt>
mov    0x4(%rsp),%edx
mov    0xc(%rsp),%ecx
mov    0x8(%rsp),%r8d
lea    0xe1c(%rip),%rsi
lea    0x10(%rsp),%r15
mov    %r15,%rdi
call   1090 <sprintf@plt>
mov    0x4(%r14),%edi
mov    %r15,%rsi
mov    $0x100,%edx
call   1030 <write@plt>
mov    0x2dd6(%rip),%r15
jmp    1225 <streamFile+0xb5>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    (%r15),%al
je     1268 <streamFile+0xf8>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    $0x23,%al
jne    1250 <streamFile+0xe0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    $0xa,%al
jne    1240 <streamFile+0xd0>
mov    $0xa,%al
jmp    1220 <streamFile+0xb0>
mov    %eax,%ecx
and    $0xfe,%cl
cmp    $0x30,%cl
jne    1220 <streamFile+0xb0>
movslq %r12d,%r12
mov    %al,0x10(%rsp,%r12,1)
add    $0x1,%r12d
jmp    1220 <streamFile+0xb0>
mov    0x4(%r14),%edi
lea    0x10(%rsp),%rsi
mov    $0x100,%edx
call   1030 <write@plt>
mov    0x4(%r14),%edi
call   1070 <close@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"r+\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [6 x i8] c"%d %d\00"
@.str.3 = [11 x i8] c"(%d,%d:%d)\00"
@EOF = global i8 0
define void @streamFile(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [256 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
%11 = alloca i32*
store i8* %0, i8** %3
store i32* %1, i32** %4
store i32 0, i32* %9
%12 = load i32*, i32** %4
%13 = getelementptr inbounds i32, i32* %12, i64 0
%14 = load i32, i32* %13
%15 = call i32 @close(i32 %14)
store i32* null, i32** %11
%16 = load i8*, i8** %3
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %11
%18 = load i32*, i32** %11
%19 = call signext i8 @fgetc(i32* %18)
%20 = load i32*, i32** %11
%21 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %8)
%22 = load i32*, i32** %11
%23 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %7, i32* %6)
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%25 = load i32, i32* %8
%26 = load i32, i32* %6
%27 = load i32, i32* %7
%28 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %25, i32 %26, i32 %27)
%29 = load i32*, i32** %4
%30 = getelementptr inbounds i32, i32* %29, i64 1
%31 = load i32, i32* %30
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%33 = call i32 @write(i32 %31, i8* %32, i32 256)
br label %34
34: ; preds = %65, %2
%35 = load i32*, i32** %11
%36 = call signext i8 @fgetc(i32* %35)
store i8 %36, i8* %10
%37 = load i8, i8* %10
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 35
br i1 %39, label %40, label %49
40: ; preds = %34
br label %41
41: ; preds = %45, %40
%42 = load i8, i8* %10
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %43, 10
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = load i32*, i32** %11
%47 = call signext i8 @fgetc(i32* %46)
store i8 %47, i8* %10
br label %41
48: ; preds = %41
br label %49
49: ; preds = %48, %34
%50 = load i8, i8* %10
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 48
br i1 %52, label %57, label %53
53: ; preds = %49
%54 = load i8, i8* %10
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 49
br i1 %56, label %57, label %64
57: ; preds = %53, %49
%58 = load i8, i8* %10
%59 = load i32, i32* %9
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %60
store i8 %58, i8* %61
%62 = load i32, i32* %9
%63 = add nsw i32 %62, 1
store i32 %63, i32* %9
br label %64
64: ; preds = %57, %53
br label %65
65: ; preds = %64
%66 = load i8, i8* %10
%67 = sext i8 %66 to i32
%68 = load i8, i8* @EOF
%69 = sext i8 %68 to i32
%70 = icmp ne i32 %67, %69
br i1 %70, label %34, label %71
71: ; preds = %65
%72 = load i32*, i32** %4
%73 = getelementptr inbounds i32, i32* %72, i64 1
%74 = load i32, i32* %73
%75 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%76 = call i32 @write(i32 %74, i8* %75, i32 256)
%77 = load i32*, i32** %4
%78 = getelementptr inbounds i32, i32* %77, i64 1
%79 = load i32, i32* %78
%80 = call i32 @close(i32 %79)
%81 = load i32*, i32** %11
%82 = call i32 @fclose(i32* %81)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"r+\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [6 x i8] c"%d %d\00"
@.str.3 = [11 x i8] c"(%d,%d:%d)\00"
@EOF = global i8 0
define void @streamFile(i8* nocapture %0, i32* nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = load i32, i32* %1
%12 = tail call i32 @close(i32 %11)
%13 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%14 = tail call signext i8 @fgetc(i32* %13)
%15 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%16 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %5, i32* %4)
%17 = load i32, i32* %6
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %17, i32 %18, i32 %19)
%21 = getelementptr inbounds i32, i32* %1, i64 1
%22 = load i32, i32* %21
%23 = call i32 @write(i32 %22, i8* %7, i32 256)
br label %24
24: ; preds = %38, %2
%25 = phi i32 [ 0, %2 ], [ %40, %38 ]
%26 = call signext i8 @fgetc(i32* %13)
%27 = icmp eq i8 %26, 35
br i1 %27, label %28, label %31
28: ; preds = %24, %28
%29 = call signext i8 @fgetc(i32* %13)
%30 = icmp eq i8 %29, 10
br i1 %30, label %38, label %28
31: ; preds = %24
%32 = and i8 %26, -2
%33 = icmp eq i8 %32, 48
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = sext i32 %25 to i64
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %35
store i8 %26, i8* %36
%37 = add nsw i32 %25, 1
br label %38
38: ; preds = %28, %34, %31
%39 = phi i8 [ %26, %34 ], [ %26, %31 ], [ 10, %28 ]
%40 = phi i32 [ %37, %34 ], [ %25, %31 ], [ %25, %28 ]
%41 = load i8, i8* @EOF
%42 = icmp eq i8 %39, %41
br i1 %42, label %43, label %24
43: ; preds = %38
%44 = load i32, i32* %21
%45 = call i32 @write(i32 %44, i8* %7, i32 256)
%46 = load i32, i32* %21
%47 = call i32 @close(i32 %46)
%48 = call i32 @fclose(i32* %13)
ret void
}