#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  if (argc != 2) {
    fprintf(stderr, "Syntaxe incorrecte.\n");
    exit(EXIT_FAILURE);
  }
  int processus;
  if ((processus = open(argv[1], O_RDONLY)) != -1) {
    int n = 0;
    char c;
    while (read(processus, &c, 1) != 0)
      n++;
    printf("Nombre de caracteres : %d\n", n);
    if (n < 30) {
      fprintf(stderr, "Le fichier specifie contient moins de 30 caracteres.\n");
    } else {
      lseek(processus, n - 30, SEEK_SET);
      int i = 0;
      for (i = 0; i < 30; i++) {
        read(processus, &c, 1);
        fprintf(stdout, "%c", c);
      }
    }
    close(processus);
  } else {
    fprintf(stderr, "Impossible d'acceder au fichier specifie.\n");
  }
  printf("\n");
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b5 <main+0x45>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     12b9 <main+0x149>
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
cmp    $0x0,%rax
je     1207 <main+0x97>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11de <main+0x6e>
mov    -0x18(%rbp),%esi
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x1e,-0x18(%rbp)
jge    123e <main+0xce>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
lea    0xdfe(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    12ac <main+0x13c>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
sub    $0x1e,%esi
mov    0x2d82(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x1e,-0x20(%rbp)
jge    12a7 <main+0x137>
mov    -0x14(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
movsbl -0x19(%rbp),%edx
lea    0xdd4(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1263 <main+0xf3>
jmp    12ac <main+0x13c>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
jmp    12d0 <main+0x160>
mov    0x2d18(%rip),%rax
mov    (%rax),%edi
lea    0xda0(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2cd3(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    129e <main+0x11e>
mov    0x8(%rsi),%rdi
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     1208 <main+0x88>
mov    %eax,%ebp
mov    $0xffffffe1,%ebx
lea    0xf(%rsp),%r14
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
add    $0x1,%ebx
test   %rax,%rax
jne    11c0 <main+0x40>
lea    0xe37(%rip),%rdi
lea    0x1e(%rbx),%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x1e,%eax
jae    1221 <main+0xa1>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
lea    0xe31(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    1277 <main+0xf7>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    127e <main+0xfe>
mov    0x2da8(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    %ebx,%esi
call   1050 <lseek@plt>
mov    $0x1e,%ebx
lea    0xf(%rsp),%r14
mov    0x2d7c(%rip),%r12
lea    0xe1b(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
mov    (%r12),%edi
movsbl 0xf(%rsp),%edx
mov    %r15,%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
add    $0xffffffff,%ebx
jne    1250 <main+0xd0>
mov    %ebp,%edi
call   1060 <close@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2d29(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
lea    0xd52(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x2d0c(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [21 x i8] c"Syntaxe incorrecte.\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [27 x i8] c"Nombre de caracteres : %d\0A\00"
@.str.2 = [54 x i8] c"Le fichier specifie contient moins de 30 caracteres.\0A\00"
@SEEK_SET = global i32 0
@stdout = global i32 0
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [43 x i8] c"Impossible d'acceder au fichier specifie.\0A\00"
@.str.5 = [2 x i8] c"\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i32, i32* @O_RDONLY
%22 = call i32 @open(i8* %20, i32 %21)
store i32 %22, i32* %6
%23 = icmp ne i32 %22, -1
br i1 %23, label %24, label %63
24: ; preds = %17
store i32 0, i32* %7
br label %25
25: ; preds = %29, %24
%26 = load i32, i32* %6
%27 = call i64 @read(i32 %26, i8* %8, i32 1)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %25
32: ; preds = %25
%33 = load i32, i32* %7
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %7
%36 = icmp slt i32 %35, 30
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0))
br label %60
40: ; preds = %32
%41 = load i32, i32* %6
%42 = load i32, i32* %7
%43 = sub nsw i32 %42, 30
%44 = load i32, i32* @SEEK_SET
%45 = call i32 @lseek(i32 %41, i32 %43, i32 %44)
store i32 0, i32* %9
store i32 0, i32* %9
br label %46
46: ; preds = %56, %40
%47 = load i32, i32* %9
%48 = icmp slt i32 %47, 30
br i1 %48, label %49, label %59
49: ; preds = %46
%50 = load i32, i32* %6
%51 = call i64 @read(i32 %50, i8* %8, i32 1)
%52 = load i32, i32* @stdout
%53 = load i8, i8* %8
%54 = sext i8 %53 to i32
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %54)
br label %56
56: ; preds = %49
%57 = load i32, i32* %9
%58 = add nsw i32 %57, 1
store i32 %58, i32* %9
br label %46
59: ; preds = %46
br label %60
60: ; preds = %59, %37
%61 = load i32, i32* %6
%62 = call i32 @close(i32 %61)
br label %66
63: ; preds = %17
%64 = load i32, i32* @stderr
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
br label %66
66: ; preds = %63, %60
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%68 = load i32, i32* @EXIT_SUCCESS
ret i32 %68
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [21 x i8] c"Syntaxe incorrecte.\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [27 x i8] c"Nombre de caracteres : %d\0A\00"
@.str.2 = [54 x i8] c"Le fichier specifie contient moins de 30 caracteres.\0A\00"
@SEEK_SET = global i32 0
@stdout = global i32 0
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [43 x i8] c"Impossible d'acceder au fichier specifie.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = icmp eq i32 %0, 2
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 @open(i8* %12, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %43, label %16
16: ; preds = %10
br label %17
17: ; preds = %17, %16
%18 = phi i32 [ 0, %16 ], [ %21, %17 ]
%19 = call i64 @read(i32 %14, i8* %3, i32 1)
%20 = icmp eq i64 %19, 0
%21 = add nuw nsw i32 %18, 1
br i1 %20, label %22, label %17
22: ; preds = %17
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%24 = icmp ult i32 %18, 30
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0))
br label %41
28: ; preds = %22
%29 = add nsw i32 %18, -30
%30 = load i32, i32* @SEEK_SET
%31 = tail call i32 @lseek(i32 %14, i32 %29, i32 %30)
br label %32
32: ; preds = %28, %32
%33 = phi i32 [ 0, %28 ], [ %39, %32 ]
%34 = call i64 @read(i32 %14, i8* %3, i32 1)
%35 = load i32, i32* @stdout
%36 = load i8, i8* %3
%37 = sext i8 %36 to i32
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %37)
%39 = add nuw nsw i32 %33, 1
%40 = icmp eq i32 %39, 30
br i1 %40, label %41, label %32
41: ; preds = %32, %25
%42 = tail call i32 @close(i32 %14)
br label %46
43: ; preds = %10
%44 = load i32, i32* @stderr
%45 = tail call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
br label %46
46: ; preds = %43, %41
%47 = tail call i32 @putchar(i32 10)
%48 = load i32, i32* @EXIT_SUCCESS
ret i32 %48
}