#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*/ outword;
typedef int /*<<< orphan*/ inword;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char **argv) {
  FILE *fp;
  FILE *fd;
  unsigned char inword[4];
  unsigned char outword[4];
  if (argc != 3) {
    printf("bitimg2img <infile> <outfile>\r\n");
    return -1;
  }
  fp = fopen(argv[1], "rb");
  fd = fopen(argv[2], "wb");
  while (fread(inword, sizeof(inword), 1, fp) > 0) {
    outword[0] = (inword[0]) ? 0xFF : 0;
    outword[1] = (inword[1]) ? 0xFF : 0;
    outword[2] = (inword[2]) ? 0xFF : 0;
    outword[3] = (inword[3]) ? 0xFF : 0;
    fwrite(outword, sizeof(outword), 1, fd);
  }
  fclose(fp);
  fclose(fd);
  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   $0x3,-0x8(%rbp)
je     1188 <main+0x38>
lea    0xe89(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125e <main+0x10e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe89(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe74(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
lea    -0x24(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x0,%rax
jle    1245 <main+0xf5>
movzbl -0x24(%rbp),%edx
xor    %eax,%eax
mov    $0xff,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,-0x28(%rbp)
movzbl -0x23(%rbp),%edx
xor    %eax,%eax
mov    $0xff,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,-0x27(%rbp)
movzbl -0x22(%rbp),%edx
xor    %eax,%eax
mov    $0xff,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,-0x26(%rbp)
movzbl -0x21(%rbp),%edx
xor    %eax,%eax
mov    $0xff,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,-0x25(%rbp)
lea    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
jmp    11b8 <main+0x68>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%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
cmp    $0x3,%edi
jne    122f <main+0xdf>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe8d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xe7d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
test   %rax,%rax
jle    121b <main+0xcb>
xor    %ebp,%ebp
lea    0xc(%rsp),%r15
lea    0x8(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
cmp    0x8(%rsp),%bpl
sbb    %eax,%eax
cmp    0x9(%rsp),%bpl
sbb    %ecx,%ecx
mov    %al,0xc(%rsp)
mov    %cl,0xd(%rsp)
cmp    0xa(%rsp),%bpl
sbb    %eax,%eax
cmp    0xb(%rsp),%bpl
mov    %al,0xe(%rsp)
sbb    %eax,%eax
mov    %al,0xf(%rsp)
mov    %r15,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
mov    %r12,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
test   %rax,%rax
jg     11c0 <main+0x70>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
jmp    1240 <main+0xf0>
lea    0xdd0(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"bitimg2img <infile> <outfile>\0D\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [3 x i8] c"wb\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 [4 x i8]
%9 = alloca [4 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %69
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %22, i32** %7
br label %23
23: ; preds = %28, %14
%24 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%25 = load i32*, i32** %6
%26 = call i64 @fread(i8* %24, i32 4, i32 1, i32* %25)
%27 = icmp sgt i64 %26, 0
br i1 %27, label %28, label %64
28: ; preds = %23
%29 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = icmp ne i32 %31, 0
%33 = zext i1 %32 to i64
%34 = select i1 %32, i32 255, i32 0
%35 = trunc i32 %34 to i8
%36 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
store i8 %35, i8* %36
%37 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 1
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = icmp ne i32 %39, 0
%41 = zext i1 %40 to i64
%42 = select i1 %40, i32 255, i32 0
%43 = trunc i32 %42 to i8
%44 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 1
store i8 %43, i8* %44
%45 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 2
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = icmp ne i32 %47, 0
%49 = zext i1 %48 to i64
%50 = select i1 %48, i32 255, i32 0
%51 = trunc i32 %50 to i8
%52 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 2
store i8 %51, i8* %52
%53 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 3
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = icmp ne i32 %55, 0
%57 = zext i1 %56 to i64
%58 = select i1 %56, i32 255, i32 0
%59 = trunc i32 %58 to i8
%60 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 3
store i8 %59, i8* %60
%61 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%62 = load i32*, i32** %7
%63 = call i32 @fwrite(i8* %61, i32 4, i32 1, i32* %62)
br label %23
64: ; preds = %23
%65 = load i32*, i32** %6
%66 = call i32 @fclose(i32* %65)
%67 = load i32*, i32** %7
%68 = call i32 @fclose(i32* %67)
store i32 0, i32* %3
br label %69
69: ; preds = %64, %12
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [3 x i8] c"wb\00"
@str = [31 x i8] c"bitimg2img <infile> <outfile>\0D\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4 x i8]
%4 = alloca [4 x i8]
%5 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 3
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
br label %45
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 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%17 = call i64 @fread(i8* %5, i32 4, i32 1, i32* %13)
%18 = icmp sgt i64 %17, 0
br i1 %18, label %19, label %42
19: ; preds = %10
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
%21 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 1
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
%23 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 2
%24 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
%25 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 3
br label %26
26: ; preds = %19, %26
%27 = load i8, i8* %5
%28 = icmp ne i8 %27, 0
%29 = sext i1 %28 to i8
store i8 %29, i8* %6
%30 = load i8, i8* %20
%31 = icmp ne i8 %30, 0
%32 = sext i1 %31 to i8
store i8 %32, i8* %21
%33 = load i8, i8* %22
%34 = icmp ne i8 %33, 0
%35 = sext i1 %34 to i8
store i8 %35, i8* %23
%36 = load i8, i8* %24
%37 = icmp ne i8 %36, 0
%38 = sext i1 %37 to i8
store i8 %38, i8* %25
%39 = call i32 @fwrite(i8* %6, i32 4, i32 1, i32* %16)
%40 = call i64 @fread(i8* %5, i32 4, i32 1, i32* %13)
%41 = icmp sgt i64 %40, 0
br i1 %41, label %26, label %42
42: ; preds = %26, %10
%43 = tail call i32 @fclose(i32* %13)
%44 = tail call i32 @fclose(i32* %16)
br label %45
45: ; preds = %42, %8
%46 = phi i32 [ -1, %8 ], [ 0, %42 ]
ret i32 %46
}