#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;
  char c;
  while (0 < read(f, &c, 1))
    ascii[(int)c]++;
  close(f);
  for (int i = 0; i < 256; i++)
    if (ascii[i])
      printf("%c:%d ", i, ascii[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>
jmp    120f <main+0xbf>
mov    -0x1c(%rbp),%edi
lea    -0x425(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jge    1250 <main+0x100>
movsbl -0x425(%rbp),%eax
cltq
mov    -0x420(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x420(%rbp,%rax,4)
jmp    120f <main+0xbf>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x42c(%rbp)
cmpl   $0x100,-0x42c(%rbp)
jge    12c2 <main+0x172>
movslq -0x42c(%rbp),%rax
cmpl   $0x0,-0x420(%rbp,%rax,4)
je     12a9 <main+0x159>
mov    -0x42c(%rbp),%esi
movslq -0x42c(%rbp),%rax
mov    -0x420(%rbp,%rax,4),%edx
lea    0xd9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ae <main+0x15e>
mov    -0x42c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x42c(%rbp)
jmp    1262 <main+0x112>
lea    0xd51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x418,%rsp
cmp    $0x1,%edi
jle    125a <main+0xda>
mov    0x8(%rsi),%rdi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
test   %eax,%eax
js     1270 <main+0xf0>
mov    %eax,%ebx
lea    0x10(%rsp),%rdi
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    11ff <main+0x7f>
lea    0xf(%rsp),%r14
nopl   0x0(%rax,%rax,1)
movsbq 0xf(%rsp),%rax
addl   $0x1,0x10(%rsp,%rax,4)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1080 <read@plt>
test   %rax,%rax
jg     11e0 <main+0x60>
mov    %ebx,%edi
call   1070 <close@plt>
lea    0xe16(%rip),%r14
xor    %ebx,%ebx
jmp    122d <main+0xad>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    $0x100,%rbx
je     1243 <main+0xc3>
mov    0x10(%rsp,%rbx,4),%edx
test   %edx,%edx
je     1220 <main+0xa0>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1220 <main+0xa0>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdc9(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xd89(%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 = [7 x i8] c"%c:%d \00"
@.str.3 = [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 i8
%12 = alloca i32
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %18
15: ; preds = %3
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %3
%19 = load i8**, i8*** %6
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = load i32, i32* @O_RDONLY
%23 = call i32 @open(i8* %21, i32 %22)
store i32 %23, i32* %8
%24 = load i32, i32* %8
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %18
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @exit(i32 2)
unreachable
29: ; preds = %18
store i32 0, i32* %10
br label %30
30: ; preds = %37, %29
%31 = load i32, i32* %10
%32 = icmp slt i32 %31, 256
br i1 %32, label %33, label %40
33: ; preds = %30
%34 = load i32, i32* %10
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [256 x i32], [256 x i32]* %9, i64 0, i64 %35
store i32 0, i32* %36
br label %37
37: ; preds = %33
%38 = load i32, i32* %10
%39 = add nsw i32 %38, 1
store i32 %39, i32* %10
br label %30
40: ; preds = %30
br label %41
41: ; preds = %45, %40
%42 = load i32, i32* %8
%43 = call i64 @read(i32 %42, i8* %11, i32 1)
%44 = icmp slt i64 0, %43
br i1 %44, label %45, label %52
45: ; preds = %41
%46 = load i8, i8* %11
%47 = sext i8 %46 to i32
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [256 x i32], [256 x i32]* %9, i64 0, i64 %48
%50 = load i32, i32* %49
%51 = add nsw i32 %50, 1
store i32 %51, i32* %49
br label %41
52: ; preds = %41
%53 = load i32, i32* %8
%54 = call i32 @close(i32 %53)
store i32 0, i32* %12
br label %55
55: ; preds = %72, %52
%56 = load i32, i32* %12
%57 = icmp slt i32 %56, 256
br i1 %57, label %58, label %75
58: ; preds = %55
%59 = load i32, i32* %12
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [256 x i32], [256 x i32]* %9, i64 0, i64 %60
%62 = load i32, i32* %61
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %71
64: ; preds = %58
%65 = load i32, i32* %12
%66 = load i32, i32* %12
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [256 x i32], [256 x i32]* %9, i64 0, i64 %67
%69 = load i32, i32* %68
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %65, i32 %69)
br label %71
71: ; preds = %64, %58
br label %72
72: ; preds = %71
%73 = load i32, i32* %12
%74 = add nsw i32 %73, 1
store i32 %74, i32* %12
br label %55
75: ; preds = %55
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, 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 = [7 x i8] c"%c:%d \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 %31
23: ; preds = %20, %23
%24 = load i8, i8* %6
%25 = sext i8 %24 to i64
%26 = getelementptr inbounds [256 x i32], [256 x i32]* %4, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = add nsw i32 %27, 1
store i32 %28, i32* %26
%29 = call i64 @read(i32 %15, i8* %6, i32 1)
%30 = icmp sgt i64 %29, 0
br i1 %30, label %23, label %31
31: ; preds = %23, %20
%32 = tail call i32 @close(i32 %15)
br label %35
33: ; preds = %43
%34 = tail call i32 @putchar(i32 10)
ret i32 0
35: ; preds = %31, %43
%36 = phi i64 [ 0, %31 ], [ %44, %43 ]
%37 = getelementptr inbounds [256 x i32], [256 x i32]* %4, i64 0, i64 %36
%38 = load i32, i32* %37
%39 = icmp eq i32 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %35
%41 = trunc i64 %36 to i32
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %41, i32 %38)
br label %43
43: ; preds = %35, %40
%44 = add nuw nsw i64 %36, 1
%45 = icmp eq i64 %44, 256
br i1 %45, label %33, label %35
}