#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*/ bfopen(int, int, char *);
scalar_t__ bfread(int, int, char *, int, unsigned char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *stdout;
int getfile(int drive, int user, char *n83, char *dest) {
  static unsigned char dma[128];
  FILE *out;
  int pos = 0;
  if (!bfopen(drive, user, n83))
    return (0);
  if (dest && (out = fopen(dest, "wb")) == NULL)
    return (0);
  if (!dest)
    out = stdout;
  while (bfread(drive, user, n83, pos, dma)) {
    if (fwrite(dma, 1, 128, out) != 128) {
      fclose(out);
      return (0);
    }
    pos += 128;
  }
  if (out != stdout)
    fclose(out);
  return (1);
}


x86 assembly (clang, -O0):
<getfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1040 <bfopen@plt>
cmp    $0x0,%eax
jne    1191 <getfile+0x41>
movl   $0x0,-0x4(%rbp)
jmp    1275 <getfile+0x125>
cmpq   $0x0,-0x20(%rbp)
je     11c6 <getfile+0x76>
mov    -0x20(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11c6 <getfile+0x76>
movl   $0x0,-0x4(%rbp)
jmp    1275 <getfile+0x125>
cmpq   $0x0,-0x20(%rbp)
jne    11df <getfile+0x8f>
mov    0x2e08(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    11e4 <getfile+0x94>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
lea    0x2e68(%rip),%r8
call   1070 <bfread@plt>
cmp    $0x0,%rax
je     1251 <getfile+0x101>
mov    -0x28(%rbp),%rcx
lea    0x2e4e(%rip),%rdi
mov    $0x1,%esi
mov    $0x80,%edx
call   1060 <fwrite@plt>
cmp    $0x80,%eax
je     1241 <getfile+0xf1>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1275 <getfile+0x125>
mov    -0x2c(%rbp),%eax
add    $0x80,%eax
mov    %eax,-0x2c(%rbp)
jmp    11e4 <getfile+0x94>
mov    -0x28(%rbp),%rax
mov    0x2d84(%rip),%rcx
cmp    (%rcx),%rax
je     126e <getfile+0x11e>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getfile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %esi,%r12d
mov    %edi,%r13d
call   1040 <bfopen@plt>
xor    %ebp,%ebp
test   %eax,%eax
je     1224 <getfile+0xd4>
test   %rbx,%rbx
je     1197 <getfile+0x47>
lea    0xe7e(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1197 <getfile+0x47>
jmp    1224 <getfile+0xd4>
mov    0x2e42(%rip),%rax
test   %rbx,%rbx
jne    11a6 <getfile+0x56>
mov    (%rax),%r15
lea    0x2eb3(%rip),%r8
mov    %r13d,%edi
mov    %r12d,%esi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1070 <bfread@plt>
test   %rax,%rax
je     1207 <getfile+0xb7>
mov    $0x80,%ebp
lea    0x2e92(%rip),%rbx
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x80,%edx
mov    %r15,%rcx
call   1060 <fwrite@plt>
cmp    $0x80,%eax
jne    121a <getfile+0xca>
mov    %r13d,%edi
mov    %r12d,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
mov    %rbx,%r8
call   1070 <bfread@plt>
sub    $0xffffff80,%ebp
test   %rax,%rax
jne    11d0 <getfile+0x80>
mov    $0x1,%ebp
mov    0x2dcd(%rip),%rax
cmp    (%rax),%r15
jne    121c <getfile+0xcc>
jmp    1224 <getfile+0xd4>
xor    %ebp,%ebp
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@getfile.dma = internal global [128 x i8] zeroinitializer
@.str = [3 x i8] c"wb\00"
@stdout = global i32* null
define i32 @getfile(i32 %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i32 0, i32* %11
%12 = load i32, i32* %6
%13 = load i32, i32* %7
%14 = load i8*, i8** %8
%15 = call i32 @bfopen(i32 %12, i32 %13, i8* %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %4
store i32 0, i32* %5
br label %57
18: ; preds = %4
%19 = load i8*, i8** %9
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = load i8*, i8** %9
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %23, i32** %10
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %26
25: ; preds = %21
store i32 0, i32* %5
br label %57
26: ; preds = %21, %18
%27 = load i8*, i8** %9
%28 = icmp ne i8* %27, null
br i1 %28, label %31, label %29
29: ; preds = %26
%30 = load i32*, i32** @stdout
store i32* %30, i32** %10
br label %31
31: ; preds = %29, %26
br label %32
32: ; preds = %46, %31
%33 = load i32, i32* %6
%34 = load i32, i32* %7
%35 = load i8*, i8** %8
%36 = load i32, i32* %11
%37 = call i64 @bfread(i32 %33, i32 %34, i8* %35, i32 %36, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @getfile.dma, i64 0, i64 0))
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %49
39: ; preds = %32
%40 = load i32*, i32** %10
%41 = call i32 @fwrite(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @getfile.dma, i64 0, i64 0), i32 1, i32 128, i32* %40)
%42 = icmp ne i32 %41, 128
br i1 %42, label %43, label %46
43: ; preds = %39
%44 = load i32*, i32** %10
%45 = call i32 @fclose(i32* %44)
store i32 0, i32* %5
br label %57
46: ; preds = %39
%47 = load i32, i32* %11
%48 = add nsw i32 %47, 128
store i32 %48, i32* %11
br label %32
49: ; preds = %32
%50 = load i32*, i32** %10
%51 = load i32*, i32** @stdout
%52 = icmp ne i32* %50, %51
br i1 %52, label %53, label %56
53: ; preds = %49
%54 = load i32*, i32** %10
%55 = call i32 @fclose(i32* %54)
br label %56
56: ; preds = %53, %49
store i32 1, i32* %5
br label %57
57: ; preds = %56, %43, %25, %17
%58 = load i32, i32* %5
ret i32 %58
}

LLVM IR (-O2):
@getfile.dma = internal global [128 x i8] zeroinitializer
@.str = [3 x i8] c"wb\00"
@stdout = global i32* null
define i32 @getfile(i32 %0, i32 %1, i8* %2, i8* %3) {
%5 = tail call i32 @bfopen(i32 %0, i32 %1, i8* %2)
%6 = icmp eq i32 %5, 0
br i1 %6, label %32, label %7
7: ; preds = %4
%8 = icmp eq i8* %3, null
br i1 %8, label %12, label %9
9: ; preds = %7
%10 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %32, label %12
12: ; preds = %9, %7
%13 = phi i32* [ %10, %9 ], [ undef, %7 ]
%14 = load i32*, i32** @stdout
%15 = select i1 %8, i32* %14, i32* %13
%16 = tail call i64 @bfread(i32 %0, i32 %1, i8* %2, i32 0, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @getfile.dma, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %26, label %21
18: ; preds = %21
%19 = tail call i64 @bfread(i32 %0, i32 %1, i8* %2, i32 %25, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @getfile.dma, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %26, label %21
21: ; preds = %12, %18
%22 = phi i32 [ %25, %18 ], [ 0, %12 ]
%23 = tail call i32 @fwrite(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @getfile.dma, i64 0, i64 0), i32 1, i32 128, i32* %15)
%24 = icmp eq i32 %23, 128
%25 = add nuw nsw i32 %22, 128
br i1 %24, label %18, label %29
26: ; preds = %18, %12
%27 = load i32*, i32** @stdout
%28 = icmp eq i32* %15, %27
br i1 %28, label %32, label %29
29: ; preds = %21, %26
%30 = phi i32 [ 1, %26 ], [ 0, %21 ]
%31 = tail call i32 @fclose(i32* %15)
br label %32
32: ; preds = %29, %26, %9, %4
%33 = phi i32 [ 0, %4 ], [ 0, %9 ], [ 1, %26 ], [ %30, %29 ]
ret i32 %33
}