#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 FormatType {
  int dummy;
};

/* Variables and functions */
int GetData(struct FormatType const *, char const *, int /*<<< orphan*/,
            int /*<<< orphan*/, int, int, char, void *, int *);
int GetNFrames(struct FormatType const *, int *, char const *);
int GetSamplesPerFrame(struct FormatType const *, char const *, int *);
int /*<<< orphan*/ assert(int);
int bytes_per_sample(char);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int);
int /*<<< orphan*/ free(void *);
void *malloc(size_t);
int /*<<< orphan*/ stderr;
void *dirfile_read_channel(char typechar, const struct FormatType *F,
                           const char *channelname, int *nsamples_out) {
  int status = 0;
  int nframes = GetNFrames(F, &status, channelname);
  if (status != 0) {
    {
      if (status != 0)
        fprintf(stderr, "line %d: *** dirfile error code: %d\n", 87, status);
    };
    return NULL;
  }
  assert(nframes > 0);
  int samples_per_frame = GetSamplesPerFrame(F, channelname, &status);
  if (status != 0) {
    {
      if (status != 0)
        fprintf(stderr, "line %d: *** dirfile error code: %d\n", 95, status);
    };
    return NULL;
  }
  assert(samples_per_frame > 0);
  int nsamples = nframes * samples_per_frame;
  size_t nbytes = nsamples * bytes_per_sample(typechar);
  void *data = malloc(nbytes);
  *nsamples_out =
      GetData(F, channelname, 0, 0, nsamples / samples_per_frame,
              nsamples % samples_per_frame, typechar, data, &status);
  if (status != 0 || *nsamples_out <= 0) {
    {
      if (status != 0)
        fprintf(stderr, "line %d: *** dirfile error code: %d\n", 112, status);
    };
    free(data);
    return NULL;
  }
  return data;
}


x86 assembly (clang, -O0):
<dirfile_read_channel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %dil,%al
mov    %al,-0x9(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    -0x2c(%rbp),%rsi
call   10a0 <GetNFrames@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     11f3 <dirfile_read_channel+0x73>
cmpl   $0x0,-0x2c(%rbp)
je     11e6 <dirfile_read_channel+0x66>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%ecx
lea    0xe24(%rip),%rsi
mov    $0x57,%edx
call   1070 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1342 <dirfile_read_channel+0x1c2>
cmpl   $0x0,-0x30(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1050 <GetSamplesPerFrame@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     1256 <dirfile_read_channel+0xd6>
cmpl   $0x0,-0x2c(%rbp)
je     1249 <dirfile_read_channel+0xc9>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%ecx
lea    0xdc1(%rip),%rsi
mov    $0x5f,%edx
call   1070 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1342 <dirfile_read_channel+0x1c2>
cmpl   $0x0,-0x34(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x30(%rbp),%eax
imul   -0x34(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x4c(%rbp)
movsbl -0x9(%rbp),%edi
call   1040 <bytes_per_sample@plt>
mov    %eax,%ecx
mov    -0x4c(%rbp),%eax
imul   %ecx,%eax
cltq
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x38(%rbp),%eax
cltd
idivl  -0x34(%rbp)
mov    %eax,%r8d
mov    -0x38(%rbp),%eax
cltd
idivl  -0x34(%rbp)
mov    %edx,%r9d
mov    -0x9(%rbp),%r11b
mov    -0x48(%rbp),%r10
xor    %ecx,%ecx
lea    -0x2c(%rbp),%rax
mov    %ecx,%edx
movsbl %r11b,%r11d
mov    %r11d,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1090 <GetData@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0x0,-0x2c(%rbp)
jne    12fd <dirfile_read_channel+0x17d>
mov    -0x28(%rbp),%rax
cmpl   $0x0,(%rax)
jg     133a <dirfile_read_channel+0x1ba>
cmpl   $0x0,-0x2c(%rbp)
je     1324 <dirfile_read_channel+0x1a4>
mov    0x2cd2(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%ecx
lea    0xce6(%rip),%rsi
mov    $0x70,%edx
call   1070 <fprintf@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1342 <dirfile_read_channel+0x1c2>
mov    -0x48(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dirfile_read_channel>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %edi,%ebp
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   10a0 <GetNFrames@plt>
mov    0xc(%rsp),%ecx
test   %ecx,%ecx
je     11d5 <dirfile_read_channel+0x55>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xe3a(%rip),%rsi
mov    $0x57,%edx
call   1070 <fprintf@plt>
jmp    12aa <dirfile_read_channel+0x12a>
mov    %eax,%r12d
xor    %edi,%edi
test   %eax,%eax
setg   %dil
call   1060 <assert@plt>
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <GetSamplesPerFrame@plt>
mov    0xc(%rsp),%ecx
test   %ecx,%ecx
je     121c <dirfile_read_channel+0x9c>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
lea    0xdf3(%rip),%rsi
mov    $0x5f,%edx
call   1070 <fprintf@plt>
jmp    12aa <dirfile_read_channel+0x12a>
mov    %eax,%r13d
xor    %edi,%edi
test   %eax,%eax
setg   %dil
call   1060 <assert@plt>
imul   %r12d,%r13d
movsbl %bpl,%edi
mov    %rdi,0x10(%rsp)
call   1040 <bytes_per_sample@plt>
imul   %r13d,%eax
movslq %eax,%rdi
call   1080 <malloc@plt>
mov    %rax,%rbp
sub    $0x8,%rsp
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r12d,%r8d
xor    %r9d,%r9d
lea    0x14(%rsp),%rax
push   %rax
push   %rbp
push   0x28(%rsp)
call   1090 <GetData@plt>
add    $0x20,%rsp
mov    %eax,(%r14)
mov    0xc(%rsp),%ecx
test   %ecx,%ecx
jne    1284 <dirfile_read_channel+0x104>
test   %eax,%eax
jg     12ac <dirfile_read_channel+0x12c>
test   %ecx,%ecx
je     12a2 <dirfile_read_channel+0x122>
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
lea    0xd68(%rip),%rsi
mov    $0x70,%edx
call   1070 <fprintf@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
xor    %ebp,%ebp
mov    %rbp,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.FormatType = type { i32 }
@stderr = global i32 0
@.str = [37 x i8] c"line %d: *** dirfile error code: %d\0A\00"
define i8* @dirfile_read_channel(i8 signext %0, %struct.FormatType* %1, i8* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i8
%7 = alloca %struct.FormatType*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i64
%15 = alloca i8*
store i8 %0, i8* %6
store %struct.FormatType* %1, %struct.FormatType** %7
store i8* %2, i8** %8
store i32* %3, i32** %9
store i32 0, i32* %10
%16 = load %struct.FormatType*, %struct.FormatType** %7
%17 = load i8*, i8** %8
%18 = call i32 @GetNFrames(%struct.FormatType* %16, i32* %10, i8* %17)
store i32 %18, i32* %11
%19 = load i32, i32* %10
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %4
%22 = load i32, i32* %10
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = load i32, i32* %10
%27 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 87, i32 %26)
br label %28
28: ; preds = %24, %21
store i8* null, i8** %5
br label %92
29: ; preds = %4
%30 = load i32, i32* %11
%31 = icmp sgt i32 %30, 0
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = load %struct.FormatType*, %struct.FormatType** %7
%35 = load i8*, i8** %8
%36 = call i32 @GetSamplesPerFrame(%struct.FormatType* %34, i8* %35, i32* %10)
store i32 %36, i32* %12
%37 = load i32, i32* %10
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %47
39: ; preds = %29
%40 = load i32, i32* %10
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %39
%43 = load i32, i32* @stderr
%44 = load i32, i32* %10
%45 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 95, i32 %44)
br label %46
46: ; preds = %42, %39
store i8* null, i8** %5
br label %92
47: ; preds = %29
%48 = load i32, i32* %12
%49 = icmp sgt i32 %48, 0
%50 = zext i1 %49 to i32
%51 = call i32 @assert(i32 %50)
%52 = load i32, i32* %11
%53 = load i32, i32* %12
%54 = mul nsw i32 %52, %53
store i32 %54, i32* %13
%55 = load i32, i32* %13
%56 = load i8, i8* %6
%57 = call i32 @bytes_per_sample(i8 signext %56)
%58 = mul nsw i32 %55, %57
%59 = sext i32 %58 to i64
store i64 %59, i64* %14
%60 = load i64, i64* %14
%61 = call i8* @malloc(i64 %60)
store i8* %61, i8** %15
%62 = load %struct.FormatType*, %struct.FormatType** %7
%63 = load i8*, i8** %8
%64 = load i32, i32* %13
%65 = load i32, i32* %12
%66 = sdiv i32 %64, %65
%67 = load i32, i32* %13
%68 = load i32, i32* %12
%69 = srem i32 %67, %68
%70 = load i8, i8* %6
%71 = load i8*, i8** %15
%72 = call i32 @GetData(%struct.FormatType* %62, i8* %63, i32 0, i32 0, i32 %66, i32 %69, i8 signext %70, i8* %71, i32* %10)
%73 = load i32*, i32** %9
store i32 %72, i32* %73
%74 = load i32, i32* %10
%75 = icmp ne i32 %74, 0
br i1 %75, label %80, label %76
76: ; preds = %47
%77 = load i32*, i32** %9
%78 = load i32, i32* %77
%79 = icmp sle i32 %78, 0
br i1 %79, label %80, label %90
80: ; preds = %76, %47
%81 = load i32, i32* %10
%82 = icmp ne i32 %81, 0
br i1 %82, label %83, label %87
83: ; preds = %80
%84 = load i32, i32* @stderr
%85 = load i32, i32* %10
%86 = call i32 @fprintf(i32 %84, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 112, i32 %85)
br label %87
87: ; preds = %83, %80
%88 = load i8*, i8** %15
%89 = call i32 @free(i8* %88)
store i8* null, i8** %5
br label %92
90: ; preds = %76
%91 = load i8*, i8** %15
store i8* %91, i8** %5
br label %92
92: ; preds = %90, %87, %46, %28
%93 = load i8*, i8** %5
ret i8* %93
}

LLVM IR (-O2):
%struct.FormatType = type { i32 }
@stderr = global i32 0
@.str = [37 x i8] c"line %d: *** dirfile error code: %d\0A\00"
define i8* @dirfile_read_channel(i8 signext %0, %struct.FormatType* %1, i8* %2, i32* nocapture writeonly %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%7 = call i32 @GetNFrames(%struct.FormatType* %1, i32* %5, i8* %2)
%8 = load i32, i32* %5
%9 = icmp eq i32 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %4
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 87, i32 %8)
br label %44
13: ; preds = %4
%14 = icmp sgt i32 %7, 0
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = call i32 @GetSamplesPerFrame(%struct.FormatType* %1, i8* %2, i32* %5)
%18 = load i32, i32* %5
%19 = icmp eq i32 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %13
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 95, i32 %18)
br label %44
23: ; preds = %13
%24 = icmp sgt i32 %17, 0
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = mul nsw i32 %17, %7
%28 = call i32 @bytes_per_sample(i8 signext %0)
%29 = mul nsw i32 %27, %28
%30 = sext i32 %29 to i64
%31 = call i8* @malloc(i64 %30)
%32 = call i32 @GetData(%struct.FormatType* %1, i8* %2, i32 0, i32 0, i32 %7, i32 0, i8 signext %0, i8* %31, i32* %5)
store i32 %32, i32* %3
%33 = load i32, i32* %5
%34 = icmp ne i32 %33, 0
%35 = icmp slt i32 %32, 1
%36 = select i1 %34, i1 true, i1 %35
br i1 %36, label %37, label %44
37: ; preds = %23
%38 = icmp eq i32 %33, 0
br i1 %38, label %42, label %39
39: ; preds = %37
%40 = load i32, i32* @stderr
%41 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 112, i32 %33)
br label %42
42: ; preds = %39, %37
%43 = call i32 @free(i8* %31)
br label %44
44: ; preds = %20, %23, %42, %10
%45 = phi i8* [ null, %10 ], [ null, %20 ], [ null, %42 ], [ %31, %23 ]
ret i8* %45
}