#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 */

/* Variables and functions */
size_t U_wmf_onerec_print(char *, char *, int, size_t);
int /*<<< orphan*/ printf(char *);
size_t wmfheader_print(char *, char *);
int myMetaFileProc(char *contents, size_t length) {
  size_t off = 0;
  size_t result;
  int OK = 1;
  int recnum = 0;
  char *blimit = contents + length;
  off = wmfheader_print(contents, blimit);
  while (OK) {
    result = U_wmf_onerec_print(contents, blimit, recnum, off);
    if (result == (size_t)-1) {
      printf("ABORTING on invalid record - corrupt file?\n");
      OK = 0;
    } else if (!result) {
      OK = 0;
    } else {
      off += result;
      recnum++;
    }
  }
  return (result);
}


x86 assembly (clang, -O0):
<myMetaFileProc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x1,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <wmfheader_print@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11ee <myMetaFileProc+0xbe>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1050 <U_wmf_onerec_print@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0xffffffffffffffff,-0x20(%rbp)
jne    11b8 <myMetaFileProc+0x88>
lea    0xe59(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
jmp    11e9 <myMetaFileProc+0xb9>
cmpq   $0x0,-0x20(%rbp)
jne    11cf <myMetaFileProc+0x9f>
movl   $0x0,-0x24(%rbp)
jmp    11e4 <myMetaFileProc+0xb4>
mov    -0x20(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11e9 <myMetaFileProc+0xb9>
jmp    1173 <myMetaFileProc+0x43>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<myMetaFileProc>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
add    %rdi,%r15
mov    %r15,%rsi
call   1040 <wmfheader_print@plt>
mov    %rax,%r12
xor    %ebp,%ebp
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %r12,%rcx
call   1050 <U_wmf_onerec_print@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1182 <myMetaFileProc+0x52>
cmp    $0xffffffffffffffff,%rbx
je     1176 <myMetaFileProc+0x46>
add    %rbx,%r12
add    $0x1,%ebp
jmp    1150 <myMetaFileProc+0x20>
lea    0xe83(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"ABORTING on invalid record - corrupt file?\0A\00"
define i32 @myMetaFileProc(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
store i64 0, i64* %5
store i32 1, i32* %7
store i32 0, i32* %8
%10 = load i8*, i8** %3
%11 = load i64, i64* %4
%12 = getelementptr inbounds i8, i8* %10, i64 %11
store i8* %12, i8** %9
%13 = load i8*, i8** %3
%14 = load i8*, i8** %9
%15 = call i64 @wmfheader_print(i8* %13, i8* %14)
store i64 %15, i64* %5
br label %16
16: ; preds = %40, %2
%17 = load i32, i32* %7
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %41
19: ; preds = %16
%20 = load i8*, i8** %3
%21 = load i8*, i8** %9
%22 = load i32, i32* %8
%23 = load i64, i64* %5
%24 = call i64 @U_wmf_onerec_print(i8* %20, i8* %21, i32 %22, i64 %23)
store i64 %24, i64* %6
%25 = load i64, i64* %6
%26 = icmp eq i64 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %19
%28 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %7
br label %40
29: ; preds = %19
%30 = load i64, i64* %6
%31 = icmp ne i64 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %29
store i32 0, i32* %7
br label %39
33: ; preds = %29
%34 = load i64, i64* %6
%35 = load i64, i64* %5
%36 = add i64 %35, %34
store i64 %36, i64* %5
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
br label %39
39: ; preds = %33, %32
br label %40
40: ; preds = %39, %27
br label %16
41: ; preds = %16
%42 = load i64, i64* %6
%43 = trunc i64 %42 to i32
ret i32 %43
}

LLVM IR (-O2):
@str = [43 x i8] c"ABORTING on invalid record - corrupt file?\00"
define i32 @myMetaFileProc(i8* %0, i64 %1) {
%3 = getelementptr inbounds i8, i8* %0, i64 %1
%4 = tail call i64 @wmfheader_print(i8* %0, i8* %3)
br label %5
5: ; preds = %11, %2
%6 = phi i64 [ %4, %2 ], [ %12, %11 ]
%7 = phi i32 [ 0, %2 ], [ %13, %11 ]
%8 = tail call i64 @U_wmf_onerec_print(i8* %0, i8* %3, i32 %7, i64 %6)
switch i64 %8, label %11 [
i64 -1, label %9
i64 0, label %14
]
9: ; preds = %5
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
br label %14
11: ; preds = %5
%12 = add i64 %8, %6
%13 = add nuw nsw i32 %7, 1
br label %5
14: ; preds = %5, %9
%15 = trunc i64 %8 to i32
ret i32 %15
}