#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, unsigned char);
int /*<<< orphan*/ fread(unsigned char **, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
scalar_t__ strcmp(char *, char *);
char *strtok(char *, char *);
int /*<<< orphan*/ system(char *);
int main(int argc, char *argv[]) {
  unsigned char image[256][256];
  unsigned char histgram[256];
  FILE *fp;
  char *fn;
  if (argc < 2) {
    printf("don't read filename\n");
    return 0;
  } else if (argc > 2) {
    printf("many arguments\n");
    return 0;
  } else {
    fp = fopen(argv[1], "rb");
    fread(image, sizeof(unsigned char), 256 * 256, fp);
    fclose(fp);
    fn = strtok(argv[1], ".");
    for (int i = 0; i < 256; i++) {
      for (int j = 0; j < 256; j++) {
        histgram[image[i][j]]++;
      }
    }
    if (strcmp(fn, "girl") == 0) {
      fp = fopen("plot_ex0girl.dat", "wb");
      for (int i = 0; i < 256; i++) {
        fprintf(fp, "%3d %3d\n", i, histgram[i]);
      }
      fclose(fp);
      system("zsh ex_girl.sh");
    } else {
      fp = fopen("plot_ex0ei.dat", "wb");
      for (int i = 0; i < 256; i++) {
        fprintf(fp, "%3d %3d\n", i, histgram[i]);
      }
      fclose(fp);
      system("zsh ex_ei.sh");
    }
    return 0;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11bb <main+0x3b>
lea    0xe56(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1407 <main+0x287>
cmpl   $0x2,-0x8(%rbp)
jle    11dd <main+0x5d>
lea    0xe49(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1407 <main+0x287>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe39(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10118(%rbp)
lea    -0x10010(%rbp),%rdi
mov    -0x10118(%rbp),%rcx
mov    $0x1,%esi
mov    $0x10000,%edx
call   1030 <fread@plt>
mov    -0x10118(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdf8(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x10120(%rbp)
movl   $0x0,-0x10124(%rbp)
cmpl   $0x100,-0x10124(%rbp)
jge    12ce <main+0x14e>
movl   $0x0,-0x10128(%rbp)
cmpl   $0x100,-0x10128(%rbp)
jge    12b5 <main+0x135>
movslq -0x10124(%rbp),%rcx
lea    -0x10010(%rbp),%rax
shl    $0x8,%rcx
add    %rcx,%rax
movslq -0x10128(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    -0x10110(%rbp,%rax,1),%cl
add    $0x1,%cl
mov    %cl,-0x10110(%rbp,%rax,1)
mov    -0x10128(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10128(%rbp)
jmp    1260 <main+0xe0>
jmp    12ba <main+0x13a>
mov    -0x10124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10124(%rbp)
jmp    1246 <main+0xc6>
mov    -0x10120(%rbp),%rdi
lea    0xd4e(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1378 <main+0x1f8>
lea    0xd3d(%rip),%rdi
lea    0xd47(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10118(%rbp)
movl   $0x0,-0x1012c(%rbp)
cmpl   $0x100,-0x1012c(%rbp)
jge    135b <main+0x1db>
mov    -0x10118(%rbp),%rdi
mov    -0x1012c(%rbp),%edx
movslq -0x1012c(%rbp),%rax
lea    0xd09(%rip),%rsi
movzbl -0x10110(%rbp,%rax,1),%ecx
ff
call   1080 <fprintf@plt>
mov    -0x1012c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1012c(%rbp)
jmp    130f <main+0x18f>
mov    -0x10118(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xcde(%rip),%rdi
call   1050 <system@plt>
jmp    1400 <main+0x280>
lea    0xcdc(%rip),%rdi
lea    0xcba(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10118(%rbp)
movl   $0x0,-0x10130(%rbp)
cmpl   $0x100,-0x10130(%rbp)
jge    13e8 <main+0x268>
mov    -0x10118(%rbp),%rdi
mov    -0x10130(%rbp),%edx
movslq -0x10130(%rbp),%rax
lea    0xc7c(%rip),%rsi
movzbl -0x10110(%rbp,%rax,1),%ecx
ff
call   1080 <fprintf@plt>
mov    -0x10130(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10130(%rbp)
jmp    139c <main+0x21c>
mov    -0x10118(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xc6f(%rip),%rdi
call   1050 <system@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10100,%rsp
cmp    $0x1,%edi
jg     11a2 <main+0x22>
lea    0xec9(%rip),%rdi
call   1030 <puts@plt>
jmp    1312 <main+0x192>
cmp    $0x2,%edi
jne    12af <main+0x12f>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe47(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r14
lea    0x100(%rsp),%rdi
mov    $0x1,%esi
mov    $0x10000,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    0x8(%rbx),%rdi
lea    0xe15(%rip),%rsi
call   10a0 <strtok@plt>
lea    0x101(%rsp),%rcx
xor    %edx,%edx
nopl   (%rax)
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl -0x1(%rcx,%rsi,1),%edi
addb   $0x1,(%rsp,%rdi,1)
movzbl (%rcx,%rsi,1),%edi
addb   $0x1,(%rsp,%rdi,1)
add    $0x2,%rsi
cmp    $0x100,%rsi
jne    1210 <main+0x90>
add    $0x1,%rdx
add    $0x100,%rcx
cmp    $0x100,%rdx
jne    1200 <main+0x80>
lea    0xdbc(%rip),%rsi
mov    %rax,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12bd <main+0x13d>
lea    0xdd9(%rip),%rdi
lea    0xdb7(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r14
xor    %ebx,%ebx
lea    0xda9(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%rsp,%rbx,1),%ecx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1080 <fprintf@plt>
add    $0x1,%rbx
cmp    $0x100,%rbx
jne    1280 <main+0x100>
mov    %r14,%rdi
call   1050 <fclose@plt>
lea    0xd98(%rip),%rdi
jmp    130d <main+0x18d>
lea    0xd9c(%rip),%rdi
call   1030 <puts@plt>
jmp    1312 <main+0x192>
lea    0xd46(%rip),%rdi
lea    0xd50(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r14
xor    %ebx,%ebx
lea    0xd42(%rip),%r15
nopl   0x0(%rax)
movzbl (%rsp,%rbx,1),%ecx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1080 <fprintf@plt>
add    $0x1,%rbx
cmp    $0x100,%rbx
jne    12e0 <main+0x160>
mov    %r14,%rdi
call   1050 <fclose@plt>
lea    0xd1a(%rip),%rdi
call   1060 <system@plt>
xor    %eax,%eax
add    $0x10100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [21 x i8] c"don't read filename\0A\00"
@.str.1 = [16 x i8] c"many arguments\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [2 x i8] c".\00"
@.str.4 = [5 x i8] c"girl\00"
@.str.5 = [17 x i8] c"plot_ex0girl.dat\00"
@.str.6 = [3 x i8] c"wb\00"
@.str.7 = [9 x i8] c"%3d %3d\0A\00"
@.str.8 = [15 x i8] c"zsh ex_girl.sh\00"
@.str.9 = [15 x i8] c"plot_ex0ei.dat\00"
@.str.10 = [13 x i8] c"zsh ex_ei.sh\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x [256 x i8]]
%7 = alloca [256 x i8]
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 2
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %109
18: ; preds = %2
%19 = load i32, i32* %4
%20 = icmp sgt i32 %19, 2
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %109
23: ; preds = %18
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %27, i32** %8
%28 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %6, i64 0, i64 0
%29 = bitcast [256 x i8]* %28 to i8**
%30 = load i32*, i32** %8
%31 = call i32 @fread(i8** %29, i32 1, i32 65536, i32* %30)
%32 = load i32*, i32** %8
%33 = call i32 @fclose(i32* %32)
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i8* @strtok(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %37, i8** %9
store i32 0, i32* %10
br label %38
38: ; preds = %61, %23
%39 = load i32, i32* %10
%40 = icmp slt i32 %39, 256
br i1 %40, label %41, label %64
41: ; preds = %38
store i32 0, i32* %11
br label %42
42: ; preds = %57, %41
%43 = load i32, i32* %11
%44 = icmp slt i32 %43, 256
br i1 %44, label %45, label %60
45: ; preds = %42
%46 = load i32, i32* %10
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %6, i64 0, i64 %47
%49 = load i32, i32* %11
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %48, i64 0, i64 %50
%52 = load i8, i8* %51
%53 = zext i8 %52 to i64
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 %53
%55 = load i8, i8* %54
%56 = add i8 %55, 1
store i8 %56, i8* %54
br label %57
57: ; preds = %45
%58 = load i32, i32* %11
%59 = add nsw i32 %58, 1
store i32 %59, i32* %11
br label %42
60: ; preds = %42
br label %61
61: ; preds = %60
%62 = load i32, i32* %10
%63 = add nsw i32 %62, 1
store i32 %63, i32* %10
br label %38
64: ; preds = %38
%65 = load i8*, i8** %9
%66 = call i64 @strcmp(i8* %65, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%67 = icmp eq i64 %66, 0
br i1 %67, label %68, label %88
68: ; preds = %64
%69 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
store i32* %69, i32** %8
store i32 0, i32* %12
br label %70
70: ; preds = %81, %68
%71 = load i32, i32* %12
%72 = icmp slt i32 %71, 256
br i1 %72, label %73, label %84
73: ; preds = %70
%74 = load i32*, i32** %8
%75 = load i32, i32* %12
%76 = load i32, i32* %12
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 %77
%79 = load i8, i8* %78
%80 = call i32 @fprintf(i32* %74, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 %75, i8 zeroext %79)
br label %81
81: ; preds = %73
%82 = load i32, i32* %12
%83 = add nsw i32 %82, 1
store i32 %83, i32* %12
br label %70
84: ; preds = %70
%85 = load i32*, i32** %8
%86 = call i32 @fclose(i32* %85)
%87 = call i32 @system(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
br label %108
88: ; preds = %64
%89 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
store i32* %89, i32** %8
store i32 0, i32* %13
br label %90
90: ; preds = %101, %88
%91 = load i32, i32* %13
%92 = icmp slt i32 %91, 256
br i1 %92, label %93, label %104
93: ; preds = %90
%94 = load i32*, i32** %8
%95 = load i32, i32* %13
%96 = load i32, i32* %13
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 %97
%99 = load i8, i8* %98
%100 = call i32 @fprintf(i32* %94, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 %95, i8 zeroext %99)
br label %101
101: ; preds = %93
%102 = load i32, i32* %13
%103 = add nsw i32 %102, 1
store i32 %103, i32* %13
br label %90
104: ; preds = %90
%105 = load i32*, i32** %8
%106 = call i32 @fclose(i32* %105)
%107 = call i32 @system(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
br label %108
108: ; preds = %104, %84
store i32 0, i32* %3
br label %109
109: ; preds = %108, %21, %16
%110 = load i32, i32* %3
ret i32 %110
}

LLVM IR (-O2):
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [2 x i8] c".\00"
@.str.4 = [5 x i8] c"girl\00"
@.str.5 = [17 x i8] c"plot_ex0girl.dat\00"
@.str.6 = [3 x i8] c"wb\00"
@.str.7 = [9 x i8] c"%3d %3d\0A\00"
@.str.8 = [15 x i8] c"zsh ex_girl.sh\00"
@.str.9 = [15 x i8] c"plot_ex0ei.dat\00"
@.str.10 = [13 x i8] c"zsh ex_ei.sh\00"
@str = [15 x i8] c"many arguments\00"
@str.11 = [20 x i8] c"don't read filename\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x [256 x i8]]
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %3, i64 0, i64 0, i64 0
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.11, i64 0, i64 0))
br label %74
10: ; preds = %2
%11 = icmp eq i32 %0, 2
br i1 %11, label %14, label %12
12: ; preds = %10
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %74
14: ; preds = %10
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%18 = bitcast [256 x [256 x i8]]* %3 to i8**
%19 = call i32 @fread(i8** %18, i32 1, i32 65536, i32* %17)
%20 = tail call i32 @fclose(i32* %17)
%21 = load i8*, i8** %15
%22 = tail call i8* @strtok(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %14, %28
%24 = phi i64 [ 0, %14 ], [ %29, %28 ]
br label %31
25: ; preds = %28
%26 = tail call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %48, label %61
28: ; preds = %31
%29 = add nuw nsw i64 %24, 1
%30 = icmp eq i64 %29, 256
br i1 %30, label %25, label %23
31: ; preds = %31, %23
%32 = phi i64 [ 0, %23 ], [ %46, %31 ]
%33 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %3, i64 0, i64 %24, i64 %32
%34 = load i8, i8* %33
%35 = zext i8 %34 to i64
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = add i8 %37, 1
store i8 %38, i8* %36
%39 = or i64 %32, 1
%40 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %3, i64 0, i64 %24, i64 %39
%41 = load i8, i8* %40
%42 = zext i8 %41 to i64
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = add i8 %44, 1
store i8 %45, i8* %43
%46 = add nuw nsw i64 %32, 2
%47 = icmp eq i64 %46, 256
br i1 %47, label %28, label %31
48: ; preds = %25
%49 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %53
50: ; preds = %53
%51 = tail call i32 @fclose(i32* %49)
%52 = tail call i32 @system(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
br label %74
53: ; preds = %48, %53
%54 = phi i64 [ 0, %48 ], [ %59, %53 ]
%55 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = trunc i64 %54 to i32
%58 = tail call i32 @fprintf(i32* %49, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 %57, i8 zeroext %56)
%59 = add nuw nsw i64 %54, 1
%60 = icmp eq i64 %59, 256
br i1 %60, label %50, label %53
61: ; preds = %25
%62 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %66
63: ; preds = %66
%64 = tail call i32 @fclose(i32* %62)
%65 = tail call i32 @system(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
br label %74
66: ; preds = %61, %66
%67 = phi i64 [ 0, %61 ], [ %72, %66 ]
%68 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %67
%69 = load i8, i8* %68
%70 = trunc i64 %67 to i32
%71 = tail call i32 @fprintf(i32* %62, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 %70, i8 zeroext %69)
%72 = add nuw nsw i64 %67, 1
%73 = icmp eq i64 %72, 256
br i1 %73, label %63, label %66
74: ; preds = %50, %63, %12, %8
ret i32 0
}