#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, float *);
int /*<<< orphan*/ fwrite(float *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
void main(int argc, char **argv) {
  int a = 0, dim;
  char *infile, *outfile;
  float fval;
  FILE *afp, *bfp;
  printf("\nConvert ASCII-data into binary-data\n");
  if (argc != 4) {
    printf("  ** Usage: %s <ascii-file> <dimension> <binary-file>\n\n",
           argv[0]);
    exit(-2);
  }
  infile = argv[1];
  dim = atoi(argv[2]);
  outfile = argv[3];
  afp = fopen(infile, "rb");
  if (!afp) {
    perror("cannot open input file\n");
    exit(-1);
  }
  bfp = fopen(outfile, "wb");
  if (!bfp) {
    perror("cannot open output file\n");
    exit(-1);
  }
  printf("Input file opened - converting...\n");
  while (fscanf(afp, "%f", &fval) > 0) {
    fwrite(&fval, sizeof(float), 1, bfp);
    a++;
    if ((a % (1000 * dim)) == 0) {
      printf("\n%d ", (int)(a / dim));
      fflush(stdout);
    }
  }
  printf("\r%d   \n\n", (int)(a / dim));
  fflush(stdout);
  fclose(afp);
  fclose(bfp);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x4,-0x4(%rbp)
je     11dd <main+0x4d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xfffffffe,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    123a <main+0xaa>
lea    0xe36(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x28(%rbp),%rdi
lea    0xe34(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    126f <main+0xdf>
lea    0xe1c(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
lea    0xe30(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   1050 <fscanf@plt>
cmp    $0x0,%rax
jle    12fb <main+0x16b>
mov    -0x40(%rbp),%rcx
lea    -0x2c(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   10b0 <fwrite@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
imul   $0x3e8,-0x18(%rbp),%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12f6 <main+0x166>
mov    -0x14(%rbp),%eax
cltd
idivl  -0x18(%rbp)
mov    %eax,%esi
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2cf1(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
jmp    127d <main+0xed>
mov    -0x14(%rbp),%eax
cltd
idivl  -0x18(%rbp)
mov    %eax,%esi
lea    0xdb5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2cc7(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xec9(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x4,%ebp
jne    12f0 <main+0x150>
mov    0x8(%rbx),%rbp
mov    0x10(%rbx),%rdi
call   10a0 <atoi@plt>
mov    %eax,(%rsp)
mov    0x18(%rbx),%rbx
lea    0xe58(%rip),%rsi
mov    %rbp,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     130b <main+0x16b>
mov    %rax,%r14
lea    0xe58(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1314 <main+0x174>
mov    %rax,%r12
lea    0xe8f(%rip),%rdi
call   1030 <puts@plt>
lea    0xe4d(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %r14,%rdi
call   1060 <fscanf@plt>
test   %rax,%rax
jle    12ab <main+0x10b>
imul   $0x3e8,(%rsp),%r15d
lea    0x4(%rsp),%rbp
lea    0xe27(%rip),%r13
xor    %ebx,%ebx
jmp    1263 <main+0xc3>
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1060 <fscanf@plt>
test   %rax,%rax
jle    12ad <main+0x10d>
mov    %rbp,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   10c0 <fwrite@plt>
add    $0x1,%ebx
mov    %ebx,%eax
cltd
idiv   %r15d
test   %edx,%edx
jne    1250 <main+0xb0>
mov    %ebx,%eax
cltd
idivl  (%rsp)
lea    0xde0(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2d3e(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
jmp    1250 <main+0xb0>
xor    %ebx,%ebx
mov    %ebx,%eax
cltd
idivl  (%rsp)
lea    0xdbd(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0xd06(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xfffffffe,%edi
call   10b0 <exit@plt>
lea    0xd29(%rip),%rdi
jmp    131b <main+0x17b>
lea    0xd3b(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [38 x i8] c"\0AConvert ASCII-data into binary-data\0A\00"
@.str.1 = [56 x i8] c" ** Usage: %s <ascii-file> <dimension> <binary-file>\0A\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [24 x i8] c"cannot open input file\0A\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [25 x i8] c"cannot open output file\0A\00"
@.str.6 = [35 x i8] c"Input file opened - converting...\0A\00"
@.str.7 = [3 x i8] c"%f\00"
@.str.8 = [5 x i8] c"\0A%d \00"
@stdout = global i32 0
@.str.9 = [9 x i8] c"\0D%d \0A\0A\00"
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca float
%10 = alloca i32*
%11 = alloca i32*
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32 0, i32* %5
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* %3
%14 = icmp ne i32 %13, 4
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i8**, i8*** %4
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 -2)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %4
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %7
%25 = load i8**, i8*** %4
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %6
%29 = load i8**, i8*** %4
%30 = getelementptr inbounds i8*, i8** %29, i64 3
%31 = load i8*, i8** %30
store i8* %31, i8** %8
%32 = load i8*, i8** %7
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %33, i32** %10
%34 = load i32*, i32** %10
%35 = icmp ne i32* %34, null
br i1 %35, label %39, label %36
36: ; preds = %21
%37 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 @exit(i32 -1)
unreachable
39: ; preds = %21
%40 = load i8*, i8** %8
%41 = call i32* @fopen(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %41, i32** %11
%42 = load i32*, i32** %11
%43 = icmp ne i32* %42, null
br i1 %43, label %47, label %44
44: ; preds = %39
%45 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%46 = call i32 @exit(i32 -1)
unreachable
47: ; preds = %39
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0))
br label %49
49: ; preds = %70, %47
%50 = load i32*, i32** %10
%51 = call i64 @fscanf(i32* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), float* %9)
%52 = icmp sgt i64 %51, 0
br i1 %52, label %53, label %71
53: ; preds = %49
%54 = load i32*, i32** %11
%55 = call i32 @fwrite(float* %9, i32 4, i32 1, i32* %54)
%56 = load i32, i32* %5
%57 = add nsw i32 %56, 1
store i32 %57, i32* %5
%58 = load i32, i32* %5
%59 = load i32, i32* %6
%60 = mul nsw i32 1000, %59
%61 = srem i32 %58, %60
%62 = icmp eq i32 %61, 0
br i1 %62, label %63, label %70
63: ; preds = %53
%64 = load i32, i32* %5
%65 = load i32, i32* %6
%66 = sdiv i32 %64, %65
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32 %66)
%68 = load i32, i32* @stdout
%69 = call i32 @fflush(i32 %68)
br label %70
70: ; preds = %63, %53
br label %49
71: ; preds = %49
%72 = load i32, i32* %5
%73 = load i32, i32* %6
%74 = sdiv i32 %72, %73
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i32 %74)
%76 = load i32, i32* @stdout
%77 = call i32 @fflush(i32 %76)
%78 = load i32*, i32** %10
%79 = call i32 @fclose(i32* %78)
%80 = load i32*, i32** %11
%81 = call i32 @fclose(i32* %80)
ret void
}

LLVM IR (-O2):
@.str.1 = [56 x i8] c" ** Usage: %s <ascii-file> <dimension> <binary-file>\0A\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [24 x i8] c"cannot open input file\0A\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [25 x i8] c"cannot open output file\0A\00"
@.str.7 = [3 x i8] c"%f\00"
@.str.8 = [5 x i8] c"\0A%d \00"
@stdout = global i32 0
@.str.9 = [9 x i8] c"\0D%d \0A\0A\00"
@str = [37 x i8] c"\0AConvert ASCII-data into binary-data\00"
@str.10 = [34 x i8] c"Input file opened - converting...\00"
define void @main(i32 %0, i8** nocapture %1) {
%3 = alloca float
%4 = bitcast float* %3 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%6 = icmp eq i32 %0, 4
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = load i8*, i8** %1
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 -2)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = getelementptr inbounds i8*, i8** %1, i64 3
%18 = load i8*, i8** %17
%19 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %11
%22 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%23 = tail call i32 @exit(i32 -1)
unreachable
24: ; preds = %11
%25 = tail call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%29 = tail call i32 @exit(i32 -1)
unreachable
30: ; preds = %24
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.10, i64 0, i64 0))
%32 = call i64 @fscanf(i32* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), float* %3)
%33 = icmp sgt i64 %32, 0
br i1 %33, label %34, label %50
34: ; preds = %30
%35 = mul nsw i32 %16, 1000
br label %36
36: ; preds = %34, %47
%37 = phi i32 [ 0, %34 ], [ %39, %47 ]
%38 = call i32 @fwrite(float* %3, i32 4, i32 1, i32* %25)
%39 = add nuw nsw i32 %37, 1
%40 = srem i32 %39, %35
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %36
%43 = sdiv i32 %39, %16
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32 %43)
%45 = load i32, i32* @stdout
%46 = call i32 @fflush(i32 %45)
br label %47
47: ; preds = %42, %36
%48 = call i64 @fscanf(i32* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), float* %3)
%49 = icmp sgt i64 %48, 0
br i1 %49, label %36, label %50
50: ; preds = %47, %30
%51 = phi i32 [ 0, %30 ], [ %39, %47 ]
%52 = sdiv i32 %51, %16
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i32 %52)
%54 = load i32, i32* @stdout
%55 = call i32 @fflush(i32 %54)
%56 = call i32 @fclose(i32* %19)
%57 = call i32 @fclose(i32* %25)
ret void
}