#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*/ uint8_t;
struct dcadec_stream {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
unsigned long ULONG_MAX;
int /*<<< orphan*/ dcadec_stream_close(struct dcadec_stream *);
struct dcadec_stream *dcadec_stream_open(char *, int /*<<< orphan*/);
int dcadec_stream_read(struct dcadec_stream *, int /*<<< orphan*/ **, size_t *);
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fwrite(int /*<<< orphan*/ *, size_t, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
unsigned long strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  if (argc < 3) {
    fprintf(stderr, "Usage: %s <input.dts> <output.dts> [first] [last]\n",
            argv[0]);
    return 1;
  }
  unsigned long first_packet = 0;
  unsigned long last_packet = ULONG_MAX;
  if (argc > 3)
    first_packet = strtoul(argv[3], NULL, 0);
  if (argc > 4)
    last_packet = strtoul(argv[4], NULL, 0);
  if (last_packet < first_packet) {
    fprintf(stderr, "Invalid packet range\n");
    return 1;
  }
  struct dcadec_stream *stream = dcadec_stream_open(argv[1], 0);
  if (!stream) {
    fprintf(stderr, "Couldn't open input file\n");
    return 1;
  }
  FILE *fp = fopen(argv[2], "wb");
  if (!fp) {
    fprintf(stderr, "Couldn't open output file\n");
    dcadec_stream_close(stream);
    return 1;
  }
  unsigned long packet_in = 0;
  unsigned long packet_out = 0;
  int ret;
  while (true) {
    uint8_t *packet;
    size_t size;
    ret = dcadec_stream_read(stream, &packet, &size);
    if (ret < 0) {
      fprintf(stderr, "Error %d reading packet\n", ret);
      break;
    }
    if (ret == 0)
      break;
    if (packet_in >= first_packet) {
      if (fwrite(packet, size, 1, fp) != 1) {
        fprintf(stderr, "Error %d writing packet\n", errno);
        ret = -1;
        break;
      }
      packet_out++;
    }
    if (++packet_in > last_packet)
      break;
  }
  if (packet_out) {
    fprintf(stderr, "Wrote %lu packets\n", packet_out);
  } else {
    fprintf(stderr, "Didn't write a single packet!\n");
    ret = -1;
  }
  fclose(fp);
  dcadec_stream_close(stream);
  return !!ret;
}


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)
cmpl   $0x3,-0x8(%rbp)
jge    11ca <main+0x4a>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1432 <main+0x2b2>
movq   $0x0,-0x18(%rbp)
mov    0x2def(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x3,-0x8(%rbp)
jle    1201 <main+0x81>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1090 <strtoul@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x4,-0x8(%rbp)
jle    1222 <main+0xa2>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1090 <strtoul@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1253 <main+0xd3>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
lea    0xdf3(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1432 <main+0x2b2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %esi,%esi
call   1070 <dcadec_stream_open@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1294 <main+0x114>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
lea    0xdc8(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1432 <main+0x2b2>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdc0(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12e3 <main+0x163>
mov    0x2d22(%rip),%rax
mov    (%rax),%edi
lea    0xd9f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <dcadec_stream_close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1432 <main+0x2b2>
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x50(%rbp),%rsi
lea    -0x58(%rbp),%rdx
call   1030 <dcadec_stream_read@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    1330 <main+0x1b0>
mov    0x2cc8(%rip),%rax
mov    (%rax),%edi
mov    -0x44(%rbp),%edx
lea    0xd5d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    13c4 <main+0x244>
cmpl   $0x0,-0x44(%rbp)
jne    133f <main+0x1bf>
jmp    13c4 <main+0x244>
mov    -0x38(%rbp),%rax
cmp    -0x18(%rbp),%rax
jb     13a4 <main+0x224>
mov    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    -0x30(%rbp),%rcx
mov    $0x1,%edx
call   10a0 <fwrite@plt>
cmp    $0x1,%eax
je     1398 <main+0x218>
mov    0x2c6d(%rip),%rax
mov    (%rax),%edi
mov    0x2c5c(%rip),%rax
mov    (%rax),%edx
lea    0xd15(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x44(%rbp)
jmp    13c4 <main+0x244>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
cmp    -0x20(%rbp),%rax
jbe    13bf <main+0x23f>
jmp    13c4 <main+0x244>
jmp    12f3 <main+0x173>
cmpq   $0x0,-0x40(%rbp)
je     13ef <main+0x26f>
mov    0x2c0a(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%rdx
lea    0xcd0(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    140d <main+0x28d>
mov    0x2bea(%rip),%rax
mov    (%rax),%edi
lea    0xcc7(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x44(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1040 <dcadec_stream_close@plt>
cmpl   $0x0,-0x44(%rbp)
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-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    $0x18,%rsp
mov    %rsi,%rbp
cmp    $0x2,%edi
jg     11bb <main+0x3b>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xe56(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%eax
jmp    139c <main+0x21c>
mov    %edi,%ebx
mov    0x2e04(%rip),%rax
mov    (%rax),%r14
cmp    $0x3,%edi
jne    11d1 <main+0x51>
xor    %r12d,%r12d
jmp    1210 <main+0x90>
mov    0x18(%rbp),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <strtoul@plt>
mov    %rax,%r12
cmp    $0x5,%ebx
jb     11f6 <main+0x76>
mov    0x20(%rbp),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <strtoul@plt>
mov    %rax,%r14
cmp    %r12,%r14
jae    1210 <main+0x90>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
lea    0xe28(%rip),%rsi
jmp    12f0 <main+0x170>
mov    0x8(%rbp),%rdi
xor    %esi,%esi
call   1070 <dcadec_stream_open@plt>
test   %rax,%rax
je     12e0 <main+0x160>
mov    %rax,%r15
mov    0x10(%rbp),%rdi
lea    0xe31(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,(%rsp)
test   %rax,%rax
je     1301 <main+0x181>
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %r15,%rdi
call   1030 <dcadec_stream_read@plt>
mov    %eax,%ebp
xor    %r13d,%r13d
test   %eax,%eax
js     12c3 <main+0x143>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
test   %ebp,%ebp
je     1327 <main+0x1a7>
cmp    %r12,%rbx
jb     12a2 <main+0x122>
mov    0x10(%rsp),%rdi
mov    0x8(%rsp),%rsi
mov    $0x1,%edx
mov    (%rsp),%rcx
call   10a0 <fwrite@plt>
cmp    $0x1,%eax
jne    132b <main+0x1ab>
add    $0x1,%r13
add    $0x1,%rbx
cmp    %r14,%rbx
ja     12dc <main+0x15c>
mov    %r15,%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1030 <dcadec_stream_read@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1270 <main+0xf0>
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
lea    0xdae(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebp,%ebx
jmp    1350 <main+0x1d0>
mov    0x2cf9(%rip),%rax
mov    (%rax),%edi
lea    0xd59(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%eax
jmp    139c <main+0x21c>
mov    0x2cd8(%rip),%rax
mov    (%rax),%edi
lea    0xd55(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r15,%rdi
call   1040 <dcadec_stream_close@plt>
mov    $0x1,%eax
jmp    139c <main+0x21c>
xor    %ebx,%ebx
jmp    1350 <main+0x1d0>
mov    0x2cae(%rip),%rax
mov    (%rax),%edi
mov    0x2c9d(%rip),%rax
mov    (%rax),%edx
lea    0xd56(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    0x2c89(%rip),%rax
mov    (%rax),%edi
test   %r13,%r13
je     1371 <main+0x1f1>
lea    0xd4e(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1384 <main+0x204>
lea    0xd4e(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    (%rsp),%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   1040 <dcadec_stream_close@plt>
xor    %eax,%eax
test   %ebx,%ebx
setne  %al
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dcadec_stream = type { i32 }
@stderr = global i32 0
@.str = [51 x i8] c"Usage: %s <input.dts> <output.dts> [first] [last]\0A\00"
@ULONG_MAX = global i64 0
@.str.1 = [22 x i8] c"Invalid packet range\0A\00"
@.str.2 = [26 x i8] c"Couldn't open input file\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [27 x i8] c"Couldn't open output file\0A\00"
@.str.5 = [25 x i8] c"Error %d reading packet\0A\00"
@.str.6 = [25 x i8] c"Error %d writing packet\0A\00"
@errno = global i32 0
@.str.7 = [19 x i8] c"Wrote %lu packets\0A\00"
@.str.8 = [31 x i8] c"Didn't write a single packet!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca %struct.dcadec_stream*
%9 = alloca i32*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32*
%14 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 3
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %21)
store i32 1, i32* %3
br label %127
23: ; preds = %2
store i64 0, i64* %6
%24 = load i64, i64* @ULONG_MAX
store i64 %24, i64* %7
%25 = load i32, i32* %4
%26 = icmp sgt i32 %25, 3
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 3
%30 = load i8*, i8** %29
%31 = call i64 @strtoul(i8* %30, i32* null, i32 0)
store i64 %31, i64* %6
br label %32
32: ; preds = %27, %23
%33 = load i32, i32* %4
%34 = icmp sgt i32 %33, 4
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 4
%38 = load i8*, i8** %37
%39 = call i64 @strtoul(i8* %38, i32* null, i32 0)
store i64 %39, i64* %7
br label %40
40: ; preds = %35, %32
%41 = load i64, i64* %7
%42 = load i64, i64* %6
%43 = icmp ult i64 %41, %42
br i1 %43, label %44, label %47
44: ; preds = %40
%45 = load i32, i32* @stderr
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %127
47: ; preds = %40
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 1
%50 = load i8*, i8** %49
%51 = call %struct.dcadec_stream* @dcadec_stream_open(i8* %50, i32 0)
store %struct.dcadec_stream* %51, %struct.dcadec_stream** %8
%52 = load %struct.dcadec_stream*, %struct.dcadec_stream** %8
%53 = icmp ne %struct.dcadec_stream* %52, null
br i1 %53, label %57, label %54
54: ; preds = %47
%55 = load i32, i32* @stderr
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %127
57: ; preds = %47
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 2
%60 = load i8*, i8** %59
%61 = call i32* @fopen(i8* %60, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %61, i32** %9
%62 = load i32*, i32** %9
%63 = icmp ne i32* %62, null
br i1 %63, label %69, label %64
64: ; preds = %57
%65 = load i32, i32* @stderr
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%67 = load %struct.dcadec_stream*, %struct.dcadec_stream** %8
%68 = call i32 @dcadec_stream_close(%struct.dcadec_stream* %67)
store i32 1, i32* %3
br label %127
69: ; preds = %57
store i64 0, i64* %10
store i64 0, i64* %11
br label %70
70: ; preds = %69, %106
%71 = load %struct.dcadec_stream*, %struct.dcadec_stream** %8
%72 = call i32 @dcadec_stream_read(%struct.dcadec_stream* %71, i32** %13, i64* %14)
store i32 %72, i32* %12
%73 = load i32, i32* %12
%74 = icmp slt i32 %73, 0
br i1 %74, label %75, label %79
75: ; preds = %70
%76 = load i32, i32* @stderr
%77 = load i32, i32* %12
%78 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %77)
br label %107
79: ; preds = %70
%80 = load i32, i32* %12
%81 = icmp eq i32 %80, 0
br i1 %81, label %82, label %83
82: ; preds = %79
br label %107
83: ; preds = %79
%84 = load i64, i64* %10
%85 = load i64, i64* %6
%86 = icmp uge i64 %84, %85
br i1 %86, label %87, label %100
87: ; preds = %83
%88 = load i32*, i32** %13
%89 = load i64, i64* %14
%90 = load i32*, i32** %9
%91 = call i32 @fwrite(i32* %88, i64 %89, i32 1, i32* %90)
%92 = icmp ne i32 %91, 1
br i1 %92, label %93, label %97
93: ; preds = %87
%94 = load i32, i32* @stderr
%95 = load i32, i32* @errno
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %94, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i32 %95)
store i32 -1, i32* %12
br label %107
97: ; preds = %87
%98 = load i64, i64* %11
%99 = add i64 %98, 1
store i64 %99, i64* %11
br label %100
100: ; preds = %97, %83
%101 = load i64, i64* %10
%102 = add i64 %101, 1
store i64 %102, i64* %10
%103 = load i64, i64* %7
%104 = icmp ugt i64 %102, %103
br i1 %104, label %105, label %106
105: ; preds = %100
br label %107
106: ; preds = %100
br label %70
107: ; preds = %105, %93, %82, %75
%108 = load i64, i64* %11
%109 = icmp ne i64 %108, 0
br i1 %109, label %110, label %114
110: ; preds = %107
%111 = load i32, i32* @stderr
%112 = load i64, i64* %11
%113 = call i32 (i32, i8*, ...) @fprintf(i32 %111, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i64 %112)
br label %117
114: ; preds = %107
%115 = load i32, i32* @stderr
%116 = call i32 (i32, i8*, ...) @fprintf(i32 %115, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0))
store i32 -1, i32* %12
br label %117
117: ; preds = %114, %110
%118 = load i32*, i32** %9
%119 = call i32 @fclose(i32* %118)
%120 = load %struct.dcadec_stream*, %struct.dcadec_stream** %8
%121 = call i32 @dcadec_stream_close(%struct.dcadec_stream* %120)
%122 = load i32, i32* %12
%123 = icmp ne i32 %122, 0
%124 = xor i1 %123, true
%125 = xor i1 %124, true
%126 = zext i1 %125 to i32
store i32 %126, i32* %3
br label %127
127: ; preds = %117, %64, %54, %44, %17
%128 = load i32, i32* %3
ret i32 %128
}

LLVM IR (-O2):
%struct.dcadec_stream = type { i32 }
@stderr = global i32 0
@.str = [51 x i8] c"Usage: %s <input.dts> <output.dts> [first] [last]\0A\00"
@ULONG_MAX = global i64 0
@.str.1 = [22 x i8] c"Invalid packet range\0A\00"
@.str.2 = [26 x i8] c"Couldn't open input file\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [27 x i8] c"Couldn't open output file\0A\00"
@.str.5 = [25 x i8] c"Error %d reading packet\0A\00"
@.str.6 = [25 x i8] c"Error %d writing packet\0A\00"
@errno = global i32 0
@.str.7 = [19 x i8] c"Wrote %lu packets\0A\00"
@.str.8 = [31 x i8] c"Didn't write a single packet!\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %97
10: ; preds = %2
%11 = load i64, i64* @ULONG_MAX
%12 = icmp eq i32 %0, 3
br i1 %12, label %28, label %13
13: ; preds = %10
%14 = getelementptr inbounds i8*, i8** %1, i64 3
%15 = load i8*, i8** %14
%16 = tail call i64 @strtoul(i8* nocapture %15, i32* null, i32 0)
%17 = icmp ugt i32 %0, 4
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = getelementptr inbounds i8*, i8** %1, i64 4
%20 = load i8*, i8** %19
%21 = tail call i64 @strtoul(i8* nocapture %20, i32* null, i32 0)
br label %22
22: ; preds = %18, %13
%23 = phi i64 [ %21, %18 ], [ %11, %13 ]
%24 = icmp ult i64 %23, %16
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %97
28: ; preds = %10, %22
%29 = phi i64 [ %23, %22 ], [ %11, %10 ]
%30 = phi i64 [ %16, %22 ], [ 0, %10 ]
%31 = getelementptr inbounds i8*, i8** %1, i64 1
%32 = load i8*, i8** %31
%33 = tail call %struct.dcadec_stream* @dcadec_stream_open(i8* %32, i32 0)
%34 = icmp eq %struct.dcadec_stream* %33, null
br i1 %34, label %35, label %38
35: ; preds = %28
%36 = load i32, i32* @stderr
%37 = tail call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %97
38: ; preds = %28
%39 = getelementptr inbounds i8*, i8** %1, i64 2
%40 = load i8*, i8** %39
%41 = tail call i32* @fopen(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%42 = icmp eq i32* %41, null
br i1 %42, label %48, label %43
43: ; preds = %38
%44 = bitcast i32** %3 to i8*
%45 = bitcast i64* %4 to i8*
%46 = call i32 @dcadec_stream_read(%struct.dcadec_stream* %33, i32** %3, i64* %4)
%47 = icmp slt i32 %46, 0
br i1 %47, label %52, label %57
48: ; preds = %38
%49 = load i32, i32* @stderr
%50 = tail call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%51 = tail call i32 @dcadec_stream_close(%struct.dcadec_stream* %33)
br label %97
52: ; preds = %79, %43
%53 = phi i64 [ 0, %43 ], [ %76, %79 ]
%54 = phi i32 [ %46, %43 ], [ %80, %79 ]
%55 = load i32, i32* @stderr
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %54)
br label %82
57: ; preds = %43, %79
%58 = phi i32 [ %80, %79 ], [ %46, %43 ]
%59 = phi i64 [ %76, %79 ], [ 0, %43 ]
%60 = phi i64 [ %77, %79 ], [ 0, %43 ]
%61 = icmp eq i32 %58, 0
br i1 %61, label %82, label %62
62: ; preds = %57
%63 = icmp ult i64 %60, %30
br i1 %63, label %75, label %64
64: ; preds = %62
%65 = load i32*, i32** %3
%66 = load i64, i64* %4
%67 = call i32 @fwrite(i32* %65, i64 %66, i32 1, i32* %41)
%68 = icmp eq i32 %67, 1
br i1 %68, label %73, label %69
69: ; preds = %64
%70 = load i32, i32* @stderr
%71 = load i32, i32* @errno
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i32 %71)
br label %82
73: ; preds = %64
%74 = add i64 %59, 1
br label %75
75: ; preds = %73, %62
%76 = phi i64 [ %74, %73 ], [ %59, %62 ]
%77 = add i64 %60, 1
%78 = icmp ugt i64 %77, %29
br i1 %78, label %82, label %79
79: ; preds = %75
%80 = call i32 @dcadec_stream_read(%struct.dcadec_stream* %33, i32** %3, i64* %4)
%81 = icmp slt i32 %80, 0
br i1 %81, label %52, label %57
82: ; preds = %75, %57, %52, %69
%83 = phi i64 [ %59, %69 ], [ %53, %52 ], [ %59, %57 ], [ %76, %75 ]
%84 = phi i32 [ -1, %69 ], [ %54, %52 ], [ 0, %57 ], [ %58, %75 ]
%85 = icmp eq i64 %83, 0
%86 = load i32, i32* @stderr
br i1 %85, label %89, label %87
87: ; preds = %82
%88 = call i32 (i32, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i64 %83)
br label %91
89: ; preds = %82
%90 = call i32 (i32, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0))
br label %91
91: ; preds = %89, %87
%92 = phi i32 [ %84, %87 ], [ -1, %89 ]
%93 = call i32 @fclose(i32* %41)
%94 = call i32 @dcadec_stream_close(%struct.dcadec_stream* %33)
%95 = icmp ne i32 %92, 0
%96 = zext i1 %95 to i32
br label %97
97: ; preds = %25, %48, %91, %35, %6
%98 = phi i32 [ 1, %6 ], [ 1, %25 ], [ 1, %35 ], [ %96, %91 ], [ 1, %48 ]
ret i32 %98
}