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

/* Variables and functions */
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
void emit_wcd_format(unsigned char *image, int scantype,
                     unsigned char *blackvals, FILE *outf) {
  unsigned char empty[512];
  unsigned char *p;
  int i;
  memset(empty, 0, sizeof(empty));
  p = image;
  for (i = 0; i < 246; i++) {
    (void)fwrite(p, 1, 512, outf);
    p += 512;
    if (scantype == 2)
      p += 512;
  }
  for (i = 0; i < 10; i++)
    (void)fwrite(empty, 1, 512, outf);
  p = (scantype == 2) ? &image[512] : image;
  for (i = 0; i < 246; i++) {
    (void)fwrite(p, 1, 512, outf);
    p += 512;
    if (scantype == 2)
      p += 512;
  }
  for (i = 0; i < 8; i++)
    (void)fwrite(empty, 1, 512, outf);
  (void)fwrite(blackvals, 1, 2 * 512, outf);
}


x86 assembly (clang, -O0):
<emit_wcd_format>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x228(%rbp)
movl   $0x0,-0x22c(%rbp)
cmpl   $0xf6,-0x22c(%rbp)
jge    11d7 <emit_wcd_format+0xb7>
mov    -0x228(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x200,%edx
call   1040 <fwrite@plt>
mov    -0x228(%rbp),%rax
add    $0x200,%rax
mov    %rax,-0x228(%rbp)
cmpl   $0x2,-0xc(%rbp)
jne    11be <emit_wcd_format+0x9e>
mov    -0x228(%rbp),%rax
add    $0x200,%rax
mov    %rax,-0x228(%rbp)
jmp    11c3 <emit_wcd_format+0xa3>
mov    -0x22c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x22c(%rbp)
jmp    1162 <emit_wcd_format+0x42>
movl   $0x0,-0x22c(%rbp)
cmpl   $0xa,-0x22c(%rbp)
jge    121c <emit_wcd_format+0xfc>
lea    -0x220(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x200,%edx
call   1040 <fwrite@plt>
mov    -0x22c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x22c(%rbp)
jmp    11e1 <emit_wcd_format+0xc1>
cmpl   $0x2,-0xc(%rbp)
jne    123c <emit_wcd_format+0x11c>
mov    -0x8(%rbp),%rax
add    $0x200,%rax
mov    %rax,-0x238(%rbp)
jmp    1247 <emit_wcd_format+0x127>
mov    -0x8(%rbp),%rax
mov    %rax,-0x238(%rbp)
mov    -0x238(%rbp),%rax
mov    %rax,-0x228(%rbp)
movl   $0x0,-0x22c(%rbp)
cmpl   $0xf6,-0x22c(%rbp)
jge    12d4 <emit_wcd_format+0x1b4>
mov    -0x228(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x200,%edx
call   1040 <fwrite@plt>
mov    -0x228(%rbp),%rax
add    $0x200,%rax
mov    %rax,-0x228(%rbp)
cmpl   $0x2,-0xc(%rbp)
jne    12bb <emit_wcd_format+0x19b>
mov    -0x228(%rbp),%rax
add    $0x200,%rax
mov    %rax,-0x228(%rbp)
jmp    12c0 <emit_wcd_format+0x1a0>
mov    -0x22c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x22c(%rbp)
jmp    125f <emit_wcd_format+0x13f>
movl   $0x0,-0x22c(%rbp)
cmpl   $0x8,-0x22c(%rbp)
jge    1319 <emit_wcd_format+0x1f9>
lea    -0x220(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x200,%edx
call   1040 <fwrite@plt>
mov    -0x22c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x22c(%rbp)
jmp    12de <emit_wcd_format+0x1be>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1040 <fwrite@plt>
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<emit_wcd_format>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %rcx,%r15
mov    %rdx,0x8(%rsp)
mov    %esi,%r12d
mov    %rdi,%rbp
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1030 <memset@plt>
xor    %r13d,%r13d
cmp    $0x2,%r12d
sete   %r13b
shl    $0x9,%r13
add    $0x200,%r13
mov    $0xf6,%r14d
mov    %rbp,%rbx
nop
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r15,%rcx
call   1040 <fwrite@plt>
add    %r13,%rbx
add    $0xffffffff,%r14d
jne    1170 <emit_wcd_format+0x50>
xor    %ebx,%ebx
cmp    $0x2,%r12d
sete   %bl
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r15,%rcx
call   1040 <fwrite@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r15,%rcx
call   1040 <fwrite@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r15,%rcx
call   1040 <fwrite@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r15,%rcx
call   1040 <fwrite@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r15,%rcx
call   1040 <fwrite@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r15,%rcx
call   1040 <fwrite@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r15,%rcx
call   1040 <fwrite@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r15,%rcx
call   1040 <fwrite@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r15,%rcx
call   1040 <fwrite@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r15,%rcx
call   1040 <fwrite@plt>
shl    $0x9,%rbx
add    %rbx,%rbp
mov    $0xf6,%ebx
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r15,%rcx
call   1040 <fwrite@plt>
add    %r13,%rbp
add    $0xffffffff,%ebx
jne    1280 <emit_wcd_format+0x160>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r15,%rcx
call   1040 <fwrite@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r15,%rcx
call   1040 <fwrite@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r15,%rcx
call   1040 <fwrite@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r15,%rcx
call   1040 <fwrite@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r15,%rcx
call   1040 <fwrite@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r15,%rcx
call   1040 <fwrite@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r15,%rcx
call   1040 <fwrite@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r15,%rcx
call   1040 <fwrite@plt>
mov    0x8(%rsp),%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r15,%rcx
call   1040 <fwrite@plt>
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @emit_wcd_format(i8* %0, i32 %1, i8* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca [512 x i8]
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32* %3, i32** %8
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%13 = call i32 @memset(i8* %12, i32 0, i32 512)
%14 = load i8*, i8** %5
store i8* %14, i8** %10
store i32 0, i32* %11
br label %15
15: ; preds = %30, %4
%16 = load i32, i32* %11
%17 = icmp slt i32 %16, 246
br i1 %17, label %18, label %33
18: ; preds = %15
%19 = load i8*, i8** %10
%20 = load i32*, i32** %8
%21 = call i32 @fwrite(i8* %19, i32 1, i32 512, i32* %20)
%22 = load i8*, i8** %10
%23 = getelementptr inbounds i8, i8* %22, i64 512
store i8* %23, i8** %10
%24 = load i32, i32* %6
%25 = icmp eq i32 %24, 2
br i1 %25, label %26, label %29
26: ; preds = %18
%27 = load i8*, i8** %10
%28 = getelementptr inbounds i8, i8* %27, i64 512
store i8* %28, i8** %10
br label %29
29: ; preds = %26, %18
br label %30
30: ; preds = %29
%31 = load i32, i32* %11
%32 = add nsw i32 %31, 1
store i32 %32, i32* %11
br label %15
33: ; preds = %15
store i32 0, i32* %11
br label %34
34: ; preds = %41, %33
%35 = load i32, i32* %11
%36 = icmp slt i32 %35, 10
br i1 %36, label %37, label %44
37: ; preds = %34
%38 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%39 = load i32*, i32** %8
%40 = call i32 @fwrite(i8* %38, i32 1, i32 512, i32* %39)
br label %41
41: ; preds = %37
%42 = load i32, i32* %11
%43 = add nsw i32 %42, 1
store i32 %43, i32* %11
br label %34
44: ; preds = %34
%45 = load i32, i32* %6
%46 = icmp eq i32 %45, 2
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load i8*, i8** %5
%49 = getelementptr inbounds i8, i8* %48, i64 512
br label %52
50: ; preds = %44
%51 = load i8*, i8** %5
br label %52
52: ; preds = %50, %47
%53 = phi i8* [ %49, %47 ], [ %51, %50 ]
store i8* %53, i8** %10
store i32 0, i32* %11
br label %54
54: ; preds = %69, %52
%55 = load i32, i32* %11
%56 = icmp slt i32 %55, 246
br i1 %56, label %57, label %72
57: ; preds = %54
%58 = load i8*, i8** %10
%59 = load i32*, i32** %8
%60 = call i32 @fwrite(i8* %58, i32 1, i32 512, i32* %59)
%61 = load i8*, i8** %10
%62 = getelementptr inbounds i8, i8* %61, i64 512
store i8* %62, i8** %10
%63 = load i32, i32* %6
%64 = icmp eq i32 %63, 2
br i1 %64, label %65, label %68
65: ; preds = %57
%66 = load i8*, i8** %10
%67 = getelementptr inbounds i8, i8* %66, i64 512
store i8* %67, i8** %10
br label %68
68: ; preds = %65, %57
br label %69
69: ; preds = %68
%70 = load i32, i32* %11
%71 = add nsw i32 %70, 1
store i32 %71, i32* %11
br label %54
72: ; preds = %54
store i32 0, i32* %11
br label %73
73: ; preds = %80, %72
%74 = load i32, i32* %11
%75 = icmp slt i32 %74, 8
br i1 %75, label %76, label %83
76: ; preds = %73
%77 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%78 = load i32*, i32** %8
%79 = call i32 @fwrite(i8* %77, i32 1, i32 512, i32* %78)
br label %80
80: ; preds = %76
%81 = load i32, i32* %11
%82 = add nsw i32 %81, 1
store i32 %82, i32* %11
br label %73
83: ; preds = %73
%84 = load i8*, i8** %7
%85 = load i32*, i32** %8
%86 = call i32 @fwrite(i8* %84, i32 1, i32 1024, i32* %85)
ret void
}

LLVM IR (-O2):
define void @emit_wcd_format(i8* nocapture %0, i32 %1, i8* nocapture %2, i32* nocapture %3) {
%5 = alloca [512 x i8]
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%7 = call i32 @memset(i8* %6, i32 0, i32 512)
%8 = icmp eq i32 %1, 2
%9 = select i1 %8, i64 1024, i64 512
br label %10
10: ; preds = %4, %10
%11 = phi i32 [ 0, %4 ], [ %15, %10 ]
%12 = phi i8* [ %0, %4 ], [ %14, %10 ]
%13 = call i32 @fwrite(i8* %12, i32 1, i32 512, i32* %3)
%14 = getelementptr inbounds i8, i8* %12, i64 %9
%15 = add nuw nsw i32 %11, 1
%16 = icmp eq i32 %15, 246
br i1 %16, label %17, label %10
17: ; preds = %10
%18 = call i32 @fwrite(i8* %6, i32 1, i32 512, i32* %3)
%19 = call i32 @fwrite(i8* %6, i32 1, i32 512, i32* %3)
%20 = call i32 @fwrite(i8* %6, i32 1, i32 512, i32* %3)
%21 = call i32 @fwrite(i8* %6, i32 1, i32 512, i32* %3)
%22 = call i32 @fwrite(i8* %6, i32 1, i32 512, i32* %3)
%23 = call i32 @fwrite(i8* %6, i32 1, i32 512, i32* %3)
%24 = call i32 @fwrite(i8* %6, i32 1, i32 512, i32* %3)
%25 = call i32 @fwrite(i8* %6, i32 1, i32 512, i32* %3)
%26 = call i32 @fwrite(i8* %6, i32 1, i32 512, i32* %3)
%27 = call i32 @fwrite(i8* %6, i32 1, i32 512, i32* %3)
%28 = select i1 %8, i64 512, i64 0
%29 = getelementptr i8, i8* %0, i64 %28
br label %30
30: ; preds = %17, %30
%31 = phi i32 [ 0, %17 ], [ %35, %30 ]
%32 = phi i8* [ %29, %17 ], [ %34, %30 ]
%33 = call i32 @fwrite(i8* %32, i32 1, i32 512, i32* %3)
%34 = getelementptr inbounds i8, i8* %32, i64 %9
%35 = add nuw nsw i32 %31, 1
%36 = icmp eq i32 %35, 246
br i1 %36, label %37, label %30
37: ; preds = %30
%38 = call i32 @fwrite(i8* %6, i32 1, i32 512, i32* %3)
%39 = call i32 @fwrite(i8* %6, i32 1, i32 512, i32* %3)
%40 = call i32 @fwrite(i8* %6, i32 1, i32 512, i32* %3)
%41 = call i32 @fwrite(i8* %6, i32 1, i32 512, i32* %3)
%42 = call i32 @fwrite(i8* %6, i32 1, i32 512, i32* %3)
%43 = call i32 @fwrite(i8* %6, i32 1, i32 512, i32* %3)
%44 = call i32 @fwrite(i8* %6, i32 1, i32 512, i32* %3)
%45 = call i32 @fwrite(i8* %6, i32 1, i32 512, i32* %3)
%46 = call i32 @fwrite(i8* %2, i32 1, i32 1024, i32* %3)
ret void
}