#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*/ assert(int /*<<< orphan*/);
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int fread(short *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  FILE *fraw, *fheader;
  int i, samples, ret;
  short sam;
  if (argc != 5) {
    printf("usage: %s inputRawFile outputHeaderFile arrayName samples\n",
           argv[0]);
    exit(1);
  }
  fraw = fopen(argv[1], "rb");
  assert(fraw != NULL);
  fheader = fopen(argv[2], "wt");
  assert(fheader != NULL);
  samples = atoi(argv[4]);
  fprintf(fheader, "short %s[] = {\n", argv[3]);
  for (i = 0; i < samples - 1; i++) {
    ret = fread(&sam, sizeof(short), 1, fraw);
    fprintf(fheader, "%d,\n", sam);
  }
  ret = fread(&sam, sizeof(short), 1, fraw);
  fprintf(fheader, "%d\n};\n", sam);
  fclose(fraw);
  fclose(fheader);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x5,-0x8(%rbp)
je     11bd <main+0x3d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe52(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe6f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe48(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
lea    0xe0d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x28(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1291 <main+0x111>
mov    -0x18(%rbp),%rcx
lea    -0x2e(%rbp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
movswl -0x2e(%rbp),%edx
lea    0xdd5(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1242 <main+0xc2>
mov    -0x18(%rbp),%rcx
lea    -0x2e(%rbp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
movswl -0x2e(%rbp),%edx
lea    0xd9c(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
cmp    $0x5,%edi
jne    1288 <main+0x108>
mov    0x8(%r15),%rdi
lea    0xe98(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1060 <assert@plt>
mov    0x10(%r15),%rdi
lea    0xe7a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1060 <assert@plt>
mov    0x20(%r15),%rdi
call   1090 <atoi@plt>
mov    %eax,%ebp
mov    0x18(%r15),%rdx
lea    0xe51(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <fprintf@plt>
cmp    $0x2,%ebp
jl     123c <main+0xbc>
add    $0xffffffff,%ebp
lea    0xe(%rsp),%r15
lea    0xe43(%rip),%r12
xchg   %ax,%ax
mov    %r15,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
movswl 0xe(%rsp),%edx
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
add    $0xffffffff,%ebp
jne    1210 <main+0x90>
lea    0xe(%rsp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
movswl 0xe(%rsp),%edx
lea    0xdf7(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r15),%rsi
lea    0xd6e(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [59 x i8] c"usage: %s inputRawFile outputHeaderFile arrayName samples\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [3 x i8] c"wt\00"
@.str.3 = [16 x i8] c"short %s[] = {\0A\00"
@.str.4 = [5 x i8] c"%d,\0A\00"
@.str.5 = [7 x i8] c"%d\0A};\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i16
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 5
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %6
%25 = load i32*, i32** %6
%26 = icmp ne i32* %25, null
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %32, i32** %7
%33 = load i32*, i32** %7
%34 = icmp ne i32* %33, null
%35 = zext i1 %34 to i32
%36 = call i32 @assert(i32 %35)
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 4
%39 = load i8*, i8** %38
%40 = call i32 @atoi(i8* %39)
store i32 %40, i32* %9
%41 = load i32*, i32** %7
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 3
%44 = load i8*, i8** %43
%45 = call i32 (i32*, i8*, ...) @fprintf(i32* %41, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %44)
store i32 0, i32* %8
br label %46
46: ; preds = %58, %20
%47 = load i32, i32* %8
%48 = load i32, i32* %9
%49 = sub nsw i32 %48, 1
%50 = icmp slt i32 %47, %49
br i1 %50, label %51, label %61
51: ; preds = %46
%52 = load i32*, i32** %6
%53 = call i32 @fread(i16* %11, i32 2, i32 1, i32* %52)
store i32 %53, i32* %10
%54 = load i32*, i32** %7
%55 = load i16, i16* %11
%56 = sext i16 %55 to i32
%57 = call i32 (i32*, i8*, ...) @fprintf(i32* %54, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %56)
br label %58
58: ; preds = %51
%59 = load i32, i32* %8
%60 = add nsw i32 %59, 1
store i32 %60, i32* %8
br label %46
61: ; preds = %46
%62 = load i32*, i32** %6
%63 = call i32 @fread(i16* %11, i32 2, i32 1, i32* %62)
store i32 %63, i32* %10
%64 = load i32*, i32** %7
%65 = load i16, i16* %11
%66 = sext i16 %65 to i32
%67 = call i32 (i32*, i8*, ...) @fprintf(i32* %64, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %66)
%68 = load i32*, i32** %6
%69 = call i32 @fclose(i32* %68)
%70 = load i32*, i32** %7
%71 = call i32 @fclose(i32* %70)
ret i32 0
}

LLVM IR (-O2):
@.str = [59 x i8] c"usage: %s inputRawFile outputHeaderFile arrayName samples\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [3 x i8] c"wt\00"
@.str.3 = [16 x i8] c"short %s[] = {\0A\00"
@.str.4 = [5 x i8] c"%d,\0A\00"
@.str.5 = [7 x i8] c"%d\0A};\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i16
%4 = bitcast i16* %3 to i8*
%5 = icmp eq i32 %0, 5
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp ne i32* %13, null
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp ne i32* %19, null
%21 = zext i1 %20 to i32
%22 = tail call i32 @assert(i32 %21)
%23 = getelementptr inbounds i8*, i8** %1, i64 4
%24 = load i8*, i8** %23
%25 = tail call i32 @atoi(i8* %24)
%26 = getelementptr inbounds i8*, i8** %1, i64 3
%27 = load i8*, i8** %26
%28 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %27)
%29 = add i32 %25, -1
%30 = icmp sgt i32 %25, 1
br i1 %30, label %31, label %39
31: ; preds = %10, %31
%32 = phi i32 [ %37, %31 ], [ 0, %10 ]
%33 = call i32 @fread(i16* %3, i32 2, i32 1, i32* %13)
%34 = load i16, i16* %3
%35 = sext i16 %34 to i32
%36 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %35)
%37 = add nuw nsw i32 %32, 1
%38 = icmp eq i32 %37, %29
br i1 %38, label %39, label %31
39: ; preds = %31, %10
%40 = call i32 @fread(i16* %3, i32 2, i32 1, i32* %13)
%41 = load i16, i16* %3
%42 = sext i16 %41 to i32
%43 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %42)
%44 = tail call i32 @fclose(i32* %13)
%45 = tail call i32 @fclose(i32* %19)
ret i32 0
}