#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(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ readBinaryDigitsInASCIIFormat(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ readHexDigitsInBinaryFormat(int /*<<< orphan*/ *);
int /*<<< orphan*/ scanf(char *, int *);
void fileBasedBitStreams(char *streamFile) {
  FILE *fp;
  int mode;
  printf("   Input File Format:\n");
  printf("    [0] ASCII - A sequence of ASCII 0's and 1's\n");
  printf("    [1] Binary - Each byte in data file contains 8 bits of data\n\n");
  printf("   Select input mode:  ");
  scanf("%1d", &mode);
  printf("\n");
  if (mode == 0) {
    if ((fp = fopen(streamFile, "r")) == NULL) {
      printf("ERROR IN FUNCTION fileBasedBitStreams:  file %s could not be "
             "opened.\n",
             streamFile);
      exit(-1);
    }
    readBinaryDigitsInASCIIFormat(fp, streamFile);
    fclose(fp);
  } else if (mode == 1) {
    if ((fp = fopen(streamFile, "rb")) == NULL) {
      printf("ERROR IN FUNCTION fileBasedBitStreams:  file %s could not be "
             "opened.\n",
             streamFile);
      exit(-1);
    }
    readHexDigitsInBinaryFormat(fp);
    fclose(fp);
  }
}


x86 assembly (clang, -O0):
<fileBasedBitStreams>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xedd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xee7(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1060 <scanf@plt>
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
jne    1231 <fileBasedBitStreams+0xc1>
mov    -0x8(%rbp),%rdi
lea    0xebf(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1216 <fileBasedBitStreams+0xa6>
mov    -0x8(%rbp),%rsi
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <readBinaryDigitsInASCIIFormat@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
jmp    128c <fileBasedBitStreams+0x11c>
cmpl   $0x1,-0x14(%rbp)
jne    1287 <fileBasedBitStreams+0x117>
mov    -0x8(%rbp),%rdi
lea    0xea8(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1275 <fileBasedBitStreams+0x105>
mov    -0x8(%rbp),%rsi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1070 <readHexDigitsInBinaryFormat@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
jmp    128c <fileBasedBitStreams+0x11c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fileBasedBitStreams>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xec9(%rip),%rdi
call   1040 <puts@plt>
lea    0xed3(%rip),%rdi
call   1040 <puts@plt>
lea    0xef7(%rip),%rdi
call   1040 <puts@plt>
lea    0xe3e(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe48(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1080 <scanf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x4(%rsp),%eax
cmp    $0x1,%eax
je     1215 <fileBasedBitStreams+0x85>
test   %eax,%eax
jne    123c <fileBasedBitStreams+0xac>
lea    0xe24(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1244 <fileBasedBitStreams+0xb4>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <readBinaryDigitsInASCIIFormat@plt>
jmp    1234 <fileBasedBitStreams+0xa4>
lea    0xe48(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1244 <fileBasedBitStreams+0xb4>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <readHexDigitsInBinaryFormat@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdd3(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [23 x i8] c" Input File Format:\0A\00"
@.str.1 = [49 x i8] c" [0] ASCII - A sequence of ASCII 0's and 1's\0A\00"
@.str.2 = [66 x i8] c" [1] Binary - Each byte in data file contains 8 bits of data\0A\0A\00"
@.str.3 = [24 x i8] c" Select input mode: \00"
@.str.4 = [4 x i8] c"%1d\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [2 x i8] c"r\00"
@.str.7 = [70 x i8] c"ERROR IN FUNCTION fileBasedBitStreams: file %s could not be opened.\0A\00"
@.str.8 = [3 x i8] c"rb\00"
define void @fileBasedBitStreams(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
store i8* %0, i8** %2
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %4)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %27
13: ; preds = %1
%14 = load i8*, i8** %2
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %15, i32** %3
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load i8*, i8** %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.7, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 -1)
unreachable
21: ; preds = %13
%22 = load i32*, i32** %3
%23 = load i8*, i8** %2
%24 = call i32 @readBinaryDigitsInASCIIFormat(i32* %22, i8* %23)
%25 = load i32*, i32** %3
%26 = call i32 @fclose(i32* %25)
br label %44
27: ; preds = %1
%28 = load i32, i32* %4
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %43
30: ; preds = %27
%31 = load i8*, i8** %2
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
store i32* %32, i32** %3
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %38
34: ; preds = %30
%35 = load i8*, i8** %2
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.7, i64 0, i64 0), i8* %35)
%37 = call i32 @exit(i32 -1)
unreachable
38: ; preds = %30
%39 = load i32*, i32** %3
%40 = call i32 @readHexDigitsInBinaryFormat(i32* %39)
%41 = load i32*, i32** %3
%42 = call i32 @fclose(i32* %41)
br label %43
43: ; preds = %38, %27
br label %44
44: ; preds = %43, %21
ret void
}

LLVM IR (-O2):
@.str.3 = [24 x i8] c" Select input mode: \00"
@.str.4 = [4 x i8] c"%1d\00"
@.str.6 = [2 x i8] c"r\00"
@.str.7 = [70 x i8] c"ERROR IN FUNCTION fileBasedBitStreams: file %s could not be opened.\0A\00"
@.str.8 = [3 x i8] c"rb\00"
@str = [22 x i8] c" Input File Format:\00"
@str.9 = [48 x i8] c" [0] ASCII - A sequence of ASCII 0's and 1's\00"
@str.10 = [65 x i8] c" [1] Binary - Each byte in data file contains 8 bits of data\0A\00"
define void @fileBasedBitStreams(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.9, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @str.10, i64 0, i64 0))
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %2)
%9 = call i32 @putchar(i32 10)
%10 = load i32, i32* %2
switch i32 %10, label %30 [
i32 0, label %11
i32 1, label %19
]
11: ; preds = %1
%12 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @.str.7, i64 0, i64 0), i8* %0)
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %11
%18 = call i32 @readBinaryDigitsInASCIIFormat(i32* %12, i8* %0)
br label %27
19: ; preds = %1
%20 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @.str.7, i64 0, i64 0), i8* %0)
%24 = call i32 @exit(i32 -1)
unreachable
25: ; preds = %19
%26 = call i32 @readHexDigitsInBinaryFormat(i32* %20)
br label %27
27: ; preds = %17, %25
%28 = phi i32* [ %20, %25 ], [ %12, %17 ]
%29 = call i32 @fclose(i32* %28)
br label %30
30: ; preds = %27, %1
ret void
}