#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
int trs_create_blank_dmk(char *fname, int sides, int density, int eight,
                         int ignden) {
  FILE *f;
  int i;
  if (sides == -1)
    sides = 2;
  if (density == -1)
    density = 2;
  if (sides != 1 && sides != 2)
    return -1;
  if (density < 1 || density > 2)
    return -1;
  f = fopen(fname, "wb");
  if (f == NULL)
    return -1;
  putc(0, f);
  putc(0, f);
  if (eight) {
    if (density == 1)
      i = 0x14e0;
    else
      i = 0x2940;
  } else {
    if (density == 1)
      i = 0x0cc0;
    else
      i = 0x1900;
  }
  putc(i & 0xff, f);
  putc(i >> 8, f);
  i = 0;
  if (sides == 1)
    i |= 0x10;
  if (density == 1)
    i |= 0x40;
  if (ignden)
    i |= 0x80;
  putc(i, f);
  putc(0, f);
  putc(0, f);
  putc(0, f);
  putc(0, f);
  putc(0, f);
  putc(0, f);
  putc(0, f);
  putc(0, f);
  putc(0, f);
  putc(0, f);
  putc(0, f);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<trs_create_blank_dmk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    115a <trs_create_blank_dmk+0x2a>
movl   $0x2,-0x14(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    116b <trs_create_blank_dmk+0x3b>
movl   $0x2,-0x18(%rbp)
cmpl   $0x1,-0x14(%rbp)
je     118b <trs_create_blank_dmk+0x5b>
cmpl   $0x2,-0x14(%rbp)
je     118b <trs_create_blank_dmk+0x5b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1332 <trs_create_blank_dmk+0x202>
cmpl   $0x1,-0x18(%rbp)
jl     119f <trs_create_blank_dmk+0x6f>
cmpl   $0x2,-0x18(%rbp)
jle    11ab <trs_create_blank_dmk+0x7b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1332 <trs_create_blank_dmk+0x202>
mov    -0x10(%rbp),%rdi
lea    0xe4a(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11d6 <trs_create_blank_dmk+0xa6>
movl   $0xffffffff,-0x4(%rbp)
jmp    1332 <trs_create_blank_dmk+0x202>
mov    -0x28(%rbp),%rsi
xor    %edi,%edi
call   1040 <putc@plt>
mov    -0x28(%rbp),%rsi
xor    %edi,%edi
call   1040 <putc@plt>
cmpl   $0x0,-0x1c(%rbp)
je     1218 <trs_create_blank_dmk+0xe8>
cmpl   $0x1,-0x18(%rbp)
jne    120c <trs_create_blank_dmk+0xdc>
movl   $0x14e0,-0x2c(%rbp)
jmp    1213 <trs_create_blank_dmk+0xe3>
movl   $0x2940,-0x2c(%rbp)
jmp    123a <trs_create_blank_dmk+0x10a>
cmpl   $0x1,-0x18(%rbp)
jne    122e <trs_create_blank_dmk+0xfe>
movl   $0xcc0,-0x2c(%rbp)
jmp    1235 <trs_create_blank_dmk+0x105>
movl   $0x1900,-0x2c(%rbp)
jmp    123a <trs_create_blank_dmk+0x10a>
mov    -0x2c(%rbp),%edi
and    $0xff,%edi
mov    -0x28(%rbp),%rsi
call   1040 <putc@plt>
mov    -0x2c(%rbp),%edi
sar    $0x8,%edi
mov    -0x28(%rbp),%rsi
call   1040 <putc@plt>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    1275 <trs_create_blank_dmk+0x145>
mov    -0x2c(%rbp),%eax
or     $0x10,%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x18(%rbp)
jne    1288 <trs_create_blank_dmk+0x158>
mov    -0x2c(%rbp),%eax
or     $0x40,%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     129d <trs_create_blank_dmk+0x16d>
mov    -0x2c(%rbp),%eax
or     $0x80,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1040 <putc@plt>
mov    -0x28(%rbp),%rsi
xor    %edi,%edi
call   1040 <putc@plt>
mov    -0x28(%rbp),%rsi
xor    %edi,%edi
call   1040 <putc@plt>
mov    -0x28(%rbp),%rsi
xor    %edi,%edi
call   1040 <putc@plt>
mov    -0x28(%rbp),%rsi
xor    %edi,%edi
call   1040 <putc@plt>
mov    -0x28(%rbp),%rsi
xor    %edi,%edi
call   1040 <putc@plt>
mov    -0x28(%rbp),%rsi
xor    %edi,%edi
call   1040 <putc@plt>
mov    -0x28(%rbp),%rsi
xor    %edi,%edi
call   1040 <putc@plt>
mov    -0x28(%rbp),%rsi
xor    %edi,%edi
call   1040 <putc@plt>
mov    -0x28(%rbp),%rsi
xor    %edi,%edi
call   1040 <putc@plt>
mov    -0x28(%rbp),%rsi
xor    %edi,%edi
call   1040 <putc@plt>
mov    -0x28(%rbp),%rsi
xor    %edi,%edi
call   1040 <putc@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trs_create_blank_dmk>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
cmp    $0xffffffff,%esi
mov    $0x2,%eax
cmove  %eax,%ebx
mov    %edx,%ebp
cmp    $0xffffffff,%edx
cmove  %eax,%ebp
lea    -0x3(%rbx),%eax
mov    $0xffffffff,%r15d
cmp    $0xfffffffe,%eax
jb     1284 <trs_create_blank_dmk+0x154>
lea    -0x3(%rbp),%eax
cmp    $0xfffffffe,%eax
jb     1284 <trs_create_blank_dmk+0x154>
mov    %r8d,%r14d
mov    %ecx,%r12d
lea    0xe85(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1284 <trs_create_blank_dmk+0x154>
mov    %rax,%r13
xor    %r15d,%r15d
xor    %edi,%edi
mov    %rax,%rsi
call   1040 <putc@plt>
xor    %edi,%edi
mov    %r13,%rsi
call   1040 <putc@plt>
xor    %eax,%eax
cmp    $0x1,%ebx
sete   %al
shl    $0x4,%eax
mov    %r14d,0x4(%rsp)
lea    0x40(%rax),%r14d
cmp    $0x1,%ebp
mov    $0x14e0,%ecx
mov    $0x2940,%edx
cmove  %ecx,%edx
mov    $0xcc0,%ecx
mov    $0x1900,%ebx
cmove  %ecx,%ebx
cmovne %eax,%r14d
test   %r12d,%r12d
cmovne %edx,%ebx
movzbl %bl,%edi
mov    %r13,%rsi
call   1040 <putc@plt>
shr    $0x8,%ebx
mov    %ebx,%edi
mov    %r13,%rsi
call   1040 <putc@plt>
lea    0x80(%r14),%edi
cmpl   $0x0,0x4(%rsp)
cmove  %r14d,%edi
mov    %r13,%rsi
call   1040 <putc@plt>
xor    %edi,%edi
mov    %r13,%rsi
call   1040 <putc@plt>
xor    %edi,%edi
mov    %r13,%rsi
call   1040 <putc@plt>
xor    %edi,%edi
mov    %r13,%rsi
call   1040 <putc@plt>
xor    %edi,%edi
mov    %r13,%rsi
call   1040 <putc@plt>
xor    %edi,%edi
mov    %r13,%rsi
call   1040 <putc@plt>
xor    %edi,%edi
mov    %r13,%rsi
call   1040 <putc@plt>
xor    %edi,%edi
mov    %r13,%rsi
call   1040 <putc@plt>
xor    %edi,%edi
mov    %r13,%rsi
call   1040 <putc@plt>
xor    %edi,%edi
mov    %r13,%rsi
call   1040 <putc@plt>
xor    %edi,%edi
mov    %r13,%rsi
call   1040 <putc@plt>
xor    %edi,%edi
mov    %r13,%rsi
call   1040 <putc@plt>
mov    %r13,%rdi
call   1030 <fclose@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
define i32 @trs_create_blank_dmk(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32
store i8* %0, i8** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%14 = load i32, i32* %8
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %5
store i32 2, i32* %8
br label %17
17: ; preds = %16, %5
%18 = load i32, i32* %9
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 2, i32* %9
br label %21
21: ; preds = %20, %17
%22 = load i32, i32* %8
%23 = icmp ne i32 %22, 1
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load i32, i32* %8
%26 = icmp ne i32 %25, 2
br i1 %26, label %27, label %28
27: ; preds = %24
store i32 -1, i32* %6
br label %114
28: ; preds = %24, %21
%29 = load i32, i32* %9
%30 = icmp slt i32 %29, 1
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = load i32, i32* %9
%33 = icmp sgt i32 %32, 2
br i1 %33, label %34, label %35
34: ; preds = %31, %28
store i32 -1, i32* %6
br label %114
35: ; preds = %31
%36 = load i8*, i8** %7
%37 = call i32* @fopen(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %37, i32** %12
%38 = load i32*, i32** %12
%39 = icmp eq i32* %38, null
br i1 %39, label %40, label %41
40: ; preds = %35
store i32 -1, i32* %6
br label %114
41: ; preds = %35
%42 = load i32*, i32** %12
%43 = call i32 @putc(i32 0, i32* %42)
%44 = load i32*, i32** %12
%45 = call i32 @putc(i32 0, i32* %44)
%46 = load i32, i32* %10
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %54
48: ; preds = %41
%49 = load i32, i32* %9
%50 = icmp eq i32 %49, 1
br i1 %50, label %51, label %52
51: ; preds = %48
store i32 5344, i32* %13
br label %53
52: ; preds = %48
store i32 10560, i32* %13
br label %53
53: ; preds = %52, %51
br label %60
54: ; preds = %41
%55 = load i32, i32* %9
%56 = icmp eq i32 %55, 1
br i1 %56, label %57, label %58
57: ; preds = %54
store i32 3264, i32* %13
br label %59
58: ; preds = %54
store i32 6400, i32* %13
br label %59
59: ; preds = %58, %57
br label %60
60: ; preds = %59, %53
%61 = load i32, i32* %13
%62 = and i32 %61, 255
%63 = load i32*, i32** %12
%64 = call i32 @putc(i32 %62, i32* %63)
%65 = load i32, i32* %13
%66 = ashr i32 %65, 8
%67 = load i32*, i32** %12
%68 = call i32 @putc(i32 %66, i32* %67)
store i32 0, i32* %13
%69 = load i32, i32* %8
%70 = icmp eq i32 %69, 1
br i1 %70, label %71, label %74
71: ; preds = %60
%72 = load i32, i32* %13
%73 = or i32 %72, 16
store i32 %73, i32* %13
br label %74
74: ; preds = %71, %60
%75 = load i32, i32* %9
%76 = icmp eq i32 %75, 1
br i1 %76, label %77, label %80
77: ; preds = %74
%78 = load i32, i32* %13
%79 = or i32 %78, 64
store i32 %79, i32* %13
br label %80
80: ; preds = %77, %74
%81 = load i32, i32* %11
%82 = icmp ne i32 %81, 0
br i1 %82, label %83, label %86
83: ; preds = %80
%84 = load i32, i32* %13
%85 = or i32 %84, 128
store i32 %85, i32* %13
br label %86
86: ; preds = %83, %80
%87 = load i32, i32* %13
%88 = load i32*, i32** %12
%89 = call i32 @putc(i32 %87, i32* %88)
%90 = load i32*, i32** %12
%91 = call i32 @putc(i32 0, i32* %90)
%92 = load i32*, i32** %12
%93 = call i32 @putc(i32 0, i32* %92)
%94 = load i32*, i32** %12
%95 = call i32 @putc(i32 0, i32* %94)
%96 = load i32*, i32** %12
%97 = call i32 @putc(i32 0, i32* %96)
%98 = load i32*, i32** %12
%99 = call i32 @putc(i32 0, i32* %98)
%100 = load i32*, i32** %12
%101 = call i32 @putc(i32 0, i32* %100)
%102 = load i32*, i32** %12
%103 = call i32 @putc(i32 0, i32* %102)
%104 = load i32*, i32** %12
%105 = call i32 @putc(i32 0, i32* %104)
%106 = load i32*, i32** %12
%107 = call i32 @putc(i32 0, i32* %106)
%108 = load i32*, i32** %12
%109 = call i32 @putc(i32 0, i32* %108)
%110 = load i32*, i32** %12
%111 = call i32 @putc(i32 0, i32* %110)
%112 = load i32*, i32** %12
%113 = call i32 @fclose(i32* %112)
store i32 0, i32* %6
br label %114
114: ; preds = %86, %40, %34, %27
%115 = load i32, i32* %6
ret i32 %115
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
define i32 @trs_create_blank_dmk(i8* nocapture %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = icmp eq i32 %1, -1
%7 = select i1 %6, i32 2, i32 %1
%8 = icmp eq i32 %2, -1
%9 = select i1 %8, i32 2, i32 %2
%10 = add i32 %7, -3
%11 = icmp ult i32 %10, -2
%12 = add i32 %9, -3
%13 = icmp ult i32 %12, -2
%14 = or i1 %11, %13
br i1 %14, label %50, label %15
15: ; preds = %5
%16 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %50, label %18
18: ; preds = %15
%19 = tail call i32 @putc(i32 0, i32* %16)
%20 = tail call i32 @putc(i32 0, i32* %16)
%21 = icmp eq i32 %3, 0
%22 = icmp eq i32 %9, 1
%23 = select i1 %22, i32 5344, i32 10560
%24 = select i1 %22, i32 3264, i32 6400
%25 = select i1 %21, i32 %24, i32 %23
%26 = and i32 %25, 224
%27 = tail call i32 @putc(i32 %26, i32* %16)
%28 = lshr i32 %25, 8
%29 = tail call i32 @putc(i32 %28, i32* %16)
%30 = icmp eq i32 %7, 1
%31 = select i1 %30, i32 16, i32 0
%32 = or i32 %31, 64
%33 = select i1 %22, i32 %32, i32 %31
%34 = icmp eq i32 %4, 0
%35 = or i32 %33, 128
%36 = select i1 %34, i32 %33, i32 %35
%37 = tail call i32 @putc(i32 %36, i32* %16)
%38 = tail call i32 @putc(i32 0, i32* %16)
%39 = tail call i32 @putc(i32 0, i32* %16)
%40 = tail call i32 @putc(i32 0, i32* %16)
%41 = tail call i32 @putc(i32 0, i32* %16)
%42 = tail call i32 @putc(i32 0, i32* %16)
%43 = tail call i32 @putc(i32 0, i32* %16)
%44 = tail call i32 @putc(i32 0, i32* %16)
%45 = tail call i32 @putc(i32 0, i32* %16)
%46 = tail call i32 @putc(i32 0, i32* %16)
%47 = tail call i32 @putc(i32 0, i32* %16)
%48 = tail call i32 @putc(i32 0, i32* %16)
%49 = tail call i32 @fclose(i32* %16)
br label %50
50: ; preds = %15, %5, %18
%51 = phi i32 [ 0, %18 ], [ -1, %5 ], [ -1, %15 ]
ret i32 %51
}