#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 /*<<< orphan*/ fread(short *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  FILE *fraw, *fheader;
  int i, samples;
  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++) {
    fread(&sam, sizeof(short), 1, fraw);
    fprintf(fheader, "%d,\n", sam);
  }
  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    128e <main+0x10e>
mov    -0x18(%rbp),%rcx
lea    -0x2a(%rbp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x20(%rbp),%rdi
movswl -0x2a(%rbp),%edx
lea    0xdd8(%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    -0x2a(%rbp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x20(%rbp),%rdi
movswl -0x2a(%rbp),%edx
lea    0xda2(%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 i16
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 5
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %6
%24 = load i32*, i32** %6
%25 = icmp ne i32* %24, null
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %31, i32** %7
%32 = load i32*, i32** %7
%33 = icmp ne i32* %32, null
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 4
%38 = load i8*, i8** %37
%39 = call i32 @atoi(i8* %38)
store i32 %39, i32* %9
%40 = load i32*, i32** %7
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 3
%43 = load i8*, i8** %42
%44 = call i32 (i32*, i8*, ...) @fprintf(i32* %40, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %43)
store i32 0, i32* %8
br label %45
45: ; preds = %57, %19
%46 = load i32, i32* %8
%47 = load i32, i32* %9
%48 = sub nsw i32 %47, 1
%49 = icmp slt i32 %46, %48
br i1 %49, label %50, label %60
50: ; preds = %45
%51 = load i32*, i32** %6
%52 = call i32 @fread(i16* %10, i32 2, i32 1, i32* %51)
%53 = load i32*, i32** %7
%54 = load i16, i16* %10
%55 = sext i16 %54 to i32
%56 = call i32 (i32*, i8*, ...) @fprintf(i32* %53, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %55)
br label %57
57: ; preds = %50
%58 = load i32, i32* %8
%59 = add nsw i32 %58, 1
store i32 %59, i32* %8
br label %45
60: ; preds = %45
%61 = load i32*, i32** %6
%62 = call i32 @fread(i16* %10, i32 2, i32 1, i32* %61)
%63 = load i32*, i32** %7
%64 = load i16, i16* %10
%65 = sext i16 %64 to i32
%66 = call i32 (i32*, i8*, ...) @fprintf(i32* %63, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %65)
%67 = load i32*, i32** %6
%68 = call i32 @fclose(i32* %67)
%69 = load i32*, i32** %7
%70 = call i32 @fclose(i32* %69)
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
}