#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*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(int, char *, int);
int main(int argc, char *argv[], char *env[]) {
  if (argc < 2) {
    printf("Aucun fichier à ouvrir...\n");
    exit(1);
  }
  int f = open(argv[1], O_RDONLY);
  if (f < 0) {
    printf("Ouverture de fichier impossible...");
    exit(2);
  }
  int ascii[256];
  for (int i = 0; i < 256; i++)
    ascii[i] = 0;
  int cpt = 0;
  char c;
  while (0 < read(f, &c, 1))
    if (!ascii[(int)c]) {
      cpt++;
      ascii[(int)c] = 1;
    }
  close(f);
  printf("%d caracteres differents : ", cpt);
  for (int i = 0; i < 256; i++)
    if (ascii[i])
      printf("%c, ", i);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    118f <main+0x3f>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11ca <main+0x7a>
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x2,%edi
call   1070 <exit@plt>
movl   $0x0,-0x424(%rbp)
cmpl   $0x100,-0x424(%rbp)
jge    120a <main+0xba>
movslq -0x424(%rbp),%rax
movl   $0x0,-0x420(%rbp,%rax,4)
mov    -0x424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
jmp    11d4 <main+0x84>
movl   $0x0,-0x428(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x429(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jge    1275 <main+0x125>
movsbl -0x429(%rbp),%eax
cltq
cmpl   $0x0,-0x420(%rbp,%rax,4)
jne    1270 <main+0x120>
mov    -0x428(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x428(%rbp)
movsbl -0x429(%rbp),%eax
cltq
movl   $0x1,-0x420(%rbp,%rax,4)
jmp    1214 <main+0xc4>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
mov    -0x428(%rbp),%esi
lea    0xdb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x430(%rbp)
cmpl   $0x100,-0x430(%rbp)
jge    12ed <main+0x19d>
movslq -0x430(%rbp),%rax
cmpl   $0x0,-0x420(%rbp,%rax,4)
je     12d4 <main+0x184>
mov    -0x430(%rbp),%esi
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12d9 <main+0x189>
mov    -0x430(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x430(%rbp)
jmp    129b <main+0x14b>
lea    0xd26(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x410,%rsp
cmp    $0x1,%edi
jle    127a <main+0xfa>
mov    0x8(%rsi),%rdi
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
test   %eax,%eax
js     1290 <main+0x110>
mov    %eax,%ebx
lea    0x10(%rsp),%rdi
xor    %ebp,%ebp
mov    $0x400,%edx
xor    %esi,%esi
call   1060 <memset@plt>
lea    0xf(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1080 <read@plt>
test   %rax,%rax
jle    121e <main+0x9e>
xor    %ebp,%ebp
lea    0xf(%rsp),%r14
jmp    1204 <main+0x84>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1080 <read@plt>
test   %rax,%rax
jle    121e <main+0x9e>
movsbq 0xf(%rsp),%rax
cmpl   $0x0,0x10(%rsp,%rax,4)
jne    11f0 <main+0x70>
add    $0x1,%ebp
movl   $0x1,0x10(%rsp,%rax,4)
jmp    11f0 <main+0x70>
mov    %ebx,%edi
call   1070 <close@plt>
lea    0xdf7(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe03(%rip),%rbx
xor    %ebp,%ebp
jmp    124d <main+0xcd>
add    $0x1,%rbp
cmp    $0x100,%rbp
je     1262 <main+0xe2>
cmpl   $0x0,0x10(%rsp,%rbp,4)
je     1240 <main+0xc0>
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1240 <main+0xc0>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdc3(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xd69(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"Aucun fichier \C3\A0 ouvrir...\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [35 x i8] c"Ouverture de fichier impossible...\00"
@.str.2 = [28 x i8] c"%d caracteres differents : \00"
@.str.3 = [5 x i8] c"%c, \00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i32
%9 = alloca [256 x i32]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8
%13 = alloca i32
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%14 = load i32, i32* %5
%15 = icmp slt i32 %14, 2
br i1 %15, label %16, label %19
16: ; preds = %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %3
%20 = load i8**, i8*** %6
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* %22, i32 %23)
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %19
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @exit(i32 2)
unreachable
30: ; preds = %19
store i32 0, i32* %10
br label %31
31: ; preds = %38, %30
%32 = load i32, i32* %10
%33 = icmp slt i32 %32, 256
br i1 %33, label %34, label %41
34: ; preds = %31
%35 = load i32, i32* %10
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [256 x i32], [256 x i32]* %9, i64 0, i64 %36
store i32 0, i32* %37
br label %38
38: ; preds = %34
%39 = load i32, i32* %10
%40 = add nsw i32 %39, 1
store i32 %40, i32* %10
br label %31
41: ; preds = %31
store i32 0, i32* %11
br label %42
42: ; preds = %60, %41
%43 = load i32, i32* %8
%44 = call i64 @read(i32 %43, i8* %12, i32 1)
%45 = icmp slt i64 0, %44
br i1 %45, label %46, label %61
46: ; preds = %42
%47 = load i8, i8* %12
%48 = sext i8 %47 to i32
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [256 x i32], [256 x i32]* %9, i64 0, i64 %49
%51 = load i32, i32* %50
%52 = icmp ne i32 %51, 0
br i1 %52, label %60, label %53
53: ; preds = %46
%54 = load i32, i32* %11
%55 = add nsw i32 %54, 1
store i32 %55, i32* %11
%56 = load i8, i8* %12
%57 = sext i8 %56 to i32
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [256 x i32], [256 x i32]* %9, i64 0, i64 %58
store i32 1, i32* %59
br label %60
60: ; preds = %53, %46
br label %42
61: ; preds = %42
%62 = load i32, i32* %8
%63 = call i32 @close(i32 %62)
%64 = load i32, i32* %11
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %64)
store i32 0, i32* %13
br label %66
66: ; preds = %79, %61
%67 = load i32, i32* %13
%68 = icmp slt i32 %67, 256
br i1 %68, label %69, label %82
69: ; preds = %66
%70 = load i32, i32* %13
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [256 x i32], [256 x i32]* %9, i64 0, i64 %71
%73 = load i32, i32* %72
%74 = icmp ne i32 %73, 0
br i1 %74, label %75, label %78
75: ; preds = %69
%76 = load i32, i32* %13
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %76)
br label %78
78: ; preds = %75, %69
br label %79
79: ; preds = %78
%80 = load i32, i32* %13
%81 = add nsw i32 %80, 1
store i32 %81, i32* %13
br label %66
82: ; preds = %66
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str.1 = [35 x i8] c"Ouverture de fichier impossible...\00"
@.str.2 = [28 x i8] c"%d caracteres differents : \00"
@.str.3 = [5 x i8] c"%c, \00"
@str = [27 x i8] c"Aucun fichier \C3\A0 ouvrir...\00"
define i32 @main(i32 %0, i8** nocapture %1, i8** nocapture readnone %2) {
%4 = alloca [256 x i32]
%5 = bitcast [256 x i32]* %4 to i8*
%6 = alloca i8
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %3
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = load i32, i32* @O_RDONLY
%15 = tail call i32 @open(i8* %13, i32 %14)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @exit(i32 2)
unreachable
20: ; preds = %11
%21 = call i64 @read(i32 %15, i8* %6, i32 1)
%22 = icmp sgt i64 %21, 0
br i1 %22, label %23, label %36
23: ; preds = %20, %32
%24 = phi i32 [ %33, %32 ], [ 0, %20 ]
%25 = load i8, i8* %6
%26 = sext i8 %25 to i64
%27 = getelementptr inbounds [256 x i32], [256 x i32]* %4, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %23
%31 = add nsw i32 %24, 1
store i32 1, i32* %27
br label %32
32: ; preds = %30, %23
%33 = phi i32 [ %24, %23 ], [ %31, %30 ]
%34 = call i64 @read(i32 %15, i8* %6, i32 1)
%35 = icmp sgt i64 %34, 0
br i1 %35, label %23, label %36
36: ; preds = %32, %20
%37 = phi i32 [ 0, %20 ], [ %33, %32 ]
%38 = tail call i32 @close(i32 %15)
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %37)
br label %42
40: ; preds = %50
%41 = tail call i32 @putchar(i32 10)
ret i32 0
42: ; preds = %36, %50
%43 = phi i64 [ 0, %36 ], [ %51, %50 ]
%44 = getelementptr inbounds [256 x i32], [256 x i32]* %4, i64 0, i64 %43
%45 = load i32, i32* %44
%46 = icmp eq i32 %45, 0
br i1 %46, label %50, label %47
47: ; preds = %42
%48 = trunc i64 %43 to i32
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %48)
br label %50
50: ; preds = %42, %47
%51 = add nuw nsw i64 %43, 1
%52 = icmp eq i64 %51, 256
br i1 %52, label %40, label %42
}