#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 */
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 = (*(volatile unsigned int *)(0x30000080));
  my_printf("nbre de colonnes dans l'image: ", *col_nb);
  *row_nb = (*(volatile unsigned int *)(0x30000080));
  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 ((*(volatile unsigned int *)(0x30000000)) == 0) {
    data[i] = (*(volatile unsigned int *)(0x30000080));
    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    $0x30000080,%eax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    0xeae(%rip),%rdi
call   1040 <my_printf@plt>
mov    $0x30000080,%eax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xeaf(%rip),%rdi
call   1040 <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    0xea8(%rip),%rdi
call   1040 <my_printf@plt>
mov    -0x18(%rbp),%rax
cmpl   $0x8000,(%rax)
jbe    11b7 <LoadImage+0x97>
lea    0xea9(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x24(%rbp)
mov    $0x30000000,%eax
mov    (%rax),%eax
cmp    $0x0,%eax
jne    11f0 <LoadImage+0xd0>
mov    $0x30000080,%eax
mov    (%rax),%eax
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    11be <LoadImage+0x9e>
lea    0xe9f(%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,%r15
mov    %rdi,%r12
mov    0x30000080,%esi
mov    %esi,(%rdi)
lea    0xebc(%rip),%rdi
call   1040 <my_printf@plt>
mov    0x30000080,%esi
mov    %esi,(%r15)
lea    0xec6(%rip),%rdi
call   1040 <my_printf@plt>
mov    (%r15),%esi
imul   (%r12),%esi
mov    %esi,(%r14)
lea    0xecd(%rip),%rdi
call   1040 <my_printf@plt>
cmpl   $0x8001,(%r14)
jb     119d <LoadImage+0x7d>
lea    0xed5(%rip),%rdi
call   1030 <puts@plt>
jmp    119d <LoadImage+0x7d>
nopl   (%rax)
mov    0x30000080,%eax
mov    %al,(%rbx)
add    $0x1,%rbx
cmpl   $0x0,0x30000000
je     1190 <LoadImage+0x70>
lea    0xee8(%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 = load volatile i32, i32* inttoptr (i64 805306496 to i32*)
%11 = load i32*, i32** %5
store i32 %10, i32* %11
%12 = load i32*, i32** %5
%13 = load i32, i32* %12
%14 = call i32 @my_printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load volatile i32, i32* inttoptr (i64 805306496 to i32*)
%16 = load i32*, i32** %6
store i32 %15, i32* %16
%17 = load i32*, i32** %6
%18 = load i32, i32* %17
%19 = call i32 @my_printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = load i32*, i32** %5
%21 = load i32, i32* %20
%22 = load i32*, i32** %6
%23 = load i32, i32* %22
%24 = mul i32 %21, %23
%25 = load i32*, i32** %7
store i32 %24, i32* %25
%26 = load i32*, i32** %7
%27 = load i32, i32* %26
%28 = call i32 @my_printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = load i32*, i32** %7
%30 = load i32, i32* %29
%31 = icmp ugt i32 %30, 32768
br i1 %31, label %32, label %34
32: ; preds = %4
%33 = call i32 @puts(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %32, %4
store i32 0, i32* %9
br label %35
35: ; preds = %38, %34
%36 = load volatile i32, i32* inttoptr (i64 805306368 to i32*)
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %47
38: ; preds = %35
%39 = load volatile i32, i32* inttoptr (i64 805306496 to i32*)
%40 = trunc i32 %39 to i8
%41 = load i8*, i8** %8
%42 = load i32, i32* %9
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
store i8 %40, i8* %44
%45 = load i32, i32* %9
%46 = add nsw i32 %45, 1
store i32 %46, i32* %9
br label %35
47: ; preds = %35
%48 = 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 = load volatile i32, i32* inttoptr (i64 805306496 to i32*)
store i32 %5, i32* %0
%6 = tail call i32 @my_printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = load volatile i32, i32* inttoptr (i64 805306496 to i32*)
store i32 %7, i32* %1
%8 = tail call i32 @my_printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = load i32, i32* %0
%10 = load i32, i32* %1
%11 = mul i32 %10, %9
store i32 %11, i32* %2
%12 = tail call i32 @my_printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = load i32, i32* %2
%14 = icmp ugt i32 %13, 32768
br i1 %14, label %15, label %17
15: ; preds = %4
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0))
br label %17
17: ; preds = %15, %4
%18 = load volatile i32, i32* inttoptr (i64 805306368 to i32*)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %17, %20
%21 = phi i64 [ %25, %20 ], [ 0, %17 ]
%22 = load volatile i32, i32* inttoptr (i64 805306496 to i32*)
%23 = trunc i32 %22 to i8
%24 = getelementptr inbounds i8, i8* %3, i64 %21
store i8 %23, i8* %24
%25 = add nuw i64 %21, 1
%26 = load volatile i32, i32* inttoptr (i64 805306368 to i32*)
%27 = icmp eq i32 %26, 0
br i1 %27, label %20, label %28
28: ; preds = %20, %17
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
ret void
}