#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 EOF;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int /*<<< orphan*/ fsync(int /*<<< orphan*/ *);
unsigned int ftell(int /*<<< orphan*/ *);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
int mmc_raw_dump_internal(const char *in_file, const char *out_file) {
  int ch;
  FILE *in;
  FILE *out;
  int val = 0;
  char buf[512];
  unsigned sz = 0;
  unsigned i;
  int ret = -1;
  in = fopen(in_file, "r");
  if (in == NULL)
    goto ERROR3;
  out = fopen(out_file, "w");
  if (out == NULL)
    goto ERROR2;
  fseek(in, 0L, SEEK_END);
  sz = ftell(in);
  fseek(in, 0L, SEEK_SET);
  if (sz % 512) {
    while ((ch = fgetc(in)) != EOF)
      fputc(ch, out);
  } else {
    for (i = 0; i < (sz / 512); i++) {
      if ((fread(buf, 512, 1, in)) != 1)
        goto ERROR1;
      if ((fwrite(buf, 512, 1, out)) != 1)
        goto ERROR1;
    }
  }
  fsync(out);
  ret = 0;
ERROR1:
  fclose(out);
ERROR2:
  fclose(in);
ERROR3:
  return ret;
}


x86 assembly (clang, -O0):
<mmc_raw_dump_internal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x234(%rbp)
movl   $0xffffffff,-0x23c(%rbp)
ff ff ff
mov    -0x8(%rbp),%rdi
lea    0xe37(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e2 <mmc_raw_dump_internal+0x52>
jmp    133f <mmc_raw_dump_internal+0x1af>
mov    -0x10(%rbp),%rdi
lea    0xe15(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1206 <mmc_raw_dump_internal+0x76>
jmp    1336 <mmc_raw_dump_internal+0x1a6>
mov    -0x20(%rbp),%rdi
mov    0x2dd7(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0x234(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2d9a(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
mov    -0x234(%rbp),%eax
and    $0x1ff,%eax
cmp    $0x0,%eax
je     128b <mmc_raw_dump_internal+0xfb>
jmp    125a <mmc_raw_dump_internal+0xca>
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2d73(%rip),%rcx
cmp    (%rcx),%eax
je     1286 <mmc_raw_dump_internal+0xf6>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1060 <fputc@plt>
jmp    125a <mmc_raw_dump_internal+0xca>
jmp    131a <mmc_raw_dump_internal+0x18a>
movl   $0x0,-0x238(%rbp)
mov    -0x238(%rbp),%eax
mov    -0x234(%rbp),%ecx
shr    $0x9,%ecx
cmp    %ecx,%eax
jae    1315 <mmc_raw_dump_internal+0x185>
lea    -0x230(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x200,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     12d4 <mmc_raw_dump_internal+0x144>
jmp    132d <mmc_raw_dump_internal+0x19d>
lea    -0x230(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x200,%esi
mov    $0x1,%edx
call   10b0 <fwrite@plt>
cmp    $0x1,%eax
je     12fc <mmc_raw_dump_internal+0x16c>
jmp    132d <mmc_raw_dump_internal+0x19d>
jmp    1301 <mmc_raw_dump_internal+0x171>
mov    -0x238(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x238(%rbp)
jmp    1295 <mmc_raw_dump_internal+0x105>
jmp    131a <mmc_raw_dump_internal+0x18a>
mov    -0x28(%rbp),%rdi
call   1090 <fsync@plt>
movl   $0x0,-0x23c(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x23c(%rbp),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mmc_raw_dump_internal>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    %rsi,%rbx
lea    0xe57(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1238 <mmc_raw_dump_internal+0xa8>
mov    %rax,%r15
lea    0xe41(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     123f <mmc_raw_dump_internal+0xaf>
mov    %rax,%r14
mov    0x2e10(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r15,%rdi
call   1070 <ftell@plt>
mov    %eax,%ebp
mov    0x2ddb(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
test   $0x1ff,%ebp
je     1246 <mmc_raw_dump_internal+0xb6>
mov    %r15,%rdi
call   1050 <fgetc@plt>
mov    0x2dc8(%rip),%rbx
cmp    (%rbx),%eax
je     1299 <mmc_raw_dump_internal+0x109>
mov    %eax,%edi
mov    %r14,%rsi
call   1060 <fputc@plt>
mov    %r15,%rdi
call   1050 <fgetc@plt>
cmp    (%rbx),%eax
jne    1220 <mmc_raw_dump_internal+0x90>
jmp    1299 <mmc_raw_dump_internal+0x109>
mov    $0xffffffff,%ebx
jmp    12b3 <mmc_raw_dump_internal+0x123>
mov    $0xffffffff,%ebx
jmp    12ab <mmc_raw_dump_internal+0x11b>
cmp    $0x200,%ebp
jb     1299 <mmc_raw_dump_internal+0x109>
shr    $0x9,%ebp
mov    %rsp,%r12
mov    $0xffffffff,%ebx
nopl   0x0(%rax)
mov    %r12,%rdi
mov    $0x200,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    12a3 <mmc_raw_dump_internal+0x113>
mov    %r12,%rdi
mov    $0x200,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10b0 <fwrite@plt>
cmp    $0x1,%eax
jne    12a3 <mmc_raw_dump_internal+0x113>
add    $0xffffffff,%ebp
jne    1260 <mmc_raw_dump_internal+0xd0>
mov    %r14,%rdi
call   1090 <fsync@plt>
xor    %ebx,%ebx
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %ebx,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@EOF = global i32 0
define i32 @mmc_raw_dump_internal(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca [512 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %8
store i32 0, i32* %10
store i32 -1, i32* %12
%13 = load i8*, i8** %3
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %6
%15 = load i32*, i32** %6
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %18
17: ; preds = %2
br label %79
18: ; preds = %2
%19 = load i8*, i8** %4
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %7
%21 = load i32*, i32** %7
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %24
23: ; preds = %18
br label %76
24: ; preds = %18
%25 = load i32*, i32** %6
%26 = load i32, i32* @SEEK_END
%27 = call i32 @fseek(i32* %25, i64 0, i32 %26)
%28 = load i32*, i32** %6
%29 = call i32 @ftell(i32* %28)
store i32 %29, i32* %10
%30 = load i32*, i32** %6
%31 = load i32, i32* @SEEK_SET
%32 = call i32 @fseek(i32* %30, i64 0, i32 %31)
%33 = load i32, i32* %10
%34 = urem i32 %33, 512
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %47
36: ; preds = %24
br label %37
37: ; preds = %42, %36
%38 = load i32*, i32** %6
%39 = call i32 @fgetc(i32* %38)
store i32 %39, i32* %5
%40 = load i32, i32* @EOF
%41 = icmp ne i32 %39, %40
br i1 %41, label %42, label %46
42: ; preds = %37
%43 = load i32, i32* %5
%44 = load i32*, i32** %7
%45 = call i32 @fputc(i32 %43, i32* %44)
br label %37
46: ; preds = %37
br label %70
47: ; preds = %24
store i32 0, i32* %11
br label %48
48: ; preds = %66, %47
%49 = load i32, i32* %11
%50 = load i32, i32* %10
%51 = udiv i32 %50, 512
%52 = icmp ult i32 %49, %51
br i1 %52, label %53, label %69
53: ; preds = %48
%54 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%55 = load i32*, i32** %6
%56 = call i32 @fread(i8* %54, i32 512, i32 1, i32* %55)
%57 = icmp ne i32 %56, 1
br i1 %57, label %58, label %59
58: ; preds = %53
br label %73
59: ; preds = %53
%60 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%61 = load i32*, i32** %7
%62 = call i32 @fwrite(i8* %60, i32 512, i32 1, i32* %61)
%63 = icmp ne i32 %62, 1
br i1 %63, label %64, label %65
64: ; preds = %59
br label %73
65: ; preds = %59
br label %66
66: ; preds = %65
%67 = load i32, i32* %11
%68 = add i32 %67, 1
store i32 %68, i32* %11
br label %48
69: ; preds = %48
br label %70
70: ; preds = %69, %46
%71 = load i32*, i32** %7
%72 = call i32 @fsync(i32* %71)
store i32 0, i32* %12
br label %73
73: ; preds = %70, %64, %58
%74 = load i32*, i32** %7
%75 = call i32 @fclose(i32* %74)
br label %76
76: ; preds = %73, %23
%77 = load i32*, i32** %6
%78 = call i32 @fclose(i32* %77)
br label %79
79: ; preds = %76, %17
%80 = load i32, i32* %12
ret i32 %80
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@EOF = global i32 0
define i32 @mmc_raw_dump_internal(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %50, label %7
7: ; preds = %2
%8 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %47, label %10
10: ; preds = %7
%11 = load i32, i32* @SEEK_END
%12 = tail call i32 @fseek(i32* %5, i64 0, i32 %11)
%13 = tail call i32 @ftell(i32* %5)
%14 = load i32, i32* @SEEK_SET
%15 = tail call i32 @fseek(i32* %5, i64 0, i32 %14)
%16 = and i32 %13, 511
%17 = icmp eq i32 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %10
%19 = tail call i32 @fgetc(i32* %5)
%20 = load i32, i32* @EOF
%21 = icmp eq i32 %19, %20
br i1 %21, label %42, label %26
22: ; preds = %10
%23 = icmp ult i32 %13, 512
br i1 %23, label %42, label %24
24: ; preds = %22
%25 = lshr i32 %13, 9
br label %34
26: ; preds = %18, %26
%27 = phi i32 [ %29, %26 ], [ %19, %18 ]
%28 = tail call i32 @fputc(i32 %27, i32* %8)
%29 = tail call i32 @fgetc(i32* %5)
%30 = load i32, i32* @EOF
%31 = icmp eq i32 %29, %30
br i1 %31, label %42, label %26
32: ; preds = %38
%33 = icmp eq i32 %41, %25
br i1 %33, label %42, label %34
34: ; preds = %24, %32
%35 = phi i32 [ %41, %32 ], [ 0, %24 ]
%36 = call i32 @fread(i8* %4, i32 512, i32 1, i32* %5)
%37 = icmp eq i32 %36, 1
br i1 %37, label %38, label %44
38: ; preds = %34
%39 = call i32 @fwrite(i8* %4, i32 512, i32 1, i32* %8)
%40 = icmp eq i32 %39, 1
%41 = add nuw nsw i32 %35, 1
br i1 %40, label %32, label %44
42: ; preds = %26, %32, %18, %22
%43 = tail call i32 @fsync(i32* %8)
br label %44
44: ; preds = %38, %34, %42
%45 = phi i32 [ 0, %42 ], [ -1, %34 ], [ -1, %38 ]
%46 = tail call i32 @fclose(i32* %8)
br label %47
47: ; preds = %7, %44
%48 = phi i32 [ -1, %7 ], [ %45, %44 ]
%49 = tail call i32 @fclose(i32* %5)
br label %50
50: ; preds = %2, %47
%51 = phi i32 [ -1, %2 ], [ %48, %47 ]
ret i32 %51
}