#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 */
scalar_t__ EOF;
int errno;
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  FILE *fichier;
  char buffer[50 + 1];
  fichier = fopen("fichier.txt", "r");
  if (fichier == NULL) {
    printf("Erreur %d\n", errno);
    return 1;
  }
  printf("Contenu du fichier :\n\n");
  while (fgets(buffer, 50, fichier) != NULL)
    printf("%s", buffer);
  if (fclose(fichier) == EOF) {
    printf("Erreur lors de la fermeture du fichier.\n");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rdi
lea    0xea8(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119b <main+0x5b>
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1216 <main+0xd6>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x32,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11dc <main+0x9c>
lea    -0x50(%rbp),%rsi
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11a9 <main+0x69>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2dfc(%rip),%rcx
cmp    (%rcx),%rax
jne    120f <main+0xcf>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1216 <main+0xd6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
lea    0xea0(%rip),%rdi
lea    0xea5(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11e9 <main+0x99>
mov    %rax,%r15
lea    0xea1(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
mov    $0x32,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11c2 <main+0x72>
lea    0xe7d(%rip),%r14
mov    %rsp,%rbx
nop
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x32,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    11a0 <main+0x50>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %rax,%rcx
mov    0x2e14(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
jne    1205 <main+0xb5>
lea    0xe50(%rip),%rdi
call   1030 <puts@plt>
jmp    1200 <main+0xb0>
mov    0x2de8(%rip),%rax
mov    (%rax),%esi
lea    0xe15(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"fichier.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"Erreur %d\0A\00"
@errno = global i32 0
@.str.3 = [23 x i8] c"Contenu du fichier :\0A\0A\00"
@.str.4 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.5 = [41 x i8] c"Erreur lors de la fermeture du fichier.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [51 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @errno
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %12)
store i32 1, i32* %3
br label %32
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %16
16: ; preds = %21, %14
%17 = getelementptr inbounds [51 x i8], [51 x i8]* %7, i64 0, i64 0
%18 = load i32*, i32** %6
%19 = call i32* @fgets(i8* %17, i32 50, i32* %18)
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = getelementptr inbounds [51 x i8], [51 x i8]* %7, i64 0, i64 0
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %22)
br label %16
24: ; preds = %16
%25 = load i32*, i32** %6
%26 = call i64 @fclose(i32* %25)
%27 = load i64, i64* @EOF
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %32
31: ; preds = %24
store i32 0, i32* %3
br label %32
32: ; preds = %31, %29, %11
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@.str = [12 x i8] c"fichier.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"Erreur %d\0A\00"
@errno = global i32 0
@.str.4 = [3 x i8] c"%s\00"
@EOF = global i64 0
@str = [22 x i8] c"Contenu du fichier :\0A\00"
@str.6 = [40 x i8] c"Erreur lors de la fermeture du fichier.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [51 x i8]
%4 = getelementptr inbounds [51 x i8], [51 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @errno
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %8)
br label %24
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%12 = call i32* @fgets(i8* %4, i32 50, i32* %5)
%13 = icmp eq i32* %12, null
br i1 %13, label %18, label %14
14: ; preds = %10, %14
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%16 = call i32* @fgets(i8* %4, i32 50, i32* %5)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %14
18: ; preds = %14, %10
%19 = call i64 @fclose(i32* %5)
%20 = load i64, i64* @EOF
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.6, i64 0, i64 0))
br label %24
24: ; preds = %18, %22, %7
%25 = phi i32 [ 1, %7 ], [ 1, %22 ], [ 0, %18 ]
ret i32 %25
}