#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ ignorer_commentaires(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
void lire_nb_lignes_colonnes_image_pgm(char nom_image[], int *nb_lignes,
                                       int *nb_colonnes) {
  FILE *f_image;
  int max_grey_val;
  if ((f_image = fopen(nom_image, "rb")) == NULL) {
    printf("\nPas d'acces en lecture sur l'image %s \n", nom_image);
    exit(EXIT_FAILURE);
  } else {
    fscanf(f_image, "P5 ");
    ignorer_commentaires(f_image);
    fscanf(f_image, "%d %d %d%*c", nb_colonnes, nb_lignes, &max_grey_val);
    fclose(f_image);
  }
}


x86 assembly (clang, -O0):
<lire_nb_lignes_colonnes_image_pgm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11b0 <lire_nb_lignes_colonnes_image_pgm+0x50>
mov    -0x8(%rbp),%rsi
lea    0xe66(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x20(%rbp),%rdi
lea    0xe71(%rip),%rsi
mov    $0x0,%al
call   1050 <fscanf@plt>
mov    -0x20(%rbp),%rdi
call   1060 <ignorer_commentaires@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe52(%rip),%rsi
lea    -0x24(%rbp),%r8
mov    $0x0,%al
call   1050 <fscanf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lire_nb_lignes_colonnes_image_pgm>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xe88(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ce <lire_nb_lignes_colonnes_image_pgm+0x6e>
mov    %rax,%rbx
lea    0xea0(%rip),%rsi
mov    %rax,%rdi
xor    %eax,%eax
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1060 <ignorer_commentaires@plt>
lea    0xe8b(%rip),%rsi
lea    0x4(%rsp),%r8
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe2e(%rip),%rdi
mov    %r12,%rsi
call   1040 <printf@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [41 x i8] c"\0APas d'acces en lecture sur l'image %s \0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [4 x i8] c"P5 \00"
@.str.3 = [12 x i8] c"%d %d %d%*c\00"
define void @lire_nb_lignes_colonnes_image_pgm(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %7
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %17
12: ; preds = %3
%13 = load i8*, i8** %4
%14 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %3
%18 = load i32*, i32** %7
%19 = call i32 (i32*, i8*, ...) @fscanf(i32* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32*, i32** %7
%21 = call i32 @ignorer_commentaires(i32* %20)
%22 = load i32*, i32** %7
%23 = load i32*, i32** %6
%24 = load i32*, i32** %5
%25 = call i32 (i32*, i8*, ...) @fscanf(i32* %22, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32* %23, i32* %24, i32* %8)
%26 = load i32*, i32** %7
%27 = call i32 @fclose(i32* %26)
br label %28
28: ; preds = %17
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [41 x i8] c"\0APas d'acces en lecture sur l'image %s \0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [4 x i8] c"P5 \00"
@.str.3 = [12 x i8] c"%d %d %d%*c\00"
define void @lire_nb_lignes_colonnes_image_pgm(i8* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %12
8: ; preds = %3
%9 = tail call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %3
%13 = tail call i32 (i32*, i8*, ...) @fscanf(i32* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%14 = tail call i32 @ignorer_commentaires(i32* %6)
%15 = call i32 (i32*, i8*, ...) @fscanf(i32* %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32* %2, i32* %1, i32* %4)
%16 = call i32 @fclose(i32* %6)
ret void
}