#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
  int /*<<< orphan*/ st_gid;
  int /*<<< orphan*/ st_uid;
};
struct bsdconv_instance {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
struct bsdconv_instance *bsdconv_create(char *);
int /*<<< orphan*/ bsdconv_destroy(struct bsdconv_instance *);
char *bsdconv_error();
int /*<<< orphan*/ bsdconv_file(struct bsdconv_instance *, int /*<<< orphan*/ *,
                                int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fchmod(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fchown(int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fstat(int /*<<< orphan*/, struct stat *);
int /*<<< orphan*/ list_modules();
char *malloc(scalar_t__);
int mkstemp(char *);
int /*<<< orphan*/ rename(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ unlink(char *);
int main(int argc, char *argv[]) {
  char *t;
  int fd;
  char *tmp = NULL;
  struct bsdconv_instance *ins;
  FILE *inf = NULL, *otf = stdout;
  int inplace = 0;
  int i;
  if (argc < 2) {
    fprintf(stderr,
            "Usage:\n\t %s conversion|-l [-i] [file] [...]\n\t\t-i:\tsave "
            "in-place\n\t\t-l:\tlist codecs\n",
            argv[0]);
    exit(1);
  }
  i = 2;
  if (strcmp(argv[1], "-l") == 0) {
    list_modules();
    return 0;
  }
  if (argc > 2)
    while (i < argc) {
      if (strcmp(argv[i], "-i") == 0)
        inplace = 1;
      else if (strcmp(argv[i], "-l") == 0)
        list_modules();
      else
        break;
      i += 1;
    }
  ins = bsdconv_create(argv[1]);
  if (!ins) {
    t = bsdconv_error();
    fprintf(stderr, "%s\n", t);
    free(t);
    exit(1);
  }
  if (i >= argc) {
    bsdconv_file(ins, stdin, stdout, NULL);
  } else
    for (; i < argc; ++i) {
      if (inplace) {
        inf = fopen(argv[i], "rb");
        if (inf == NULL) {
          fprintf(stderr, "Failed opening file %s.\n", argv[i]);
          bsdconv_destroy(ins);
          exit(1);
        }
        tmp = malloc(strlen(argv[i]) + 8);
        strcpy(tmp, argv[i]);
        strcat(tmp, ".XXXXXX");
        if ((fd = mkstemp(tmp)) == -1) {
          free(tmp);
          fprintf(stderr, "Failed creating temp file.\n");
          bsdconv_destroy(ins);
          exit(1);
        }
        otf = fdopen(fd, "wb");
        if (!otf) {
          fprintf(stderr, "Unable to open output file for %s\n", argv[i]);
          bsdconv_destroy(ins);
          exit(1);
        }
        struct stat stat;
        fstat(fileno(inf), &stat);
        fchown(fileno(otf), stat.st_uid, stat.st_gid);
        fchmod(fileno(otf), stat.st_mode);
        bsdconv_file(ins, inf, otf, argv[i]);
        fclose(inf);
        fclose(otf);
        unlink(argv[i]);
        rename(tmp, argv[i]);
        free(tmp);
      } else {
        inf = fopen(argv[i], "rb");
        if (inf == NULL) {
          fprintf(stderr, "Failed opening file %s.\n", argv[i]);
          bsdconv_destroy(ins);
          exit(1);
        }
        bsdconv_file(ins, inf, stdout, argv[i]);
        fclose(inf);
      }
    }
  bsdconv_destroy(ins);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x38(%rbp)
mov    0x2d33(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    12dd <main+0x6d>
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd34(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
movl   $0x2,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd60(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    1315 <main+0xa5>
mov    $0x0,%al
call   10b0 <list_modules@plt>
movl   $0x0,-0x4(%rbp)
jmp    16db <main+0x46b>
cmpl   $0x2,-0x8(%rbp)
jle    13a9 <main+0x139>
jmp    1324 <main+0xb4>
mov    -0x48(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    13a4 <main+0x134>
mov    -0x10(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd13(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    135e <main+0xee>
movl   $0x1,-0x44(%rbp)
jmp    1396 <main+0x126>
mov    -0x10(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xce2(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    138c <main+0x11c>
mov    $0x0,%al
call   10b0 <list_modules@plt>
jmp    1391 <main+0x121>
jmp    13a4 <main+0x134>
jmp    1396 <main+0x126>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1324 <main+0xb4>
jmp    13a9 <main+0x139>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10d0 <bsdconv_create@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    13fe <main+0x18e>
mov    $0x0,%al
call   1060 <bsdconv_error@plt>
mov    %rax,-0x18(%rbp)
mov    0x2c01(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xcd7(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
mov    -0x48(%rbp),%eax
cmp    -0x8(%rbp),%eax
jl     1430 <main+0x1c0>
mov    -0x30(%rbp),%rdi
mov    0x2bd3(%rip),%rax
mov    (%rax),%rsi
mov    0x2bb1(%rip),%rax
mov    (%rax),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1090 <bsdconv_file@plt>
jmp    16cb <main+0x45b>
jmp    1435 <main+0x1c5>
mov    -0x48(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    16c6 <main+0x456>
cmpl   $0x0,-0x44(%rbp)
je     162a <main+0x3ba>
mov    -0x10(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xbfb(%rip),%rsi
call   1140 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    14a8 <main+0x238>
mov    0x2b5f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xbce(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1180 <bsdconv_destroy@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
mov    -0x10(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1080 <strlen@plt>
mov    %rax,%rdi
add    $0x8,%rdi
call   10f0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1050 <strcpy@plt>
mov    -0x28(%rbp),%rdi
lea    0xb8c(%rip),%rsi
call   1160 <strcat@plt>
mov    -0x28(%rbp),%rdi
call   1100 <mkstemp@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    1536 <main+0x2c6>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    0x2ac5(%rip),%rax
mov    (%rax),%edi
lea    0xb61(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1180 <bsdconv_destroy@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
mov    -0x1c(%rbp),%edi
lea    0xb59(%rip),%rsi
call   1110 <fdopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    158a <main+0x31a>
mov    0x2a7d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xb2c(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1180 <bsdconv_destroy@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
mov    -0x38(%rbp),%rdi
call   10e0 <fileno@plt>
mov    %eax,%edi
lea    -0x58(%rbp),%rsi
call   1190 <fstat@plt>
mov    -0x40(%rbp),%rdi
call   10e0 <fileno@plt>
mov    %eax,%edi
mov    -0x50(%rbp),%esi
mov    -0x54(%rbp),%edx
call   1130 <fchown@plt>
mov    -0x40(%rbp),%rdi
call   10e0 <fileno@plt>
mov    %eax,%edi
mov    -0x58(%rbp),%esi
call   1120 <fchmod@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x10(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
call   1090 <bsdconv_file@plt>
mov    -0x38(%rbp),%rdi
call   1070 <fclose@plt>
mov    -0x40(%rbp),%rdi
call   1070 <fclose@plt>
mov    -0x10(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <unlink@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1150 <rename@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    16b3 <main+0x443>
mov    -0x10(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xa1c(%rip),%rsi
call   1140 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1687 <main+0x417>
mov    0x2980(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0x9ef(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1180 <bsdconv_destroy@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    0x293a(%rip),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
call   1090 <bsdconv_file@plt>
mov    -0x38(%rbp),%rdi
call   1070 <fclose@plt>
jmp    16b8 <main+0x448>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1435 <main+0x1c5>
jmp    16cb <main+0x45b>
mov    -0x30(%rbp),%rdi
call   1180 <bsdconv_destroy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r12
cmp    $0x1,%edi
jle    154b <main+0x2db>
mov    %edi,%ebp
mov    0x8(%r12),%rdi
lea    0xdbb(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     130a <main+0x9a>
cmp    $0x3,%ebp
mov    %ebp,0x14(%rsp)
jb     1316 <main+0xa6>
mov    %ebp,%ebx
mov    $0x2,%r15d
lea    0xd9c(%rip),%r13
lea    0xd92(%rip),%rbp
xor    %r14d,%r14d
jmp    12df <main+0x6f>
cs nopw 0x0(%rax,%rax,1)
mov    $0x1,%r14d
add    $0x1,%r15
cmp    %r15,%rbx
je     1321 <main+0xb1>
mov    (%r12,%r15,8),%rdi
mov    %r13,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     12d0 <main+0x60>
mov    (%r12,%r15,8),%rdi
mov    %rbp,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
jne    1324 <main+0xb4>
xor    %eax,%eax
call   10b0 <list_modules@plt>
jmp    12d6 <main+0x66>
xor    %eax,%eax
call   10b0 <list_modules@plt>
jmp    14d6 <main+0x266>
mov    $0x2,%r15d
xor    %r14d,%r14d
jmp    1328 <main+0xb8>
mov    %ebx,%r15d
mov    0x14(%rsp),%ebp
mov    0x8(%r12),%rdi
call   10d0 <bsdconv_create@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     1570 <main+0x300>
cmp    %ebp,%r15d
jge    14ac <main+0x23c>
mov    %r15d,%eax
lea    (%r12,%rax,8),%rbx
jmp    1371 <main+0x101>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x8,%rbx
add    $0x1,%r15d
cmp    %ebp,%r15d
jge    14cc <main+0x25c>
mov    (%rbx),%rdi
lea    0xcde(%rip),%rsi
call   1140 <fopen@plt>
mov    %rax,%r12
test   %r14d,%r14d
je     1480 <main+0x210>
test   %r12,%r12
je     14e7 <main+0x277>
mov    (%rbx),%rbp
mov    %rbp,%rdi
call   1080 <strlen@plt>
lea    0x8(%rax),%rdi
call   10f0 <malloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    %rbp,%rsi
call   1050 <strcpy@plt>
mov    %r13,%rdi
lea    0xcb4(%rip),%rsi
call   1160 <strcat@plt>
mov    %r13,%rdi
call   1100 <mkstemp@plt>
cmp    $0xffffffff,%eax
je     14fc <main+0x28c>
mov    %eax,%edi
lea    0xcb9(%rip),%rsi
call   1110 <fdopen@plt>
test   %rax,%rax
je     151d <main+0x2ad>
mov    %rax,%rbp
mov    %r12,%rdi
call   10e0 <fileno@plt>
mov    %eax,%edi
lea    0x18(%rsp),%rsi
call   1190 <fstat@plt>
mov    %rbp,%rdi
call   10e0 <fileno@plt>
mov    0x1c(%rsp),%edx
mov    0x20(%rsp),%esi
mov    %eax,%edi
call   1130 <fchown@plt>
mov    %rbp,%rdi
call   10e0 <fileno@plt>
mov    0x18(%rsp),%esi
mov    %eax,%edi
call   1120 <fchmod@plt>
mov    (%rbx),%rcx
mov    0x8(%rsp),%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1090 <bsdconv_file@plt>
mov    %r12,%rdi
call   1070 <fclose@plt>
mov    %rbp,%rdi
call   1070 <fclose@plt>
mov    (%rbx),%rdi
call   1040 <unlink@plt>
mov    (%rbx),%rsi
mov    %r13,%rdi
call   1150 <rename@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    0x14(%rsp),%ebp
jmp    1360 <main+0xf0>
cs nopw 0x0(%rax,%rax,1)
test   %r12,%r12
je     14e7 <main+0x277>
mov    0x2b44(%rip),%rax
mov    (%rax),%rdx
mov    (%rbx),%rcx
mov    0x8(%rsp),%rdi
mov    %r12,%rsi
call   1090 <bsdconv_file@plt>
mov    %r12,%rdi
call   1070 <fclose@plt>
jmp    1360 <main+0xf0>
mov    0x2b35(%rip),%rax
mov    (%rax),%rsi
mov    0x2b13(%rip),%rax
mov    (%rax),%rdx
mov    0x8(%rsp),%rdi
xor    %ecx,%ecx
call   1090 <bsdconv_file@plt>
mov    0x8(%rsp),%rdi
call   1180 <bsdconv_destroy@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2aea(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xb62(%rip),%rsi
jmp    1530 <main+0x2c0>
mov    %r13,%rdi
call   1030 <free@plt>
mov    0x2acd(%rip),%rax
mov    (%rax),%edi
lea    0xb69(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
jmp    1537 <main+0x2c7>
mov    0x2ab4(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xb6c(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    0x8(%rsp),%rdi
call   1180 <bsdconv_destroy@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
mov    0x2a86(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rdx
lea    0xaa1(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
xor    %eax,%eax
call   1060 <bsdconv_error@plt>
mov    %rax,%rbx
mov    0x2a57(%rip),%rax
mov    (%rax),%edi
lea    0xb31(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   1170 <exit@plt>

LLVM IR (-O0):
%struct.bsdconv_instance = type { i32 }
%struct.stat = type { i32, i32, i32 }
@stdout = global i32* null
@stderr = global i32 0
@.str = [83 x i8] c"Usage:\0A\09 %s conversion|-l [-i] [file] [...]\0A\09\09-i:\09save in-place\0A\09\09-l:\09list codecs\0A\00"
@.str.1 = [3 x i8] c"-l\00"
@.str.2 = [3 x i8] c"-i\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@stdin = global i32* null
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [25 x i8] c"Failed opening file %s.\0A\00"
@.str.6 = [8 x i8] c".XXXXXX\00"
@.str.7 = [28 x i8] c"Failed creating temp file.\0A\00"
@.str.8 = [3 x i8] c"wb\00"
@.str.9 = [35 x i8] c"Unable to open output file for %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca %struct.bsdconv_instance*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %8
store i32* null, i32** %10
%15 = load i32*, i32** @stdout
store i32* %15, i32** %11
store i32 0, i32* %12
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 2
br i1 %17, label %18, label %25
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %2
store i32 2, i32* %13
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %25
%32 = call i32 (...) @list_modules()
store i32 0, i32* %3
br label %247
33: ; preds = %25
%34 = load i32, i32* %4
%35 = icmp sgt i32 %34, 2
br i1 %35, label %36, label %66
36: ; preds = %33
br label %37
37: ; preds = %62, %36
%38 = load i32, i32* %13
%39 = load i32, i32* %4
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %65
41: ; preds = %37
%42 = load i8**, i8*** %5
%43 = load i32, i32* %13
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8*, i8** %42, i64 %44
%46 = load i8*, i8** %45
%47 = call i64 @strcmp(i8* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %41
store i32 1, i32* %12
br label %62
50: ; preds = %41
%51 = load i8**, i8*** %5
%52 = load i32, i32* %13
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8*, i8** %51, i64 %53
%55 = load i8*, i8** %54
%56 = call i64 @strcmp(i8* %55, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %50
%59 = call i32 (...) @list_modules()
br label %61
60: ; preds = %50
br label %65
61: ; preds = %58
br label %62
62: ; preds = %61, %49
%63 = load i32, i32* %13
%64 = add nsw i32 %63, 1
store i32 %64, i32* %13
br label %37
65: ; preds = %60, %37
br label %66
66: ; preds = %65, %33
%67 = load i8**, i8*** %5
%68 = getelementptr inbounds i8*, i8** %67, i64 1
%69 = load i8*, i8** %68
%70 = call %struct.bsdconv_instance* @bsdconv_create(i8* %69)
store %struct.bsdconv_instance* %70, %struct.bsdconv_instance** %9
%71 = load %struct.bsdconv_instance*, %struct.bsdconv_instance** %9
%72 = icmp ne %struct.bsdconv_instance* %71, null
br i1 %72, label %81, label %73
73: ; preds = %66
%74 = call i8* (...) @bsdconv_error()
store i8* %74, i8** %6
%75 = load i32, i32* @stderr
%76 = load i8*, i8** %6
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %76)
%78 = load i8*, i8** %6
%79 = call i32 @free(i8* %78)
%80 = call i32 @exit(i32 1)
unreachable
81: ; preds = %66
%82 = load i32, i32* %13
%83 = load i32, i32* %4
%84 = icmp sge i32 %82, %83
br i1 %84, label %85, label %90
85: ; preds = %81
%86 = load %struct.bsdconv_instance*, %struct.bsdconv_instance** %9
%87 = load i32*, i32** @stdin
%88 = load i32*, i32** @stdout
%89 = call i32 @bsdconv_file(%struct.bsdconv_instance* %86, i32* %87, i32* %88, i8* null)
br label %244
90: ; preds = %81
br label %91
91: ; preds = %240, %90
%92 = load i32, i32* %13
%93 = load i32, i32* %4
%94 = icmp slt i32 %92, %93
br i1 %94, label %95, label %243
95: ; preds = %91
%96 = load i32, i32* %12
%97 = icmp ne i32 %96, 0
br i1 %97, label %98, label %207
98: ; preds = %95
%99 = load i8**, i8*** %5
%100 = load i32, i32* %13
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds i8*, i8** %99, i64 %101
%103 = load i8*, i8** %102
%104 = call i32* @fopen(i8* %103, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %104, i32** %10
%105 = load i32*, i32** %10
%106 = icmp eq i32* %105, null
br i1 %106, label %107, label %118
107: ; preds = %98
%108 = load i32, i32* @stderr
%109 = load i8**, i8*** %5
%110 = load i32, i32* %13
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds i8*, i8** %109, i64 %111
%113 = load i8*, i8** %112
%114 = call i32 (i32, i8*, ...) @fprintf(i32 %108, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %113)
%115 = load %struct.bsdconv_instance*, %struct.bsdconv_instance** %9
%116 = call i32 @bsdconv_destroy(%struct.bsdconv_instance* %115)
%117 = call i32 @exit(i32 1)
unreachable
118: ; preds = %98
%119 = load i8**, i8*** %5
%120 = load i32, i32* %13
%121 = sext i32 %120 to i64
%122 = getelementptr inbounds i8*, i8** %119, i64 %121
%123 = load i8*, i8** %122
%124 = call i64 @strlen(i8* %123)
%125 = add nsw i64 %124, 8
%126 = call i8* @malloc(i64 %125)
store i8* %126, i8** %8
%127 = load i8*, i8** %8
%128 = load i8**, i8*** %5
%129 = load i32, i32* %13
%130 = sext i32 %129 to i64
%131 = getelementptr inbounds i8*, i8** %128, i64 %130
%132 = load i8*, i8** %131
%133 = call i32 @strcpy(i8* %127, i8* %132)
%134 = load i8*, i8** %8
%135 = call i32 @strcat(i8* %134, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%136 = load i8*, i8** %8
%137 = call i32 @mkstemp(i8* %136)
store i32 %137, i32* %7
%138 = icmp eq i32 %137, -1
br i1 %138, label %139, label %147
139: ; preds = %118
%140 = load i8*, i8** %8
%141 = call i32 @free(i8* %140)
%142 = load i32, i32* @stderr
%143 = call i32 (i32, i8*, ...) @fprintf(i32 %142, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
%144 = load %struct.bsdconv_instance*, %struct.bsdconv_instance** %9
%145 = call i32 @bsdconv_destroy(%struct.bsdconv_instance* %144)
%146 = call i32 @exit(i32 1)
unreachable
147: ; preds = %118
%148 = load i32, i32* %7
%149 = call i32* @fdopen(i32 %148, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
store i32* %149, i32** %11
%150 = load i32*, i32** %11
%151 = icmp ne i32* %150, null
br i1 %151, label %163, label %152
152: ; preds = %147
%153 = load i32, i32* @stderr
%154 = load i8**, i8*** %5
%155 = load i32, i32* %13
%156 = sext i32 %155 to i64
%157 = getelementptr inbounds i8*, i8** %154, i64 %156
%158 = load i8*, i8** %157
%159 = call i32 (i32, i8*, ...) @fprintf(i32 %153, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.9, i64 0, i64 0), i8* %158)
%160 = load %struct.bsdconv_instance*, %struct.bsdconv_instance** %9
%161 = call i32 @bsdconv_destroy(%struct.bsdconv_instance* %160)
%162 = call i32 @exit(i32 1)
unreachable
163: ; preds = %147
%164 = load i32*, i32** %10
%165 = call i32 @fileno(i32* %164)
%166 = call i32 @fstat(i32 %165, %struct.stat* %14)
%167 = load i32*, i32** %11
%168 = call i32 @fileno(i32* %167)
%169 = getelementptr inbounds %struct.stat, %struct.stat* %14, i32 0, i32 2
%170 = load i32, i32* %169
%171 = getelementptr inbounds %struct.stat, %struct.stat* %14, i32 0, i32 1
%172 = load i32, i32* %171
%173 = call i32 @fchown(i32 %168, i32 %170, i32 %172)
%174 = load i32*, i32** %11
%175 = call i32 @fileno(i32* %174)
%176 = getelementptr inbounds %struct.stat, %struct.stat* %14, i32 0, i32 0
%177 = load i32, i32* %176
%178 = call i32 @fchmod(i32 %175, i32 %177)
%179 = load %struct.bsdconv_instance*, %struct.bsdconv_instance** %9
%180 = load i32*, i32** %10
%181 = load i32*, i32** %11
%182 = load i8**, i8*** %5
%183 = load i32, i32* %13
%184 = sext i32 %183 to i64
%185 = getelementptr inbounds i8*, i8** %182, i64 %184
%186 = load i8*, i8** %185
%187 = call i32 @bsdconv_file(%struct.bsdconv_instance* %179, i32* %180, i32* %181, i8* %186)
%188 = load i32*, i32** %10
%189 = call i32 @fclose(i32* %188)
%190 = load i32*, i32** %11
%191 = call i32 @fclose(i32* %190)
%192 = load i8**, i8*** %5
%193 = load i32, i32* %13
%194 = sext i32 %193 to i64
%195 = getelementptr inbounds i8*, i8** %192, i64 %194
%196 = load i8*, i8** %195
%197 = call i32 @unlink(i8* %196)
%198 = load i8*, i8** %8
%199 = load i8**, i8*** %5
%200 = load i32, i32* %13
%201 = sext i32 %200 to i64
%202 = getelementptr inbounds i8*, i8** %199, i64 %201
%203 = load i8*, i8** %202
%204 = call i32 @rename(i8* %198, i8* %203)
%205 = load i8*, i8** %8
%206 = call i32 @free(i8* %205)
br label %239
207: ; preds = %95
%208 = load i8**, i8*** %5
%209 = load i32, i32* %13
%210 = sext i32 %209 to i64
%211 = getelementptr inbounds i8*, i8** %208, i64 %210
%212 = load i8*, i8** %211
%213 = call i32* @fopen(i8* %212, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %213, i32** %10
%214 = load i32*, i32** %10
%215 = icmp eq i32* %214, null
br i1 %215, label %216, label %227
216: ; preds = %207
%217 = load i32, i32* @stderr
%218 = load i8**, i8*** %5
%219 = load i32, i32* %13
%220 = sext i32 %219 to i64
%221 = getelementptr inbounds i8*, i8** %218, i64 %220
%222 = load i8*, i8** %221
%223 = call i32 (i32, i8*, ...) @fprintf(i32 %217, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %222)
%224 = load %struct.bsdconv_instance*, %struct.bsdconv_instance** %9
%225 = call i32 @bsdconv_destroy(%struct.bsdconv_instance* %224)
%226 = call i32 @exit(i32 1)
unreachable
227: ; preds = %207
%228 = load %struct.bsdconv_instance*, %struct.bsdconv_instance** %9
%229 = load i32*, i32** %10
%230 = load i32*, i32** @stdout
%231 = load i8**, i8*** %5
%232 = load i32, i32* %13
%233 = sext i32 %232 to i64
%234 = getelementptr inbounds i8*, i8** %231, i64 %233
%235 = load i8*, i8** %234
%236 = call i32 @bsdconv_file(%struct.bsdconv_instance* %228, i32* %229, i32* %230, i8* %235)
%237 = load i32*, i32** %10
%238 = call i32 @fclose(i32* %237)
br label %239
239: ; preds = %227, %163
br label %240
240: ; preds = %239
%241 = load i32, i32* %13
%242 = add nsw i32 %241, 1
store i32 %242, i32* %13
br label %91
243: ; preds = %91
br label %244
244: ; preds = %243, %85
%245 = load %struct.bsdconv_instance*, %struct.bsdconv_instance** %9
%246 = call i32 @bsdconv_destroy(%struct.bsdconv_instance* %245)
store i32 0, i32* %3
br label %247
247: ; preds = %244, %31
%248 = load i32, i32* %3
ret i32 %248
}

LLVM IR (-O2):
%struct.stat = type { i32, i32, i32 }
%struct.bsdconv_instance = type { i32 }
@stdout = global i32* null
@stderr = global i32 0
@.str = [83 x i8] c"Usage:\0A\09 %s conversion|-l [-i] [file] [...]\0A\09\09-i:\09save in-place\0A\09\09-l:\09list codecs\0A\00"
@.str.1 = [3 x i8] c"-l\00"
@.str.2 = [3 x i8] c"-i\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@stdin = global i32* null
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [25 x i8] c"Failed opening file %s.\0A\00"
@.str.6 = [8 x i8] c".XXXXXX\00"
@.str.7 = [28 x i8] c"Failed creating temp file.\0A\00"
@.str.8 = [3 x i8] c"wb\00"
@.str.9 = [35 x i8] c"Unable to open output file for %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = tail call i32 (...) @list_modules()
br label %139
17: ; preds = %10
%18 = icmp ugt i32 %0, 2
br i1 %18, label %19, label %40
19: ; preds = %17
%20 = zext i32 %0 to i64
br label %21
21: ; preds = %19, %34
%22 = phi i64 [ 2, %19 ], [ %36, %34 ]
%23 = phi i32 [ 0, %19 ], [ %35, %34 ]
%24 = getelementptr inbounds i8*, i8** %1, i64 %22
%25 = load i8*, i8** %24
%26 = tail call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %34, label %28
28: ; preds = %21
%29 = load i8*, i8** %24
%30 = tail call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %28
%33 = tail call i32 (...) @list_modules()
br label %34
34: ; preds = %21, %32
%35 = phi i32 [ %23, %32 ], [ 1, %21 ]
%36 = add nuw nsw i64 %22, 1
%37 = icmp eq i64 %36, %20
br i1 %37, label %40, label %21
38: ; preds = %28
%39 = trunc i64 %22 to i32
br label %40
40: ; preds = %34, %38, %17
%41 = phi i32 [ 0, %17 ], [ %23, %38 ], [ %35, %34 ]
%42 = phi i32 [ 2, %17 ], [ %39, %38 ], [ %0, %34 ]
%43 = load i8*, i8** %11
%44 = tail call %struct.bsdconv_instance* @bsdconv_create(i8* %43)
%45 = icmp eq %struct.bsdconv_instance* %44, null
br i1 %45, label %46, label %52
46: ; preds = %40
%47 = tail call i8* (...) @bsdconv_error()
%48 = load i32, i32* @stderr
%49 = tail call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %47)
%50 = tail call i32 @free(i8* %47)
%51 = tail call i32 @exit(i32 1)
unreachable
52: ; preds = %40
%53 = icmp slt i32 %42, %0
br i1 %53, label %54, label %61
54: ; preds = %52
%55 = icmp eq i32 %41, 0
%56 = bitcast %struct.stat* %3 to i8*
%57 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 2
%58 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%59 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%60 = zext i32 %42 to i64
br label %65
61: ; preds = %52
%62 = load i32*, i32** @stdin
%63 = load i32*, i32** @stdout
%64 = tail call i32 @bsdconv_file(%struct.bsdconv_instance* %44, i32* %62, i32* %63, i8* null)
br label %137
65: ; preds = %54, %133
%66 = phi i64 [ %60, %54 ], [ %134, %133 ]
%67 = getelementptr inbounds i8*, i8** %1, i64 %66
%68 = load i8*, i8** %67
%69 = tail call i32* @fopen(i8* %68, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%70 = icmp eq i32* %69, null
br i1 %55, label %121, label %71
71: ; preds = %65
br i1 %70, label %72, label %78
72: ; preds = %71
%73 = load i32, i32* @stderr
%74 = load i8*, i8** %67
%75 = tail call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %74)
%76 = tail call i32 @bsdconv_destroy(%struct.bsdconv_instance* %44)
%77 = tail call i32 @exit(i32 1)
unreachable
78: ; preds = %71
%79 = load i8*, i8** %67
%80 = tail call i64 @strlen(i8* dereferenceable(1) %79)
%81 = add nsw i64 %80, 8
%82 = tail call i8* @malloc(i64 %81)
%83 = tail call i32 @strcpy(i8* %82, i8* %79)
%84 = tail call i32 @strcat(i8* %82, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%85 = tail call i32 @mkstemp(i8* %82)
%86 = icmp eq i32 %85, -1
br i1 %86, label %87, label %93
87: ; preds = %78
%88 = tail call i32 @free(i8* %82)
%89 = load i32, i32* @stderr
%90 = tail call i32 (i32, i8*, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
%91 = tail call i32 @bsdconv_destroy(%struct.bsdconv_instance* %44)
%92 = tail call i32 @exit(i32 1)
unreachable
93: ; preds = %78
%94 = tail call i32* @fdopen(i32 %85, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%95 = icmp eq i32* %94, null
br i1 %95, label %96, label %102
96: ; preds = %93
%97 = load i32, i32* @stderr
%98 = load i8*, i8** %67
%99 = tail call i32 (i32, i8*, ...) @fprintf(i32 %97, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.9, i64 0, i64 0), i8* %98)
%100 = tail call i32 @bsdconv_destroy(%struct.bsdconv_instance* %44)
%101 = tail call i32 @exit(i32 1)
unreachable
102: ; preds = %93
%103 = tail call i32 @fileno(i32* %69)
%104 = call i32 @fstat(i32 %103, %struct.stat* %3)
%105 = tail call i32 @fileno(i32* %94)
%106 = load i32, i32* %57
%107 = load i32, i32* %58
%108 = tail call i32 @fchown(i32 %105, i32 %106, i32 %107)
%109 = tail call i32 @fileno(i32* %94)
%110 = load i32, i32* %59
%111 = tail call i32 @fchmod(i32 %109, i32 %110)
%112 = load i8*, i8** %67
%113 = tail call i32 @bsdconv_file(%struct.bsdconv_instance* %44, i32* %69, i32* %94, i8* %112)
%114 = tail call i32 @fclose(i32* %69)
%115 = tail call i32 @fclose(i32* %94)
%116 = load i8*, i8** %67
%117 = tail call i32 @unlink(i8* %116)
%118 = load i8*, i8** %67
%119 = tail call i32 @rename(i8* %82, i8* %118)
%120 = tail call i32 @free(i8* %82)
br label %133
121: ; preds = %65
br i1 %70, label %122, label %128
122: ; preds = %121
%123 = load i32, i32* @stderr
%124 = load i8*, i8** %67
%125 = tail call i32 (i32, i8*, ...) @fprintf(i32 %123, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %124)
%126 = tail call i32 @bsdconv_destroy(%struct.bsdconv_instance* %44)
%127 = tail call i32 @exit(i32 1)
unreachable
128: ; preds = %121
%129 = load i32*, i32** @stdout
%130 = load i8*, i8** %67
%131 = tail call i32 @bsdconv_file(%struct.bsdconv_instance* %44, i32* %69, i32* %129, i8* %130)
%132 = tail call i32 @fclose(i32* %69)
br label %133
133: ; preds = %102, %128
%134 = add nuw nsw i64 %66, 1
%135 = trunc i64 %134 to i32
%136 = icmp slt i32 %135, %0
br i1 %136, label %65, label %137
137: ; preds = %133, %61
%138 = tail call i32 @bsdconv_destroy(%struct.bsdconv_instance* %44)
br label %139
139: ; preds = %137, %15
ret i32 0
}