#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*/ bfmake(int, int, char *);
int /*<<< orphan*/ bfwrite(int, int, char *, int, unsigned char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int getfilesize(char *);
int /*<<< orphan*/ make83(char *);
int /*<<< orphan*/ memset(unsigned char *, int, int);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
int putfile(char *fn, int dest_drive, int dest_user) {
  static unsigned char dma[128];
  FILE *in;
  char n83[12];
  int f, siz, rcdsiz;
  strcpy(n83, make83(fn));
  if (!bfmake(dest_drive, dest_user, n83))
    return (0);
  if ((siz = getfilesize(fn)) == -1 || (in = fopen(fn, "rb")) == NULL)
    return (0);
  rcdsiz = (siz + 127) / 128;
  for (f = 0; f < rcdsiz; f++) {
    memset(dma, 26, 128);
    fread(dma, 1, 128, in);
    if (!bfwrite(dest_drive, dest_user, n83, f * 128, dma)) {
      fclose(in);
      return (0);
    }
  }
  fclose(in);
  return (1);
}


x86 assembly (clang, -O0):
<putfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
lea    -0x2c(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <make83@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
lea    -0x2c(%rbp),%rdx
call   1090 <bfmake@plt>
cmp    $0x0,%eax
jne    11e2 <putfile+0x52>
movl   $0x0,-0x4(%rbp)
jmp    12d2 <putfile+0x142>
mov    -0x10(%rbp),%rdi
call   1070 <getfilesize@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
je     1215 <putfile+0x85>
mov    -0x10(%rbp),%rdi
lea    0xdfe(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1221 <putfile+0x91>
movl   $0x0,-0x4(%rbp)
jmp    12d2 <putfile+0x142>
mov    -0x34(%rbp),%eax
add    $0x7f,%eax
mov    $0x80,%ecx
cltd
idiv   %ecx
mov    %eax,-0x38(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    12c2 <putfile+0x132>
lea    0x2e34(%rip),%rdi
mov    $0x1a,%esi
mov    $0x80,%edx
call   1080 <memset@plt>
mov    -0x20(%rbp),%rcx
lea    0x2e1a(%rip),%rdi
mov    $0x1,%esi
mov    $0x80,%edx
call   1040 <fread@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
lea    -0x2c(%rbp),%rdx
mov    -0x30(%rbp),%ecx
shl    $0x7,%ecx
lea    0x2df4(%rip),%r8
call   10b0 <bfwrite@plt>
cmp    $0x0,%eax
jne    12af <putfile+0x11f>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    12d2 <putfile+0x142>
jmp    12b4 <putfile+0x124>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1239 <putfile+0xa9>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putfile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r12d
mov    %esi,%r13d
mov    %rdi,%rbp
call   1060 <make83@plt>
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    %r13d,%edi
mov    %r12d,%esi
mov    %rbx,%rdx
call   1090 <bfmake@plt>
xor    %r14d,%r14d
test   %eax,%eax
je     127d <putfile+0xed>
mov    %rbp,%rdi
call   1070 <getfilesize@plt>
cmp    $0xffffffff,%eax
je     127d <putfile+0xed>
mov    %eax,%ebx
lea    0xe12(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     127d <putfile+0xed>
mov    %rax,%r15
test   %ebx,%ebx
jle    126a <putfile+0xda>
add    $0x7f,%ebx
shr    $0x7,%ebx
lea    0x2e6d(%rip),%rbp
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x1a,%esi
mov    $0x80,%edx
call   1080 <memset@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x80,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
mov    %r13d,%edi
mov    %r12d,%esi
lea    0xc(%rsp),%rdx
mov    %r14d,%ecx
mov    %rbp,%r8
call   10b0 <bfwrite@plt>
test   %eax,%eax
je     1272 <putfile+0xe2>
sub    $0xffffff80,%r14d
add    $0xffffffff,%ebx
jne    1220 <putfile+0x90>
mov    $0x1,%r14d
jmp    1275 <putfile+0xe5>
xor    %r14d,%r14d
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@putfile.dma = internal global [128 x i8] zeroinitializer
@.str = [3 x i8] c"rb\00"
define i32 @putfile(i8* %0, i32 %1, i32 %2) {
%4 = alloca [12 x i8]
%5 = getelementptr inbounds [12 x i8], [12 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @make83(i8* %0)
%7 = call i32 @strcpy(i8* %5, i32 %6)
%8 = call i32 @bfmake(i32 %1, i32 %2, i8* %5)
%9 = icmp eq i32 %8, 0
br i1 %9, label %34, label %10
10: ; preds = %3
%11 = call i32 @getfilesize(i8* %0)
%12 = icmp eq i32 %11, -1
br i1 %12, label %34, label %13
13: ; preds = %10
%14 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %34, label %16
16: ; preds = %13
%17 = icmp sgt i32 %11, 0
br i1 %17, label %18, label %31
18: ; preds = %16
%19 = add nuw nsw i32 %11, 127
%20 = lshr i32 %19, 7
br label %23
21: ; preds = %23
%22 = icmp eq i32 %30, %20
br i1 %22, label %31, label %23
23: ; preds = %18, %21
%24 = phi i32 [ %30, %21 ], [ 0, %18 ]
%25 = call i32 @memset(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @putfile.dma, i64 0, i64 0), i32 26, i32 128)
%26 = call i32 @fread(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @putfile.dma, i64 0, i64 0), i32 1, i32 128, i32* %14)
%27 = shl nsw i32 %24, 7
%28 = call i32 @bfwrite(i32 %1, i32 %2, i8* %5, i32 %27, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @putfile.dma, i64 0, i64 0))
%29 = icmp eq i32 %28, 0
%30 = add nuw nsw i32 %24, 1
br i1 %29, label %31, label %21
31: ; preds = %21, %23, %16
%32 = phi i32 [ 1, %16 ], [ 0, %23 ], [ 1, %21 ]
%33 = call i32 @fclose(i32* %14)
br label %34
34: ; preds = %31, %10, %13, %3
%35 = phi i32 [ 0, %3 ], [ 0, %13 ], [ 0, %10 ], [ %32, %31 ]
ret i32 %35
}