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

/* Variables and functions */
char *MAP_FAILED;
int MAP_FILE;
int MAP_SHARED;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int, char *, ...);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ isalpha(unsigned char);
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ memcmp(char *, char *, int);
char *mmap(int /*<<< orphan*/ *, int, int /*<<< orphan*/, int, int, int);
int open(char *, int /*<<< orphan*/, int);
char *strdup(char *);
char toupper(unsigned char);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  off_t in_len;
  u_char *in_ptr;
  FILE *out_file;
  char *include_name, *cp;
  int i;
  if (argc != 3)
    usage();
  i = open(argv[1], O_RDONLY, 0644);
  if (i < 0)
    err(1, "unable to open %s", argv[1]);
  out_file = fopen(argv[2], "w+");
  if (out_file == NULL)
    err(1, "unable to create %s", argv[2]);
  include_name = strdup(argv[2]);
  if (include_name == NULL)
    err(1, "unable to allocate include name");
  for (cp = include_name; *cp != '\0'; cp++) {
    if (isalpha((unsigned char)*cp))
      *cp = toupper((unsigned char)*cp);
    else if (*cp == '.')
      *cp = '_';
  }
  in_len = lseek(i, 0, SEEK_END);
  if (in_len == (off_t)-1)
    err(1, "unable to determine length of input file");
  in_ptr = mmap(NULL, in_len, PROT_READ, MAP_FILE | MAP_SHARED, i, (off_t)0);
  if (in_ptr == MAP_FAILED)
    err(1, "unable to mmap input file");
  (void)close(i);
  fprintf(out_file, "/*\t$"
                    "NetBSD"
                    "$\t*/\n\n");
  fprintf(out_file,
          "/*\n"
          " * Firmware for Cyclades Z series multiport serial boards.\n"
          " * Automatically generated from:\n"
          " *\n"
          " *\t%s\n"
          " */\n\n",
          argv[1]);
  fprintf(out_file, "#ifndef _%s_\n", include_name);
  fprintf(out_file, "#define\t_%s_\n\n", include_name);
  fprintf(out_file, "static const uint8_t cycladesz_firmware[] = {\n");
  i = 0;
  while (in_len != 0) {
    if (i == 0)
      fprintf(out_file, "\t");
    if (*in_ptr == '@' && in_len > 4 && memcmp(in_ptr, "@(#)", 4) == 0)
      fprintf(out_file, "0x%02x,", '_');
    else
      fprintf(out_file, "0x%02x,", *in_ptr);
    in_ptr++;
    in_len--;
    i++;
    if (i == 10) {
      fprintf(out_file, "\n");
      i = 0;
    } else if (in_len != 0) {
      fprintf(out_file, " ");
    }
  }
  fprintf(out_file, "\n};\n\n");
  fprintf(out_file, "#endif /* _%s_ */\n", include_name);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11e7 <main+0x27>
mov    $0x0,%al
call   10b0 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
mov    $0x1a4,%edx
call   10c0 <open@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    122a <main+0x6a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    $0x1,%edi
lea    0xddd(%rip),%rsi
mov    $0x0,%al
call   1090 <err@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdd9(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1268 <main+0xa8>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
mov    $0x1,%edi
lea    0xdb4(%rip),%rsi
mov    $0x0,%al
call   1090 <err@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10e0 <strdup@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1297 <main+0xd7>
mov    $0x1,%edi
lea    0xd99(%rip),%rsi
mov    $0x0,%al
call   1090 <err@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1310 <main+0x150>
mov    -0x38(%rbp),%rax
movzbl (%rax),%edi
call   10a0 <isalpha@plt>
cmp    $0x0,%rax
je     12de <main+0x11e>
mov    -0x38(%rbp),%rax
movzbl (%rax),%edi
call   1030 <toupper@plt>
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %cl,(%rax)
jmp    12fa <main+0x13a>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    12f5 <main+0x135>
mov    -0x38(%rbp),%rax
movb   $0x5f,(%rax)
jmp    12fa <main+0x13a>
jmp    12ff <main+0x13f>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    129f <main+0xdf>
mov    -0x3c(%rbp),%edi
mov    0x2cbe(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1343 <main+0x183>
mov    $0x1,%edi
lea    0xd0d(%rip),%rsi
mov    $0x0,%al
call   1090 <err@plt>
mov    -0x14(%rbp),%esi
mov    0x2cab(%rip),%rax
mov    (%rax),%edx
mov    0x2c72(%rip),%rax
mov    (%rax),%ecx
mov    0x2c89(%rip),%rax
or     (%rax),%ecx
mov    -0x3c(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2c38(%rip),%rcx
cmp    (%rcx),%rax
jne    139c <main+0x1dc>
mov    $0x1,%edi
lea    0xcdd(%rip),%rsi
mov    $0x0,%al
call   1090 <err@plt>
mov    -0x3c(%rbp),%edi
call   1060 <close@plt>
mov    -0x28(%rbp),%rdi
lea    0xcdd(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xcd4(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xd2c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xd24(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xd21(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x0,-0x3c(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1515 <main+0x355>
cmpl   $0x0,-0x3c(%rbp)
jne    143b <main+0x27b>
mov    -0x28(%rbp),%rdi
lea    0xd23(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x40,%eax
jne    1490 <main+0x2d0>
cmpl   $0x4,-0x14(%rbp)
jle    1490 <main+0x2d0>
mov    -0x20(%rbp),%rdi
lea    0xcf9(%rip),%rsi
mov    $0x4,%edx
call   1070 <memcmp@plt>
cmp    $0x0,%rax
jne    1490 <main+0x2d0>
mov    -0x28(%rbp),%rdi
lea    0xcdf(%rip),%rsi
mov    $0x5f,%edx
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    14a9 <main+0x2e9>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rax
movsbl (%rax),%edx
lea    0xcbc(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
cmpl   $0xa,-0x3c(%rbp)
jne    14ef <main+0x32f>
mov    -0x28(%rbp),%rdi
lea    0xbbf(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x0,-0x3c(%rbp)
jmp    1510 <main+0x350>
cmpl   $0x0,-0x14(%rbp)
je     150b <main+0x34b>
mov    -0x28(%rbp),%rdi
lea    0xc62(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    1510 <main+0x350>
jmp    1415 <main+0x255>
mov    -0x28(%rbp),%rdi
lea    0xc48(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xc38(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
cmp    $0x3,%edi
je     11fa <main+0x1a>
xor    %eax,%eax
call   10c0 <usage@plt>
mov    0x8(%r15),%rdi
mov    0x2dcb(%rip),%rax
mov    (%rax),%esi
mov    $0x1a4,%edx
call   10d0 <open@plt>
mov    %eax,%r12d
test   %eax,%eax
jns    122f <main+0x4f>
mov    0x8(%r15),%rdx
lea    0xddd(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   10a0 <err@plt>
mov    0x10(%r15),%rdi
lea    0xdd8(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,%r13
test   %rax,%rax
jne    125e <main+0x7e>
mov    0x10(%r15),%rdx
lea    0xdc3(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   10a0 <err@plt>
mov    0x10(%r15),%rdi
call   1100 <strdup@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1282 <main+0xa2>
lea    0xdb3(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   10a0 <err@plt>
mov    (%r14),%al
test   %al,%al
je     12bf <main+0xdf>
mov    %r14,%rbx
jmp    12a6 <main+0xc6>
xchg   %ax,%ax
movzbl %cl,%edi
call   1030 <toupper@plt>
mov    %al,(%rbx)
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     12bf <main+0xdf>
movzbl %al,%edi
call   10b0 <isalpha@plt>
movzbl (%rbx),%ecx
test   %rax,%rax
jne    1290 <main+0xb0>
mov    $0x5f,%al
cmp    $0x2e,%cl
je     1298 <main+0xb8>
jmp    129a <main+0xba>
mov    0x2d12(%rip),%rax
mov    (%rax),%edx
mov    %r12d,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    12ec <main+0x10c>
lea    0xd69(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   10a0 <err@plt>
mov    0x2d05(%rip),%rax
mov    (%rax),%edx
mov    0x2ccc(%rip),%rax
mov    0x2ce5(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    %ebp,%esi
mov    %r12d,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%rbx
mov    0x2c98(%rip),%rax
cmp    (%rax),%rbx
jne    1338 <main+0x158>
lea    0xd46(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   10a0 <err@plt>
mov    %r12d,%edi
call   1060 <close@plt>
lea    0xd45(%rip),%rdi
mov    $0x10,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   10f0 <fwrite@plt>
mov    0x8(%r15),%rdx
lea    0xd39(%rip),%rsi
xor    %r15d,%r15d
mov    %r13,%rdi
xor    %eax,%eax
call   1090 <fprintf@plt>
lea    0xd93(%rip),%rsi
mov    %r13,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
lea    0xd8d(%rip),%rsi
mov    %r13,%rdi
mov    %r14,(%rsp)
mov    %r14,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
lea    0xd84(%rip),%rdi
mov    $0x2e,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   10f0 <fwrite@plt>
test   %ebp,%ebp
je     1458 <main+0x278>
lea    0xd97(%rip),%r12
jmp    13e6 <main+0x206>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
add    $0xffffffff,%ebp
mov    %r13,%rsi
call   1070 <fputc@plt>
mov    %r14d,%r15d
test   %ebp,%ebp
je     1458 <main+0x278>
test   %r15d,%r15d
jne    13f8 <main+0x218>
mov    $0x9,%edi
mov    %r13,%rsi
call   1070 <fputc@plt>
movzbl (%rbx),%eax
cmp    $0x40,%al
jne    1420 <main+0x240>
cmp    $0x5,%ebp
jl     1420 <main+0x240>
mov    %rbx,%rdi
lea    0xd49(%rip),%rsi
mov    $0x4,%edx
call   1080 <memcmp@plt>
test   %rax,%rax
je     1451 <main+0x271>
movzbl (%rbx),%eax
movsbl %al,%edx
xor    %r14d,%r14d
mov    %r13,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
add    $0x1,%r15d
mov    $0xa,%edi
cmp    $0xa,%r15d
je     13d0 <main+0x1f0>
mov    $0x20,%edi
mov    %r15d,%r14d
cmp    $0x1,%ebp
jne    13d0 <main+0x1f0>
jmp    1458 <main+0x278>
mov    $0x5f,%edx
jmp    1423 <main+0x243>
lea    0xd05(%rip),%rdi
mov    $0x5,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   10f0 <fwrite@plt>
lea    0xcf2(%rip),%rsi
mov    %r13,%rdi
mov    (%rsp),%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [18 x i8] c"unable to open %s\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [20 x i8] c"unable to create %s\00"
@.str.3 = [32 x i8] c"unable to allocate include name\00"
@SEEK_END = global i32 0
@.str.4 = [41 x i8] c"unable to determine length of input file\00"
@PROT_READ = global i32 0
@MAP_FILE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.5 = [26 x i8] c"unable to mmap input file\00"
@.str.6 = [17 x i8] c"/*\09$NetBSD$\09*/\0A\0A\00"
@.str.7 = [110 x i8] c"/*\0A * Firmware for Cyclades Z series multiport serial boards.\0A * Automatically generated from:\0A *\0A *\09%s\0A */\0A\0A\00"
@.str.8 = [14 x i8] c"#ifndef _%s_\0A\00"
@.str.9 = [15 x i8] c"#define\09_%s_\0A\0A\00"
@.str.10 = [47 x i8] c"static const uint8_t cycladesz_firmware[] = {\0A\00"
@.str.11 = [2 x i8] c"\09\00"
@.str.12 = [5 x i8] c"@(#)\00"
@.str.13 = [8 x i8] c"0x%02x,\00"
@.str.14 = [2 x i8] c"\0A\00"
@.str.15 = [2 x i8] c" \00"
@.str.16 = [6 x i8] c"\0A};\0A\0A\00"
@.str.17 = [19 x i8] c"#endif /* _%s_ */\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (...) @usage()
br label %16
16: ; preds = %14, %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = load i32, i32* @O_RDONLY
%21 = call i32 @open(i8* %19, i32 %20, i32 420)
store i32 %21, i32* %11
%22 = load i32, i32* %11
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %16
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %24, %16
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %33, i32** %8
%34 = load i32*, i32** %8
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %41
36: ; preds = %29
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %39)
br label %41
41: ; preds = %36, %29
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = load i8*, i8** %43
%45 = call i8* @strdup(i8* %44)
store i8* %45, i8** %9
%46 = load i8*, i8** %9
%47 = icmp eq i8* %46, null
br i1 %47, label %48, label %50
48: ; preds = %41
%49 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
br label %50
50: ; preds = %48, %41
%51 = load i8*, i8** %9
store i8* %51, i8** %10
br label %52
52: ; preds = %76, %50
%53 = load i8*, i8** %10
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %79
57: ; preds = %52
%58 = load i8*, i8** %10
%59 = load i8, i8* %58
%60 = call i64 @isalpha(i8 zeroext %59)
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %67
62: ; preds = %57
%63 = load i8*, i8** %10
%64 = load i8, i8* %63
%65 = call signext i8 @toupper(i8 zeroext %64)
%66 = load i8*, i8** %10
store i8 %65, i8* %66
br label %75
67: ; preds = %57
%68 = load i8*, i8** %10
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = icmp eq i32 %70, 46
br i1 %71, label %72, label %74
72: ; preds = %67
%73 = load i8*, i8** %10
store i8 95, i8* %73
br label %74
74: ; preds = %72, %67
br label %75
75: ; preds = %74, %62
br label %76
76: ; preds = %75
%77 = load i8*, i8** %10
%78 = getelementptr inbounds i8, i8* %77, i32 1
store i8* %78, i8** %10
br label %52
79: ; preds = %52
%80 = load i32, i32* %11
%81 = load i32, i32* @SEEK_END
%82 = call i32 @lseek(i32 %80, i32 0, i32 %81)
store i32 %82, i32* %6
%83 = load i32, i32* %6
%84 = icmp eq i32 %83, -1
br i1 %84, label %85, label %87
85: ; preds = %79
%86 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0))
br label %87
87: ; preds = %85, %79
%88 = load i32, i32* %6
%89 = load i32, i32* @PROT_READ
%90 = load i32, i32* @MAP_FILE
%91 = load i32, i32* @MAP_SHARED
%92 = or i32 %90, %91
%93 = load i32, i32* %11
%94 = call i8* @mmap(i32* null, i32 %88, i32 %89, i32 %92, i32 %93, i32 0)
store i8* %94, i8** %7
%95 = load i8*, i8** %7
%96 = load i8*, i8** @MAP_FAILED
%97 = icmp eq i8* %95, %96
br i1 %97, label %98, label %100
98: ; preds = %87
%99 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
br label %100
100: ; preds = %98, %87
%101 = load i32, i32* %11
%102 = call i32 @close(i32 %101)
%103 = load i32*, i32** %8
%104 = call i32 (i32*, i8*, ...) @fprintf(i32* %103, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%105 = load i32*, i32** %8
%106 = load i8**, i8*** %5
%107 = getelementptr inbounds i8*, i8** %106, i64 1
%108 = load i8*, i8** %107
%109 = call i32 (i32*, i8*, ...) @fprintf(i32* %105, i8* getelementptr inbounds ([110 x i8], [110 x i8]* @.str.7, i64 0, i64 0), i8* %108)
%110 = load i32*, i32** %8
%111 = load i8*, i8** %9
%112 = call i32 (i32*, i8*, ...) @fprintf(i32* %110, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8* %111)
%113 = load i32*, i32** %8
%114 = load i8*, i8** %9
%115 = call i32 (i32*, i8*, ...) @fprintf(i32* %113, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i8* %114)
%116 = load i32*, i32** %8
%117 = call i32 (i32*, i8*, ...) @fprintf(i32* %116, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.10, i64 0, i64 0))
store i32 0, i32* %11
br label %118
118: ; preds = %167, %100
%119 = load i32, i32* %6
%120 = icmp ne i32 %119, 0
br i1 %120, label %121, label %168
121: ; preds = %118
%122 = load i32, i32* %11
%123 = icmp eq i32 %122, 0
br i1 %123, label %124, label %127
124: ; preds = %121
%125 = load i32*, i32** %8
%126 = call i32 (i32*, i8*, ...) @fprintf(i32* %125, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
br label %127
127: ; preds = %124, %121
%128 = load i8*, i8** %7
%129 = load i8, i8* %128
%130 = sext i8 %129 to i32
%131 = icmp eq i32 %130, 64
br i1 %131, label %132, label %142
132: ; preds = %127
%133 = load i32, i32* %6
%134 = icmp sgt i32 %133, 4
br i1 %134, label %135, label %142
135: ; preds = %132
%136 = load i8*, i8** %7
%137 = call i64 @memcmp(i8* %136, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0), i32 4)
%138 = icmp eq i64 %137, 0
br i1 %138, label %139, label %142
139: ; preds = %135
%140 = load i32*, i32** %8
%141 = call i32 (i32*, i8*, ...) @fprintf(i32* %140, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.13, i64 0, i64 0), i32 95)
br label %148
142: ; preds = %135, %132, %127
%143 = load i32*, i32** %8
%144 = load i8*, i8** %7
%145 = load i8, i8* %144
%146 = sext i8 %145 to i32
%147 = call i32 (i32*, i8*, ...) @fprintf(i32* %143, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.13, i64 0, i64 0), i32 %146)
br label %148
148: ; preds = %142, %139
%149 = load i8*, i8** %7
%150 = getelementptr inbounds i8, i8* %149, i32 1
store i8* %150, i8** %7
%151 = load i32, i32* %6
%152 = add nsw i32 %151, -1
store i32 %152, i32* %6
%153 = load i32, i32* %11
%154 = add nsw i32 %153, 1
store i32 %154, i32* %11
%155 = load i32, i32* %11
%156 = icmp eq i32 %155, 10
br i1 %156, label %157, label %160
157: ; preds = %148
%158 = load i32*, i32** %8
%159 = call i32 (i32*, i8*, ...) @fprintf(i32* %158, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.14, i64 0, i64 0))
store i32 0, i32* %11
br label %167
160: ; preds = %148
%161 = load i32, i32* %6
%162 = icmp ne i32 %161, 0
br i1 %162, label %163, label %166
163: ; preds = %160
%164 = load i32*, i32** %8
%165 = call i32 (i32*, i8*, ...) @fprintf(i32* %164, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0))
br label %166
166: ; preds = %163, %160
br label %167
167: ; preds = %166, %157
br label %118
168: ; preds = %118
%169 = load i32*, i32** %8
%170 = call i32 (i32*, i8*, ...) @fprintf(i32* %169, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.16, i64 0, i64 0))
%171 = load i32*, i32** %8
%172 = load i8*, i8** %9
%173 = call i32 (i32*, i8*, ...) @fprintf(i32* %171, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.17, i64 0, i64 0), i8* %172)
ret i32 0
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [18 x i8] c"unable to open %s\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [20 x i8] c"unable to create %s\00"
@.str.3 = [32 x i8] c"unable to allocate include name\00"
@SEEK_END = global i32 0
@.str.4 = [41 x i8] c"unable to determine length of input file\00"
@PROT_READ = global i32 0
@MAP_FILE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.5 = [26 x i8] c"unable to mmap input file\00"
@.str.6 = [17 x i8] c"/*\09$NetBSD$\09*/\0A\0A\00"
@.str.7 = [110 x i8] c"/*\0A * Firmware for Cyclades Z series multiport serial boards.\0A * Automatically generated from:\0A *\0A *\09%s\0A */\0A\0A\00"
@.str.8 = [14 x i8] c"#ifndef _%s_\0A\00"
@.str.9 = [15 x i8] c"#define\09_%s_\0A\0A\00"
@.str.10 = [47 x i8] c"static const uint8_t cycladesz_firmware[] = {\0A\00"
@.str.12 = [5 x i8] c"@(#)\00"
@.str.13 = [8 x i8] c"0x%02x,\00"
@.str.16 = [6 x i8] c"\0A};\0A\0A\00"
@.str.17 = [19 x i8] c"#endif /* _%s_ */\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 (...) @usage()
br label %6
6: ; preds = %4, %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = load i32, i32* @O_RDONLY
%10 = tail call i32 @open(i8* %8, i32 %9, i32 420)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %6
%13 = load i8*, i8** %7
%14 = tail call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %12, %6
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load i8*, i8** %16
%22 = tail call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %20, %15
%24 = load i8*, i8** %16
%25 = tail call i8* @strdup(i8* %24)
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = tail call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
br label %29
29: ; preds = %27, %23
%30 = load i8, i8* %25
%31 = icmp eq i8 %30, 0
br i1 %31, label %48, label %32
32: ; preds = %29, %44
%33 = phi i8 [ %46, %44 ], [ %30, %29 ]
%34 = phi i8* [ %45, %44 ], [ %25, %29 ]
%35 = tail call i64 @isalpha(i8 zeroext %33)
%36 = icmp eq i64 %35, 0
%37 = load i8, i8* %34
br i1 %36, label %40, label %38
38: ; preds = %32
%39 = tail call signext i8 @toupper(i8 zeroext %37)
br label %42
40: ; preds = %32
%41 = icmp eq i8 %37, 46
br i1 %41, label %42, label %44
42: ; preds = %40, %38
%43 = phi i8 [ %39, %38 ], [ 95, %40 ]
store i8 %43, i8* %34
br label %44
44: ; preds = %42, %40
%45 = getelementptr inbounds i8, i8* %34, i64 1
%46 = load i8, i8* %45
%47 = icmp eq i8 %46, 0
br i1 %47, label %48, label %32
48: ; preds = %44, %29
%49 = load i32, i32* @SEEK_END
%50 = tail call i32 @lseek(i32 %10, i32 0, i32 %49)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %54
52: ; preds = %48
%53 = tail call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0))
br label %54
54: ; preds = %52, %48
%55 = load i32, i32* @PROT_READ
%56 = load i32, i32* @MAP_FILE
%57 = load i32, i32* @MAP_SHARED
%58 = or i32 %57, %56
%59 = tail call i8* @mmap(i32* null, i32 %50, i32 %55, i32 %58, i32 %10, i32 0)
%60 = load i8*, i8** @MAP_FAILED
%61 = icmp eq i8* %59, %60
br i1 %61, label %62, label %64
62: ; preds = %54
%63 = tail call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
br label %64
64: ; preds = %62, %54
%65 = tail call i32 @close(i32 %10)
%66 = tail call i64 @fwrite(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i64 16, i64 1, i32* %18)
%67 = load i8*, i8** %7
%68 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([110 x i8], [110 x i8]* @.str.7, i64 0, i64 0), i8* %67)
%69 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8* %25)
%70 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i8* %25)
%71 = tail call i64 @fwrite(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.10, i64 0, i64 0), i64 46, i64 1, i32* %18)
%72 = icmp eq i32 %50, 0
br i1 %72, label %107, label %73
73: ; preds = %64, %102
%74 = phi i32 [ %104, %102 ], [ 0, %64 ]
%75 = phi i32 [ %97, %102 ], [ %50, %64 ]
%76 = phi i8* [ %96, %102 ], [ %59, %64 ]
%77 = icmp eq i32 %74, 0
br i1 %77, label %78, label %80
78: ; preds = %73
%79 = tail call i32 @fputc(i32 9, i32* %18)
br label %80
80: ; preds = %78, %73
%81 = load i8, i8* %76
%82 = icmp eq i8 %81, 64
%83 = icmp sgt i32 %75, 4
%84 = select i1 %82, i1 %83, i1 false
br i1 %84, label %85, label %90
85: ; preds = %80
%86 = tail call i64 @memcmp(i8* %76, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0), i32 4)
%87 = icmp eq i64 %86, 0
br i1 %87, label %93, label %88
88: ; preds = %85
%89 = load i8, i8* %76
br label %90
90: ; preds = %88, %80
%91 = phi i8 [ %89, %88 ], [ %81, %80 ]
%92 = sext i8 %91 to i32
br label %93
93: ; preds = %85, %90
%94 = phi i32 [ %92, %90 ], [ 95, %85 ]
%95 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.13, i64 0, i64 0), i32 %94)
%96 = getelementptr inbounds i8, i8* %76, i64 1
%97 = add nsw i32 %75, -1
%98 = add nsw i32 %74, 1
%99 = icmp eq i32 %98, 10
br i1 %99, label %102, label %100
100: ; preds = %93
%101 = icmp eq i32 %97, 0
br i1 %101, label %107, label %102
102: ; preds = %100, %93
%103 = phi i32 [ 10, %93 ], [ 32, %100 ]
%104 = phi i32 [ 0, %93 ], [ %98, %100 ]
%105 = tail call i32 @fputc(i32 %103, i32* %18)
%106 = icmp eq i32 %97, 0
br i1 %106, label %107, label %73
107: ; preds = %100, %102, %64
%108 = tail call i64 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.16, i64 0, i64 0), i64 5, i64 1, i32* %18)
%109 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.17, i64 0, i64 0), i8* %25)
ret i32 0
}