#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *, char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  FILE *f = fopen("exo1.f.out", "r");
  if (f == NULL) {
    printf("Could not open file\n");
    return 1;
  }
  char nom[20], prenom[20];
  int age;
  while (fscanf(f, "Nom: %s , Prénom: %s , Age: %i\n", nom, prenom, &age) == 3)
    printf("Nom:\t%s\nPrénom:\t%s\nAge:\t%i\n", nom, prenom, age);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xeae(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    118b <main+0x4b>
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11e3 <main+0xa3>
jmp    1190 <main+0x50>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    -0x50(%rbp),%rcx
lea    0xe7f(%rip),%rsi
lea    -0x54(%rbp),%r8
call   1050 <fscanf@plt>
cmp    $0x3,%eax
jne    11d3 <main+0x93>
lea    -0x30(%rbp),%rsi
lea    -0x50(%rbp),%rdx
mov    -0x54(%rbp),%ecx
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1190 <main+0x50>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
lea    0xe9b(%rip),%rdi
lea    0xe9f(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11f9 <main+0xa9>
mov    %rax,%r15
lea    0xe89(%rip),%rsi
lea    0x30(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
mov    %rax,%rdi
call   1060 <fscanf@plt>
cmp    $0x3,%eax
jne    11ed <main+0x9d>
lea    0xe87(%rip),%r14
lea    0x30(%rsp),%r12
lea    0x10(%rsp),%rbx
lea    0xe55(%rip),%r13
lea    0xc(%rsp),%rbp
nopl   (%rax)
mov    0xc(%rsp),%ecx
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
mov    %rbp,%r8
call   1060 <fscanf@plt>
cmp    $0x3,%eax
je     11c0 <main+0x70>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    120a <main+0xba>
lea    0xe4b(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"exo1.f.out\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [21 x i8] c"Could not open file\0A\00"
@.str.3 = [33 x i8] c"Nom: %s , Pr\C3\A9nom: %s , Age: %i\0A\00"
@.str.4 = [29 x i8] c"Nom:\09%s\0APr\C3\A9nom:\09%s\0AAge:\09%i\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [20 x i8]
%4 = alloca [20 x i8]
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
%7 = load i32*, i32** %2
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %26
11: ; preds = %0
br label %12
12: ; preds = %18, %11
%13 = load i32*, i32** %2
%14 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%15 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%16 = call i32 @fscanf(i32* %13, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %14, i8* %15, i32* %5)
%17 = icmp eq i32 %16, 3
br i1 %17, label %18, label %23
18: ; preds = %12
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%21 = load i32, i32* %5
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %19, i8* %20, i32 %21)
br label %12
23: ; preds = %12
%24 = load i32*, i32** %2
%25 = call i32 @fclose(i32* %24)
store i32 0, i32* %1
br label %26
26: ; preds = %23, %9
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
@.str = [11 x i8] c"exo1.f.out\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [33 x i8] c"Nom: %s , Pr\C3\A9nom: %s , Age: %i\0A\00"
@.str.4 = [29 x i8] c"Nom:\09%s\0APr\C3\A9nom:\09%s\0AAge:\09%i\0A\00"
@str = [20 x i8] c"Could not open file\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = alloca [20 x i8]
%3 = alloca i32
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %21
8: ; preds = %0
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%11 = bitcast i32* %3 to i8*
%12 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %9, i8* %10, i32* %3)
%13 = icmp eq i32 %12, 3
br i1 %13, label %14, label %19
14: ; preds = %8, %14
%15 = load i32, i32* %3
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %9, i8* %10, i32 %15)
%17 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %9, i8* %10, i32* %3)
%18 = icmp eq i32 %17, 3
br i1 %18, label %14, label %19
19: ; preds = %14, %8
%20 = call i32 @fclose(i32* %4)
br label %21
21: ; preds = %19, %6
%22 = phi i32 [ 1, %6 ], [ 0, %19 ]
ret i32 %22
}