#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*/ fread(unsigned char **, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned char **, int, int, int /*<<< orphan*/ *);
unsigned char laplacian(unsigned char, unsigned char, unsigned char,
                        unsigned char, unsigned char, unsigned char,
                        unsigned char, unsigned char, unsigned char);
int /*<<< orphan*/ system(char *);
int main() {
  unsigned char image[256][256];
  unsigned char image_w[256][256] = {0};
  FILE *fp;
  fp = fopen("girl.dat", "rb");
  fread(image, sizeof(unsigned char), 256 * 256, fp);
  fclose(fp);
  for (int i = 1; i < 256 - 1; i++) {
    for (int j = 1; j < 256 - 1; j++) {
      image_w[i][j] =
          laplacian(image[i - 1][j - 1], image[i - 1][j], image[i - 1][j + 1],
                    image[i][j - 1], image[i][j], image[i][j + 1],
                    image[i + 1][j - 1], image[i + 1][j], image[i + 1][j + 1]);
    }
  }
  fp = fopen("girl_laplacian.dat", "wb");
  fwrite(image_w, sizeof(unsigned char), 256 * 256, fp);
  fclose(fp);
  system("zsh plot_ex1-2.sh");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x20038,%rsp
movl   $0x0,-0xc(%rbp)
lea    -0x20010(%rbp),%rdi
xor    %esi,%esi
mov    $0x10000,%edx
call   1060 <memset@plt>
lea    0xe63(%rip),%rdi
lea    0xe65(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20018(%rbp)
lea    -0x10010(%rbp),%rdi
mov    -0x20018(%rbp),%rcx
mov    $0x1,%esi
mov    $0x10000,%edx
call   1030 <fread@plt>
mov    -0x20018(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x2001c(%rbp)
cmpl   $0xff,-0x2001c(%rbp)
jge    13ea <main+0x27a>
movl   $0x1,-0x20020(%rbp)
cmpl   $0xff,-0x20020(%rbp)
jge    13d1 <main+0x261>
mov    -0x2001c(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    -0x10010(%rbp),%rax
shl    $0x8,%rcx
add    %rcx,%rax
mov    -0x20020(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dil
mov    -0x2001c(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    -0x10010(%rbp),%rax
shl    $0x8,%rcx
add    %rcx,%rax
movslq -0x20020(%rbp),%rcx
mov    (%rax,%rcx,1),%sil
mov    -0x2001c(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    -0x10010(%rbp),%rax
shl    $0x8,%rcx
add    %rcx,%rax
mov    -0x20020(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
movslq -0x2001c(%rbp),%rcx
lea    -0x10010(%rbp),%rax
shl    $0x8,%rcx
add    %rcx,%rax
mov    -0x20020(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x2001c(%rbp),%r8
lea    -0x10010(%rbp),%rax
shl    $0x8,%r8
add    %r8,%rax
movslq -0x20020(%rbp),%r8
mov    (%rax,%r8,1),%r8b
movslq -0x2001c(%rbp),%r9
lea    -0x10010(%rbp),%rax
shl    $0x8,%r9
add    %r9,%rax
mov    -0x20020(%rbp),%r9d
add    $0x1,%r9d
movslq %r9d,%r9
mov    (%rax,%r9,1),%r9b
mov    -0x2001c(%rbp),%eax
add    $0x1,%eax
movslq %eax,%r10
lea    -0x10010(%rbp),%rax
shl    $0x8,%r10
add    %r10,%rax
mov    -0x20020(%rbp),%r10d
sub    $0x1,%r10d
movslq %r10d,%r10
mov    (%rax,%r10,1),%bl
mov    -0x2001c(%rbp),%eax
add    $0x1,%eax
movslq %eax,%r10
lea    -0x10010(%rbp),%rax
shl    $0x8,%r10
add    %r10,%rax
movslq -0x20020(%rbp),%r10
mov    (%rax,%r10,1),%r11b
mov    -0x2001c(%rbp),%eax
add    $0x1,%eax
movslq %eax,%r10
lea    -0x10010(%rbp),%rax
shl    $0x8,%r10
add    %r10,%rax
mov    -0x20020(%rbp),%r10d
add    $0x1,%r10d
movslq %r10d,%r10
movzbl %dil,%edi
movzbl %sil,%esi
movzbl %dl,%edx
movzbl %cl,%ecx
movzbl %r8b,%r8d
movzbl %r9b,%r9d
movzbl %bl,%ebx
mov    %ebx,(%rsp)
movzbl %r11b,%r11d
mov    %r11d,0x8(%rsp)
movzbl (%rax,%r10,1),%eax
mov    %eax,0x10(%rsp)
call   1090 <laplacian@plt>
mov    %al,%dl
movslq -0x2001c(%rbp),%rcx
lea    -0x20010(%rbp),%rax
shl    $0x8,%rcx
add    %rcx,%rax
movslq -0x20020(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20020(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20020(%rbp)
jmp    11fd <main+0x8d>
jmp    13d6 <main+0x266>
mov    -0x2001c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2001c(%rbp)
jmp    11e3 <main+0x73>
lea    0xc1b(%rip),%rdi
lea    0xc27(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20018(%rbp)
lea    -0x20010(%rbp),%rdi
mov    -0x20018(%rbp),%rcx
mov    $0x1,%esi
mov    $0x10000,%edx
call   1080 <fwrite@plt>
mov    -0x20018(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xbee(%rip),%rdi
call   1050 <system@plt>
xor    %eax,%eax
add    $0x20038,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20028,%rsp
lea    0x10020(%rsp),%rdi
mov    $0x10000,%edx
xor    %esi,%esi
call   1060 <memset@plt>
lea    0xe64(%rip),%rdi
lea    0xe66(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0x20(%rsp),%rdi
mov    $0x1,%esi
mov    $0x10000,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x20(%rsp),%al
mov    0x21(%rsp),%r14b
mov    0x120(%rsp),%bl
mov    0x121(%rsp),%bpl
lea    0x10121(%rsp),%rsi
lea    0x222(%rsp),%rdi
mov    $0x1,%ecx
nopw   0x0(%rax,%rax,1)
mov    %eax,%r8d
add    $0x1,%rcx
mov    %rcx,0x8(%rsp)
shl    $0x8,%rcx
mov    0x20(%rsp,%rcx,1),%dl
mov    0x21(%rsp,%rcx,1),%cl
xor    %r13d,%r13d
mov    %cl,0x3(%rsp)
mov    %ecx,%r15d
mov    %dl,0x4(%rsp)
mov    %bpl,0x5(%rsp)
mov    %bl,0x6(%rsp)
mov    %ebx,%ecx
mov    %rsi,0x18(%rsp)
mov    %rdi,0x10(%rsp)
nopl   0x0(%rax,%rax,1)
mov    %r14d,%ebx
mov    %ebp,%r12d
mov    %r15d,%eax
mov    %r15b,0x7(%rsp)
movzbl -0x200(%rdi,%r13,1),%r14d
ff ff
movzbl -0x100(%rdi,%r13,1),%ebp
ff ff
movzbl (%rdi,%r13,1),%r15d
sub    $0x8,%rsp
movzbl %al,%r11d
movzbl %dl,%r10d
movzbl %r14b,%edx
movzbl %bpl,%r9d
movzbl %r8b,%edi
movzbl %bl,%esi
movzbl %cl,%ecx
movzbl %r12b,%r8d
push   %r15
push   %r11
push   %r10
call   1090 <laplacian@plt>
mov    0x30(%rsp),%rdi
mov    0x38(%rsp),%rsi
add    $0x20,%rsp
mov    %al,(%rsi,%r13,1)
add    $0x1,%r13
movzbl 0x7(%rsp),%edx
mov    %r12d,%ecx
mov    %ebx,%r8d
cmp    $0xfe,%r13
jne    1240 <main+0xd0>
add    $0x100,%rsi
add    $0x100,%rdi
mov    0x8(%rsp),%rcx
cmp    $0xff,%rcx
mov    0x6(%rsp),%al
mov    0x5(%rsp),%r14b
mov    0x4(%rsp),%bl
mov    0x3(%rsp),%bpl
jne    1200 <main+0x90>
lea    0xd17(%rip),%rdi
lea    0xd23(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0x10020(%rsp),%rdi
mov    $0x1,%esi
mov    $0x10000,%edx
mov    %rax,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xcf5(%rip),%rdi
call   1050 <system@plt>
xor    %eax,%eax
add    $0x20028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [9 x i8] c"girl.dat\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [19 x i8] c"girl_laplacian.dat\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [18 x i8] c"zsh plot_ex1-2.sh\00"
define i32 @main() {
%1 = alloca [256 x [256 x i8]]
%2 = alloca [256 x [256 x i8]]
%3 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %1, i64 0, i64 0, i64 0
%4 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %2, i64 0, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = bitcast [256 x [256 x i8]]* %1 to i8**
%7 = call i32 @fread(i8** %6, i32 1, i32 65536, i32* %5)
%8 = tail call i32 @fclose(i32* %5)
%9 = load i8, i8* %3
%10 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %1, i64 0, i64 0, i64 1
%11 = load i8, i8* %10
%12 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %1, i64 0, i64 1, i64 0
%13 = load i8, i8* %12
%14 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %1, i64 0, i64 1, i64 1
%15 = load i8, i8* %14
br label %16
16: ; preds = %0, %34
%17 = phi i8 [ %15, %0 ], [ %27, %34 ]
%18 = phi i8 [ %13, %0 ], [ %25, %34 ]
%19 = phi i8 [ %11, %0 ], [ %17, %34 ]
%20 = phi i8 [ %9, %0 ], [ %18, %34 ]
%21 = phi i64 [ 1, %0 ], [ %23, %34 ]
%22 = add nsw i64 %21, -1
%23 = add nuw nsw i64 %21, 1
%24 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %1, i64 0, i64 %23, i64 0
%25 = load i8, i8* %24
%26 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %1, i64 0, i64 %23, i64 1
%27 = load i8, i8* %26
br label %36
28: ; preds = %34
%29 = tail call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%30 = bitcast [256 x [256 x i8]]* %2 to i8**
%31 = call i32 @fwrite(i8** %30, i32 1, i32 65536, i32* %29)
%32 = tail call i32 @fclose(i32* %29)
%33 = tail call i32 @system(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
34: ; preds = %36
%35 = icmp eq i64 %23, 255
br i1 %35, label %28, label %16
36: ; preds = %16, %36
%37 = phi i8 [ %27, %16 ], [ %50, %36 ]
%38 = phi i8 [ %25, %16 ], [ %37, %36 ]
%39 = phi i8 [ %17, %16 ], [ %48, %36 ]
%40 = phi i8 [ %18, %16 ], [ %39, %36 ]
%41 = phi i8 [ %19, %16 ], [ %46, %36 ]
%42 = phi i8 [ %20, %16 ], [ %41, %36 ]
%43 = phi i64 [ 1, %16 ], [ %44, %36 ]
%44 = add nuw nsw i64 %43, 1
%45 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %1, i64 0, i64 %22, i64 %44
%46 = load i8, i8* %45
%47 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %1, i64 0, i64 %21, i64 %44
%48 = load i8, i8* %47
%49 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %1, i64 0, i64 %23, i64 %44
%50 = load i8, i8* %49
%51 = tail call zeroext i8 @laplacian(i8 zeroext %42, i8 zeroext %41, i8 zeroext %46, i8 zeroext %40, i8 zeroext %39, i8 zeroext %48, i8 zeroext %38, i8 zeroext %37, i8 zeroext %50)
%52 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %2, i64 0, i64 %21, i64 %43
store i8 %51, i8* %52
%53 = icmp eq i64 %44, 255
br i1 %53, label %34, label %36
}