#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*/ z;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(unsigned short *);
size_t fwrite(unsigned short *, int, int, int /*<<< orphan*/ *);
unsigned short *malloc(int);
int /*<<< orphan*/ printf(char *, int, ...);
int main(void) {
  FILE *file;
  size_t ret;
  int i;
  char x[10] = "ABCDEFGHIJ";
  unsigned y[5] = {1, 11, 21, 31, 41};
  unsigned short z[7] = {3, 5, 7, 9, 13, 15, 17};
  unsigned short *zz, *pzz;
  zz = malloc(sizeof(unsigned short) * 2);
  pzz = zz;
  *pzz = 3;
  printf("pzz = %d\n", *pzz);
  pzz++;
  file = fopen("test.bin", "wb");
  ret = fwrite(z, sizeof(z[0]), sizeof(z) / sizeof(z[0]), file);
  fclose(file);
  *x = 0;
  *y = 0;
  file = fopen("test.bin", "rb");
  for (i = 0; i < sizeof(z) / sizeof(z[0]); i++)
    printf("z[%d] = %d\n", i, z[i]);
  fclose(file);
  free(zz);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe8a(%rip),%rax
mov    %rax,-0x26(%rbp)
mov    0xe87(%rip),%ax
mov    %ax,-0x1e(%rbp)
mov    0xe84(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe81(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xe7f(%rip),%eax
mov    %eax,-0x30(%rbp)
mov    0xe79(%rip),%rax
mov    %rax,-0x4e(%rbp)
mov    0xe77(%rip),%eax
mov    %eax,-0x46(%rbp)
mov    0xe71(%rip),%ax
mov    %ax,-0x42(%rbp)
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
movw   $0x3,(%rax)
mov    -0x60(%rbp),%rax
movzwl (%rax),%esi
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x60(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x60(%rbp)
lea    0xe32(%rip),%rdi
lea    0xe34(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x4e(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x2,%esi
mov    $0x7,%edx
call   1080 <fwrite@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movb   $0x0,-0x26(%rbp)
movl   $0x0,-0x40(%rbp)
lea    0xdec(%rip),%rdi
lea    0xdf1(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    $0x7,%rax
jae    129d <main+0x13d>
mov    -0x1c(%rbp),%esi
movslq -0x1c(%rbp),%rax
movzwl -0x4e(%rbp,%rax,2),%edx
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1267 <main+0x107>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0xe96(%rip),%rax
mov    %rax,0x6(%rsp)
mov    0xe84(%rip),%rax
mov    %rax,(%rsp)
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
movw   $0x3,(%rax)
lea    0xe75(%rip),%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe6c(%rip),%r15
lea    0xe6e(%rip),%rsi
mov    %r15,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x2,%esi
mov    $0x7,%edx
mov    %rax,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe42(%rip),%rsi
mov    %r15,%rdi
call   1070 <fopen@plt>
mov    %rax,%r15
movzwl (%rsp),%edx
lea    0xe2f(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movzwl 0x2(%rsp),%edx
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movzwl 0x4(%rsp),%edx
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movzwl 0x6(%rsp),%edx
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movzwl 0x8(%rsp),%edx
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movzwl 0xa(%rsp),%edx
mov    %rbx,%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movzwl 0xc(%rsp),%edx
mov    %rbx,%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.x = [10 x i8] c"ABCDEFGHIJ"
@__const.main.y = [5 x i32] [i32 1, i32 11, i32 21, i32 31, i32 41]
@__const.main.z = [7 x i16] [i16 3, i16 5, i16 7, i16 9, i16 13, i16 15, i16 17]
@.str = [10 x i8] c"pzz = %d\0A\00"
@.str.1 = [9 x i8] c"test.bin\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [12 x i8] c"z[%d] = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i32
%5 = alloca [10 x i8]
%6 = alloca [5 x i32]
%7 = alloca [7 x i16]
%8 = alloca i16*
%9 = alloca i16*
store i32 0, i32* %1
%10 = bitcast [10 x i8]* %5 to i8*
%11 = bitcast [5 x i32]* %6 to i8*
%12 = bitcast [7 x i16]* %7 to i8*
%13 = call i16* @malloc(i32 4)
store i16* %13, i16** %8
%14 = load i16*, i16** %8
store i16* %14, i16** %9
%15 = load i16*, i16** %9
store i16 3, i16* %15
%16 = load i16*, i16** %9
%17 = load i16, i16* %16
%18 = zext i16 %17 to i32
%19 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = load i16*, i16** %9
%21 = getelementptr inbounds i16, i16* %20, i32 1
store i16* %21, i16** %9
%22 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %22, i32** %2
%23 = getelementptr inbounds [7 x i16], [7 x i16]* %7, i64 0, i64 0
%24 = load i32*, i32** %2
%25 = call i64 @fwrite(i16* %23, i32 2, i32 7, i32* %24)
store i64 %25, i64* %3
%26 = load i32*, i32** %2
%27 = call i32 @fclose(i32* %26)
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
store i8 0, i8* %28
%29 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 0
store i32 0, i32* %29
%30 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %30, i32** %2
store i32 0, i32* %4
br label %31
31: ; preds = %43, %0
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = icmp ult i64 %33, 7
br i1 %34, label %35, label %46
35: ; preds = %31
%36 = load i32, i32* %4
%37 = load i32, i32* %4
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [7 x i16], [7 x i16]* %7, i64 0, i64 %38
%40 = load i16, i16* %39
%41 = zext i16 %40 to i32
%42 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %36, i32 %41)
br label %43
43: ; preds = %35
%44 = load i32, i32* %4
%45 = add nsw i32 %44, 1
store i32 %45, i32* %4
br label %31
46: ; preds = %31
%47 = load i32*, i32** %2
%48 = call i32 @fclose(i32* %47)
%49 = load i16*, i16** %8
%50 = call i32 @free(i16* %49)
ret i32 0
}

LLVM IR (-O2):
@__const.main.z = [7 x i16] [i16 3, i16 5, i16 7, i16 9, i16 13, i16 15, i16 17]
@.str = [10 x i8] c"pzz = %d\0A\00"
@.str.1 = [9 x i8] c"test.bin\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [12 x i8] c"z[%d] = %d\0A\00"
define i32 @main() {
%1 = alloca [7 x i16]
%2 = bitcast [7 x i16]* %1 to i8*
%3 = tail call i16* @malloc(i32 4)
store i16 3, i16* %3
%4 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 3)
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%6 = getelementptr inbounds [7 x i16], [7 x i16]* %1, i64 0, i64 0
%7 = call i64 @fwrite(i16* %6, i32 2, i32 7, i32* %5)
%8 = tail call i32 @fclose(i32* %5)
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%10 = load i16, i16* %6
%11 = zext i16 %10 to i32
%12 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 0, i32 %11)
%13 = getelementptr inbounds [7 x i16], [7 x i16]* %1, i64 0, i64 1
%14 = load i16, i16* %13
%15 = zext i16 %14 to i32
%16 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 1, i32 %15)
%17 = getelementptr inbounds [7 x i16], [7 x i16]* %1, i64 0, i64 2
%18 = load i16, i16* %17
%19 = zext i16 %18 to i32
%20 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 2, i32 %19)
%21 = getelementptr inbounds [7 x i16], [7 x i16]* %1, i64 0, i64 3
%22 = load i16, i16* %21
%23 = zext i16 %22 to i32
%24 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 3, i32 %23)
%25 = getelementptr inbounds [7 x i16], [7 x i16]* %1, i64 0, i64 4
%26 = load i16, i16* %25
%27 = zext i16 %26 to i32
%28 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 4, i32 %27)
%29 = getelementptr inbounds [7 x i16], [7 x i16]* %1, i64 0, i64 5
%30 = load i16, i16* %29
%31 = zext i16 %30 to i32
%32 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 5, i32 %31)
%33 = getelementptr inbounds [7 x i16], [7 x i16]* %1, i64 0, i64 6
%34 = load i16, i16* %33
%35 = zext i16 %34 to i32
%36 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 6, i32 %35)
%37 = tail call i32 @fclose(i32* %9)
%38 = tail call i32 @free(i16* %3)
ret i32 0
}