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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x14020,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x14018(%rbp)
lea    -0x10010(%rbp),%rdi
mov    -0x14018(%rbp),%rcx
mov    $0x1,%esi
mov    $0x10000,%edx
call   1030 <fread@plt>
mov    -0x14018(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x1401c(%rbp)
cmpl   $0x80,-0x1401c(%rbp)
jge    124e <main+0xfe>
movl   $0x0,-0x14020(%rbp)
cmpl   $0x80,-0x14020(%rbp)
jge    1235 <main+0xe5>
mov    -0x1401c(%rbp),%eax
shl    $0x1,%eax
movslq %eax,%rcx
lea    -0x10010(%rbp),%rax
shl    $0x8,%rcx
add    %rcx,%rax
mov    -0x14020(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
movslq -0x1401c(%rbp),%rcx
lea    -0x14010(%rbp),%rax
shl    $0x7,%rcx
add    %rcx,%rax
movslq -0x14020(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14020(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14020(%rbp)
jmp    11c9 <main+0x79>
jmp    123a <main+0xea>
mov    -0x1401c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1401c(%rbp)
jmp    11af <main+0x5f>
lea    0xdb6(%rip),%rdi
lea    0xdb8(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x14018(%rbp)
lea    -0x14010(%rbp),%rdi
mov    -0x14018(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4000,%edx
call   1070 <fwrite@plt>
mov    -0x14018(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xd7f(%rip),%rdi
call   1050 <system@plt>
xor    %eax,%eax
add    $0x14020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x14000,%rsp
lea    0xeb1(%rip),%rdi
lea    0xeb2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0x4000(%rsp),%rdi
mov    $0x1,%esi
mov    $0x10000,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
movdqa 0xe66(%rip),%xmm0
nopw   0x0(%rax,%rax,1)
movdqa 0x4010(%rsp,%rax,4),%xmm1
pand   %xmm0,%xmm1
movdqa 0x4000(%rsp,%rax,4),%xmm2
pand   %xmm0,%xmm2
packuswb %xmm1,%xmm2
movdqa %xmm2,(%rsp,%rax,1)
movdqa 0x4030(%rsp,%rax,4),%xmm1
pand   %xmm0,%xmm1
movdqa 0x4020(%rsp,%rax,4),%xmm2
pand   %xmm0,%xmm2
packuswb %xmm1,%xmm2
movdqa %xmm2,0x10(%rsp,%rax,1)
movdqa 0x4050(%rsp,%rax,4),%xmm1
pand   %xmm0,%xmm1
movdqa 0x4040(%rsp,%rax,4),%xmm2
pand   %xmm0,%xmm2
packuswb %xmm1,%xmm2
movdqa %xmm2,0x20(%rsp,%rax,1)
movdqa 0x4070(%rsp,%rax,4),%xmm1
pand   %xmm0,%xmm1
movdqa 0x4060(%rsp,%rax,4),%xmm2
pand   %xmm0,%xmm2
packuswb %xmm1,%xmm2
movdqa %xmm2,0x30(%rsp,%rax,1)
movdqa 0x4090(%rsp,%rax,4),%xmm1
pand   %xmm0,%xmm1
movdqa 0x4080(%rsp,%rax,4),%xmm2
pand   %xmm0,%xmm2
packuswb %xmm1,%xmm2
movdqa %xmm2,0x40(%rsp,%rax,1)
movdqa 0x40b0(%rsp,%rax,4),%xmm1
pand   %xmm0,%xmm1
movdqa 0x40a0(%rsp,%rax,4),%xmm2
pand   %xmm0,%xmm2
packuswb %xmm1,%xmm2
movdqa %xmm2,0x50(%rsp,%rax,1)
movdqa 0x40d0(%rsp,%rax,4),%xmm1
pand   %xmm0,%xmm1
movdqa 0x40c0(%rsp,%rax,4),%xmm2
pand   %xmm0,%xmm2
packuswb %xmm1,%xmm2
movdqa %xmm2,0x60(%rsp,%rax,1)
movdqa 0x40e0(%rsp,%rax,4),%xmm1
pand   %xmm0,%xmm1
packuswb %xmm1,%xmm1
movq   %xmm1,0x70(%rsp,%rax,1)
movzbl 0x40f0(%rsp,%rax,4),%ecx
movzbl 0x40f2(%rsp,%rax,4),%edx
mov    %cl,0x78(%rsp,%rax,1)
mov    %dl,0x79(%rsp,%rax,1)
movzbl 0x40f4(%rsp,%rax,4),%ecx
mov    %cl,0x7a(%rsp,%rax,1)
movzbl 0x40f6(%rsp,%rax,4),%ecx
mov    %cl,0x7b(%rsp,%rax,1)
movzbl 0x40f8(%rsp,%rax,4),%ecx
mov    %cl,0x7c(%rsp,%rax,1)
movzbl 0x40fa(%rsp,%rax,4),%ecx
mov    %cl,0x7d(%rsp,%rax,1)
movzbl 0x40fc(%rsp,%rax,4),%ecx
mov    %cl,0x7e(%rsp,%rax,1)
movzbl 0x40fe(%rsp,%rax,4),%ecx
mov    %cl,0x7f(%rsp,%rax,1)
sub    $0xffffffffffffff80,%rax
cmp    $0x4000,%rax
jne    11a0 <main+0x50>
lea    0xcf2(%rip),%rdi
lea    0xcf4(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x4000,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xccb(%rip),%rdi
call   1050 <system@plt>
xor    %eax,%eax
add    $0x14000,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [8 x i8] c"czp.dat\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [9 x i8] c"czp1.dat\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [13 x i8] c"zsh ex1-2.sh\00"
define i32 @main() {
%1 = alloca [256 x [256 x i8]]
%2 = alloca [128 x [128 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 [128 x [128 x i8]], [128 x [128 x i8]]* %2, i64 0, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 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)
br label %9
9: ; preds = %0, %9
%10 = phi i64 [ 0, %0 ], [ %84, %9 ]
%11 = shl nuw nsw i64 %10, 1
%12 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %1, i64 0, i64 %11, i64 0
%13 = bitcast i8* %12 to <32 x i8>*
%14 = load <32 x i8>, <32 x i8>* %13
%15 = shufflevector <32 x i8> %14, <32 x i8> poison, <16 x i32> <i32 0, i32 2, i32 4, i32 6, i32 8, i32 10, i32 12, i32 14, i32 16, i32 18, i32 20, i32 22, i32 24, i32 26, i32 28, i32 30>
%16 = getelementptr inbounds [128 x [128 x i8]], [128 x [128 x i8]]* %2, i64 0, i64 %10, i64 0
%17 = bitcast i8* %16 to <16 x i8>*
store <16 x i8> %15, <16 x i8>* %17
%18 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %1, i64 0, i64 %11, i64 32
%19 = bitcast i8* %18 to <32 x i8>*
%20 = load <32 x i8>, <32 x i8>* %19
%21 = shufflevector <32 x i8> %20, <32 x i8> poison, <16 x i32> <i32 0, i32 2, i32 4, i32 6, i32 8, i32 10, i32 12, i32 14, i32 16, i32 18, i32 20, i32 22, i32 24, i32 26, i32 28, i32 30>
%22 = getelementptr inbounds [128 x [128 x i8]], [128 x [128 x i8]]* %2, i64 0, i64 %10, i64 16
%23 = bitcast i8* %22 to <16 x i8>*
store <16 x i8> %21, <16 x i8>* %23
%24 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %1, i64 0, i64 %11, i64 64
%25 = bitcast i8* %24 to <32 x i8>*
%26 = load <32 x i8>, <32 x i8>* %25
%27 = shufflevector <32 x i8> %26, <32 x i8> poison, <16 x i32> <i32 0, i32 2, i32 4, i32 6, i32 8, i32 10, i32 12, i32 14, i32 16, i32 18, i32 20, i32 22, i32 24, i32 26, i32 28, i32 30>
%28 = getelementptr inbounds [128 x [128 x i8]], [128 x [128 x i8]]* %2, i64 0, i64 %10, i64 32
%29 = bitcast i8* %28 to <16 x i8>*
store <16 x i8> %27, <16 x i8>* %29
%30 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %1, i64 0, i64 %11, i64 96
%31 = bitcast i8* %30 to <32 x i8>*
%32 = load <32 x i8>, <32 x i8>* %31
%33 = shufflevector <32 x i8> %32, <32 x i8> poison, <16 x i32> <i32 0, i32 2, i32 4, i32 6, i32 8, i32 10, i32 12, i32 14, i32 16, i32 18, i32 20, i32 22, i32 24, i32 26, i32 28, i32 30>
%34 = getelementptr inbounds [128 x [128 x i8]], [128 x [128 x i8]]* %2, i64 0, i64 %10, i64 48
%35 = bitcast i8* %34 to <16 x i8>*
store <16 x i8> %33, <16 x i8>* %35
%36 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %1, i64 0, i64 %11, i64 128
%37 = bitcast i8* %36 to <32 x i8>*
%38 = load <32 x i8>, <32 x i8>* %37
%39 = shufflevector <32 x i8> %38, <32 x i8> poison, <16 x i32> <i32 0, i32 2, i32 4, i32 6, i32 8, i32 10, i32 12, i32 14, i32 16, i32 18, i32 20, i32 22, i32 24, i32 26, i32 28, i32 30>
%40 = getelementptr inbounds [128 x [128 x i8]], [128 x [128 x i8]]* %2, i64 0, i64 %10, i64 64
%41 = bitcast i8* %40 to <16 x i8>*
store <16 x i8> %39, <16 x i8>* %41
%42 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %1, i64 0, i64 %11, i64 160
%43 = bitcast i8* %42 to <32 x i8>*
%44 = load <32 x i8>, <32 x i8>* %43
%45 = shufflevector <32 x i8> %44, <32 x i8> poison, <16 x i32> <i32 0, i32 2, i32 4, i32 6, i32 8, i32 10, i32 12, i32 14, i32 16, i32 18, i32 20, i32 22, i32 24, i32 26, i32 28, i32 30>
%46 = getelementptr inbounds [128 x [128 x i8]], [128 x [128 x i8]]* %2, i64 0, i64 %10, i64 80
%47 = bitcast i8* %46 to <16 x i8>*
store <16 x i8> %45, <16 x i8>* %47
%48 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %1, i64 0, i64 %11, i64 192
%49 = bitcast i8* %48 to <32 x i8>*
%50 = load <32 x i8>, <32 x i8>* %49
%51 = shufflevector <32 x i8> %50, <32 x i8> poison, <16 x i32> <i32 0, i32 2, i32 4, i32 6, i32 8, i32 10, i32 12, i32 14, i32 16, i32 18, i32 20, i32 22, i32 24, i32 26, i32 28, i32 30>
%52 = getelementptr inbounds [128 x [128 x i8]], [128 x [128 x i8]]* %2, i64 0, i64 %10, i64 96
%53 = bitcast i8* %52 to <16 x i8>*
store <16 x i8> %51, <16 x i8>* %53
%54 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %1, i64 0, i64 %11, i64 224
%55 = bitcast i8* %54 to <16 x i8>*
%56 = load <16 x i8>, <16 x i8>* %55
%57 = shufflevector <16 x i8> %56, <16 x i8> poison, <8 x i32> <i32 0, i32 2, i32 4, i32 6, i32 8, i32 10, i32 12, i32 14>
%58 = getelementptr inbounds [128 x [128 x i8]], [128 x [128 x i8]]* %2, i64 0, i64 %10, i64 112
%59 = bitcast i8* %58 to <8 x i8>*
store <8 x i8> %57, <8 x i8>* %59
%60 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %1, i64 0, i64 %11, i64 240
%61 = load i8, i8* %60
%62 = getelementptr inbounds [128 x [128 x i8]], [128 x [128 x i8]]* %2, i64 0, i64 %10, i64 120
store i8 %61, i8* %62
%63 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %1, i64 0, i64 %11, i64 242
%64 = load i8, i8* %63
%65 = getelementptr inbounds [128 x [128 x i8]], [128 x [128 x i8]]* %2, i64 0, i64 %10, i64 121
store i8 %64, i8* %65
%66 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %1, i64 0, i64 %11, i64 244
%67 = load i8, i8* %66
%68 = getelementptr inbounds [128 x [128 x i8]], [128 x [128 x i8]]* %2, i64 0, i64 %10, i64 122
store i8 %67, i8* %68
%69 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %1, i64 0, i64 %11, i64 246
%70 = load i8, i8* %69
%71 = getelementptr inbounds [128 x [128 x i8]], [128 x [128 x i8]]* %2, i64 0, i64 %10, i64 123
store i8 %70, i8* %71
%72 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %1, i64 0, i64 %11, i64 248
%73 = load i8, i8* %72
%74 = getelementptr inbounds [128 x [128 x i8]], [128 x [128 x i8]]* %2, i64 0, i64 %10, i64 124
store i8 %73, i8* %74
%75 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %1, i64 0, i64 %11, i64 250
%76 = load i8, i8* %75
%77 = getelementptr inbounds [128 x [128 x i8]], [128 x [128 x i8]]* %2, i64 0, i64 %10, i64 125
store i8 %76, i8* %77
%78 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %1, i64 0, i64 %11, i64 252
%79 = load i8, i8* %78
%80 = getelementptr inbounds [128 x [128 x i8]], [128 x [128 x i8]]* %2, i64 0, i64 %10, i64 126
store i8 %79, i8* %80
%81 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %1, i64 0, i64 %11, i64 254
%82 = load i8, i8* %81
%83 = getelementptr inbounds [128 x [128 x i8]], [128 x [128 x i8]]* %2, i64 0, i64 %10, i64 127
store i8 %82, i8* %83
%84 = add nuw nsw i64 %10, 1
%85 = icmp eq i64 %84, 128
br i1 %85, label %86, label %9
86: ; preds = %9
%87 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%88 = bitcast [128 x [128 x i8]]* %2 to i8**
%89 = call i32 @fwrite(i8** %88, i32 1, i32 16384, i32* %87)
%90 = tail call i32 @fclose(i32* %87)
%91 = tail call i32 @system(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}