#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int fscanf(int /*<<< orphan*/ *, char *, double *);
int /*<<< orphan*/ fwrite(float *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ reverse_float(float);
int /*<<< orphan*/ sprintf(char *, char *, char *, char const *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
int main(int argc, char **argv) {
  const char *binfile = "fedstl.bin";
  const char *datfile = "fedstl.dat";
  char datpath[512];
  int swap_ends = 0;
  FILE *fdat, *fbin;
  double xx;
  float x;
  if (argc == 2 && !strcmp(argv[1], "--swap-ends")) {
    swap_ends = 1;
    argc--;
  } else if (argc == 3 && !strcmp(argv[2], "--swap-ends")) {
    swap_ends = 1;
    argc--;
  }
  if (swap_ends) {
    puts("*** making data file with swapped endianness");
  }
  if (argc > 1) {
    sprintf(datpath, "%s/%s", argv[1], datfile);
  } else {
    strcpy(datpath, datfile);
  }
  fdat = fopen(datpath, "r");
  if (fdat == NULL) {
    fprintf(stderr, "Couldn't open %s\n", datfile);
    exit(EXIT_FAILURE);
  }
  fbin = fopen(binfile, "wb");
  if (fbin == NULL) {
    fprintf(stderr, "Couldn't open %s\n", binfile);
    exit(EXIT_FAILURE);
  }
  while (fscanf(fdat, "%lf", &xx) == 1) {
    x = xx;
    if (swap_ends) {
      reverse_float(x);
    }
    fwrite(&x, sizeof x, 1, fbin);
  }
  fclose(fbin);
  fclose(fdat);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe30(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe30(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x224(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1228 <main+0x78>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe14(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    1228 <main+0x78>
movl   $0x1,-0x224(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1267 <main+0xb7>
cmpl   $0x3,-0x8(%rbp)
jne    1262 <main+0xb2>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdd5(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    1262 <main+0xb2>
movl   $0x1,-0x224(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1267 <main+0xb7>
cmpl   $0x0,-0x224(%rbp)
je     1280 <main+0xd0>
lea    0xda7(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x1,-0x8(%rbp)
jle    12ae <main+0xfe>
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x20(%rbp),%rcx
lea    0xdab(%rip),%rsi
call   10b0 <sprintf@plt>
jmp    12be <main+0x10e>
lea    -0x220(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x220(%rbp),%rdi
lea    0xd89(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x230(%rbp)
cmpq   $0x0,-0x230(%rbp)
jne    130d <main+0x15d>
mov    0x2cf3(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xd5d(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2cd2(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    0xd51(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x238(%rbp)
cmpq   $0x0,-0x238(%rbp)
jne    1359 <main+0x1a9>
mov    0x2ca7(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xd11(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2c86(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
jmp    135e <main+0x1ae>
mov    -0x230(%rbp),%rdi
lea    0xd00(%rip),%rsi
lea    -0x240(%rbp),%rdx
call   1070 <fscanf@plt>
cmp    $0x1,%eax
jne    13d1 <main+0x221>
movsd  -0x240(%rbp),%xmm0
ff
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x244(%rbp)
ff
cmpl   $0x0,-0x224(%rbp)
je     13af <main+0x1ff>
movss  -0x244(%rbp),%xmm0
ff
call   1050 <reverse_float@plt>
mov    -0x238(%rbp),%rcx
lea    -0x244(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   10d0 <fwrite@plt>
jmp    135e <main+0x1ae>
mov    -0x238(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x230(%rbp),%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %rsi,%r14
cmp    $0x3,%edi
je     11f1 <main+0x41>
mov    %edi,%ebx
mov    $0x1,%bpl
cmp    $0x2,%edi
jne    121b <main+0x6b>
mov    0x8(%r14),%rdi
lea    0xe38(%rip),%rsi
call   1080 <strcmp@plt>
mov    $0x1,%bpl
test   %eax,%eax
jne    1220 <main+0x70>
mov    $0x1,%ebx
jmp    120d <main+0x5d>
mov    0x10(%r14),%rdi
lea    0xe1a(%rip),%rsi
call   1080 <strcmp@plt>
mov    $0x1,%bpl
test   %eax,%eax
jne    1220 <main+0x70>
mov    $0x2,%ebx
lea    0xe0e(%rip),%rdi
call   1040 <puts@plt>
xor    %ebp,%ebp
cmp    $0x2,%ebx
jl     123e <main+0x8e>
mov    0x8(%r14),%rdx
lea    0xe24(%rip),%rsi
lea    0xdd9(%rip),%rcx
lea    0x10(%rsp),%rdi
call   10b0 <sprintf@plt>
jmp    124f <main+0x9f>
lea    0xdc6(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1030 <strcpy@plt>
lea    0xdff(%rip),%rsi
lea    0x10(%rsp),%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1328 <main+0x178>
mov    %rax,%r14
lea    0xd8d(%rip),%rdi
lea    0xdef(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1341 <main+0x191>
mov    %rax,%rbx
lea    0xdda(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %r14,%rdi
call   1070 <fscanf@plt>
cmp    $0x1,%eax
jne    1304 <main+0x154>
lea    0x4(%rsp),%r15
lea    0xdbc(%rip),%r12
lea    0x8(%rsp),%r13
jmp    12e8 <main+0x138>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10d0 <fwrite@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1070 <fscanf@plt>
cmp    $0x1,%eax
jne    1304 <main+0x154>
movsd  0x8(%rsp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x4(%rsp)
test   %bpl,%bpl
jne    12c0 <main+0x110>
call   1050 <reverse_float@plt>
jmp    12c0 <main+0x110>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cb1(%rip),%rax
mov    (%rax),%edi
lea    0xd1f(%rip),%rsi
lea    0xccc(%rip),%rdx
jmp    1358 <main+0x1a8>
mov    0x2c98(%rip),%rax
mov    (%rax),%edi
lea    0xd06(%rip),%rsi
lea    0xca8(%rip),%rdx
call   1090 <fprintf@plt>
mov    0x2c74(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"fedstl.bin\00"
@.str.1 = [11 x i8] c"fedstl.dat\00"
@.str.2 = [12 x i8] c"--swap-ends\00"
@.str.3 = [45 x i8] c"*** making data file with swapped endianness\00"
@.str.4 = [6 x i8] c"%s/%s\00"
@.str.5 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.6 = [18 x i8] c"Couldn't open %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.7 = [3 x i8] c"wb\00"
@.str.8 = [4 x i8] c"%lf\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [512 x i8]
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca double
%13 = alloca float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8** %7
store i32 0, i32* %9
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 2
br i1 %15, label %16, label %25
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @strcmp(i8* %19, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp ne i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %16
store i32 1, i32* %9
%23 = load i32, i32* %4
%24 = add nsw i32 %23, -1
store i32 %24, i32* %4
br label %38
25: ; preds = %16, %2
%26 = load i32, i32* %4
%27 = icmp eq i32 %26, 3
br i1 %27, label %28, label %37
28: ; preds = %25
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i32 @strcmp(i8* %31, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%33 = icmp ne i32 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %28
store i32 1, i32* %9
%35 = load i32, i32* %4
%36 = add nsw i32 %35, -1
store i32 %36, i32* %4
br label %37
37: ; preds = %34, %28, %25
br label %38
38: ; preds = %37, %22
%39 = load i32, i32* %9
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = call i32 @puts(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0))
br label %43
43: ; preds = %41, %38
%44 = load i32, i32* %4
%45 = icmp sgt i32 %44, 1
br i1 %45, label %46, label %53
46: ; preds = %43
%47 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 1
%50 = load i8*, i8** %49
%51 = load i8*, i8** %7
%52 = call i32 @sprintf(i8* %47, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %50, i8* %51)
br label %57
53: ; preds = %43
%54 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%55 = load i8*, i8** %7
%56 = call i32 @strcpy(i8* %54, i8* %55)
br label %57
57: ; preds = %53, %46
%58 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%59 = call i32* @fopen(i8* %58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %59, i32** %10
%60 = load i32*, i32** %10
%61 = icmp eq i32* %60, null
br i1 %61, label %62, label %68
62: ; preds = %57
%63 = load i32, i32* @stderr
%64 = load i8*, i8** %7
%65 = call i32 @fprintf(i32 %63, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %64)
%66 = load i32, i32* @EXIT_FAILURE
%67 = call i32 @exit(i32 %66)
unreachable
68: ; preds = %57
%69 = load i8*, i8** %6
%70 = call i32* @fopen(i8* %69, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
store i32* %70, i32** %11
%71 = load i32*, i32** %11
%72 = icmp eq i32* %71, null
br i1 %72, label %73, label %79
73: ; preds = %68
%74 = load i32, i32* @stderr
%75 = load i8*, i8** %6
%76 = call i32 @fprintf(i32 %74, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %75)
%77 = load i32, i32* @EXIT_FAILURE
%78 = call i32 @exit(i32 %77)
unreachable
79: ; preds = %68
br label %80
80: ; preds = %92, %79
%81 = load i32*, i32** %10
%82 = call i32 @fscanf(i32* %81, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), double* %12)
%83 = icmp eq i32 %82, 1
br i1 %83, label %84, label %95
84: ; preds = %80
%85 = load double, double* %12
%86 = fptrunc double %85 to float
store float %86, float* %13
%87 = load i32, i32* %9
%88 = icmp ne i32 %87, 0
br i1 %88, label %89, label %92
89: ; preds = %84
%90 = load float, float* %13
%91 = call i32 @reverse_float(float %90)
br label %92
92: ; preds = %89, %84
%93 = load i32*, i32** %11
%94 = call i32 @fwrite(float* %13, i32 4, i32 1, i32* %93)
br label %80
95: ; preds = %80
%96 = load i32*, i32** %11
%97 = call i32 @fclose(i32* %96)
%98 = load i32*, i32** %10
%99 = call i32 @fclose(i32* %98)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"fedstl.bin\00"
@.str.1 = [11 x i8] c"fedstl.dat\00"
@.str.2 = [12 x i8] c"--swap-ends\00"
@.str.3 = [45 x i8] c"*** making data file with swapped endianness\00"
@.str.4 = [6 x i8] c"%s/%s\00"
@.str.5 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.6 = [18 x i8] c"Couldn't open %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.7 = [3 x i8] c"wb\00"
@.str.8 = [4 x i8] c"%lf\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8]
%4 = alloca double
%5 = alloca float
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%7 = bitcast double* %4 to i8*
%8 = bitcast float* %5 to i8*
switch i32 %0, label %22 [
i32 2, label %9
i32 3, label %14
]
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @strcmp(i8* dereferenceable(1) %11, i8* dereferenceable(12) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i32 %12, 0
br i1 %13, label %19, label %26
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i32 @strcmp(i8* dereferenceable(1) %16, i8* dereferenceable(12) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %9, %14
%20 = phi i32 [ 2, %14 ], [ 1, %9 ]
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %2, %19
%23 = phi i32 [ %20, %19 ], [ %0, %2 ]
%24 = phi i1 [ false, %19 ], [ true, %2 ]
%25 = icmp sgt i32 %23, 1
br i1 %25, label %26, label %31
26: ; preds = %9, %14, %22
%27 = phi i1 [ %24, %22 ], [ true, %14 ], [ true, %9 ]
%28 = getelementptr inbounds i8*, i8** %1, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %29, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %33
31: ; preds = %22
%32 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %31, %26
%34 = phi i1 [ %24, %31 ], [ %27, %26 ]
%35 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %42
37: ; preds = %33
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %33
%43 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%44 = icmp eq i32* %43, null
br i1 %44, label %48, label %45
45: ; preds = %42
%46 = call i32 @fscanf(i32* %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), double* %4)
%47 = icmp eq i32 %46, 1
br i1 %47, label %53, label %62
48: ; preds = %42
%49 = load i32, i32* @stderr
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%51 = load i32, i32* @EXIT_FAILURE
%52 = call i32 @exit(i32 %51)
unreachable
53: ; preds = %45, %58
%54 = load double, double* %4
%55 = fptrunc double %54 to float
store float %55, float* %5
br i1 %34, label %58, label %56
56: ; preds = %53
%57 = call i32 @reverse_float(float %55)
br label %58
58: ; preds = %56, %53
%59 = call i32 @fwrite(float* %5, i32 4, i32 1, i32* %43)
%60 = call i32 @fscanf(i32* %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), double* %4)
%61 = icmp eq i32 %60, 1
br i1 %61, label %53, label %62
62: ; preds = %58, %45
%63 = call i32 @fclose(i32* %43)
%64 = call i32 @fclose(i32* %35)
ret i32 0
}