#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 */

/* Variables and functions */
scalar_t__ i_empty();
void *i_read();
int /*<<< orphan*/ my_printf(char *, unsigned int);
int /*<<< orphan*/ puts(char *);
void LoadImage(unsigned int *col_nb, unsigned int *row_nb,
               unsigned int *pixel_nb, unsigned char *data) {
  int i;
  *col_nb = i_read();
  my_printf("nbre de colonnes dans l'image: ", *col_nb);
  *row_nb = i_read();
  my_printf("nbre de lignes dans l'image: ", *row_nb);
  *pixel_nb = (*col_nb) * (*row_nb);
  my_printf("nbre de pixel dans l'image: ", *pixel_nb);
  if (*pixel_nb > 32768) {
    puts("WARNING :image trop volumineuse, taille max = 32768 octets");
  }
  i = 0;
  while (i_empty() == 0) {
    data[i] = i_read();
    i++;
  }
  puts("Lecture de la FIFO d'entree terminee\n");
}


x86 assembly (clang, -O0):
<LoadImage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    $0x0,%al
call   1060 <i_read@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    0xe8c(%rip),%rdi
call   1050 <my_printf@plt>
mov    $0x0,%al
call   1060 <i_read@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe8b(%rip),%rdi
call   1050 <my_printf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
imul   (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    0xe84(%rip),%rdi
call   1050 <my_printf@plt>
mov    -0x18(%rbp),%rax
cmpl   $0x8000,(%rax)
jbe    11db <LoadImage+0x9b>
lea    0xe85(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x24(%rbp)
mov    $0x0,%al
call   1040 <i_empty@plt>
cmp    $0x0,%rax
jne    1215 <LoadImage+0xd5>
mov    $0x0,%al
call   1060 <i_read@plt>
mov    %al,%dl
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11e2 <LoadImage+0xa2>
lea    0xe7a(%rip),%rdi
call   1030 <puts@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LoadImage>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
xor    %eax,%eax
call   1060 <i_read@plt>
mov    %eax,(%r15)
lea    0xe9b(%rip),%rdi
mov    %eax,%esi
call   1050 <my_printf@plt>
xor    %eax,%eax
call   1060 <i_read@plt>
mov    %eax,(%r12)
lea    0xea2(%rip),%rdi
mov    %eax,%esi
call   1050 <my_printf@plt>
mov    (%r12),%esi
imul   (%r15),%esi
mov    %esi,(%r14)
lea    0xea7(%rip),%rdi
call   1050 <my_printf@plt>
cmpl   $0x8001,(%r14)
jb     11b1 <LoadImage+0x71>
lea    0xeaf(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <i_empty@plt>
test   %rax,%rax
jne    11d9 <LoadImage+0x99>
nopl   (%rax)
xor    %eax,%eax
call   1060 <i_read@plt>
mov    %al,(%rbx)
xor    %eax,%eax
call   1040 <i_empty@plt>
add    $0x1,%rbx
test   %rax,%rax
je     11c0 <LoadImage+0x80>
lea    0xeb6(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"nbre de colonnes dans l'image: \00"
@.str.1 = [30 x i8] c"nbre de lignes dans l'image: \00"
@.str.2 = [29 x i8] c"nbre de pixel dans l'image: \00"
@.str.3 = [59 x i8] c"WARNING :image trop volumineuse, taille max = 32768 octets\00"
@.str.4 = [38 x i8] c"Lecture de la FIFO d'entree terminee\0A\00"
define void @LoadImage(i32* %0, i32* %1, i32* %2, i8* %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i8* %3, i8** %8
%10 = call i8* (...) @i_read()
%11 = ptrtoint i8* %10 to i32
%12 = load i32*, i32** %5
store i32 %11, i32* %12
%13 = load i32*, i32** %5
%14 = load i32, i32* %13
%15 = call i32 @my_printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = call i8* (...) @i_read()
%17 = ptrtoint i8* %16 to i32
%18 = load i32*, i32** %6
store i32 %17, i32* %18
%19 = load i32*, i32** %6
%20 = load i32, i32* %19
%21 = call i32 @my_printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = load i32*, i32** %5
%23 = load i32, i32* %22
%24 = load i32*, i32** %6
%25 = load i32, i32* %24
%26 = mul i32 %23, %25
%27 = load i32*, i32** %7
store i32 %26, i32* %27
%28 = load i32*, i32** %7
%29 = load i32, i32* %28
%30 = call i32 @my_printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = load i32*, i32** %7
%32 = load i32, i32* %31
%33 = icmp ugt i32 %32, 32768
br i1 %33, label %34, label %36
34: ; preds = %4
%35 = call i32 @puts(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %34, %4
store i32 0, i32* %9
br label %37
37: ; preds = %40, %36
%38 = call i64 (...) @i_empty()
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %49
40: ; preds = %37
%41 = call i8* (...) @i_read()
%42 = ptrtoint i8* %41 to i8
%43 = load i8*, i8** %8
%44 = load i32, i32* %9
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
store i8 %42, i8* %46
%47 = load i32, i32* %9
%48 = add nsw i32 %47, 1
store i32 %48, i32* %9
br label %37
49: ; preds = %37
%50 = call i32 @puts(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [32 x i8] c"nbre de colonnes dans l'image: \00"
@.str.1 = [30 x i8] c"nbre de lignes dans l'image: \00"
@.str.2 = [29 x i8] c"nbre de pixel dans l'image: \00"
@.str.3 = [59 x i8] c"WARNING :image trop volumineuse, taille max = 32768 octets\00"
@.str.4 = [38 x i8] c"Lecture de la FIFO d'entree terminee\0A\00"
define void @LoadImage(i32* nocapture %0, i32* nocapture %1, i32* nocapture %2, i8* nocapture writeonly %3) {
%5 = tail call i8* (...) @i_read()
%6 = ptrtoint i8* %5 to i64
%7 = trunc i64 %6 to i32
store i32 %7, i32* %0
%8 = tail call i32 @my_printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = tail call i8* (...) @i_read()
%10 = ptrtoint i8* %9 to i64
%11 = trunc i64 %10 to i32
store i32 %11, i32* %1
%12 = tail call i32 @my_printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = load i32, i32* %0
%14 = load i32, i32* %1
%15 = mul i32 %14, %13
store i32 %15, i32* %2
%16 = tail call i32 @my_printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %2
%18 = icmp ugt i32 %17, 32768
br i1 %18, label %19, label %21
19: ; preds = %4
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0))
br label %21
21: ; preds = %19, %4
%22 = tail call i64 (...) @i_empty()
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %33
24: ; preds = %21, %24
%25 = phi i64 [ %30, %24 ], [ 0, %21 ]
%26 = tail call i8* (...) @i_read()
%27 = ptrtoint i8* %26 to i64
%28 = trunc i64 %27 to i8
%29 = getelementptr inbounds i8, i8* %3, i64 %25
store i8 %28, i8* %29
%30 = add nuw i64 %25, 1
%31 = tail call i64 (...) @i_empty()
%32 = icmp eq i64 %31, 0
br i1 %32, label %24, label %33
33: ; preds = %24, %21
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
ret void
}