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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char);
int /*<<< orphan*/ printf(char *, ...);
unsigned int read(unsigned int, int *, int);
int /*<<< orphan*/ reset_read_ptr(unsigned int);
int /*<<< orphan*/ start_acq(unsigned int);
void debug(unsigned int fd) {
  unsigned int k, len_ = 0;
  int32_t buffer[8192];
  char i, q;
  FILE *f;
  f = fopen("iq.dat", "w");
  if (f == NULL) {
    printf("error opening iq.dat\r\n");
    return;
  }
  reset_read_ptr(fd);
  start_acq(fd);
  len_ = read(fd, buffer, 8192);
  if (len_ < 8192) {
    printf("read failed with %d\r\n", len_);
    fclose(f);
    return;
  }
  for (k = 0; k < len_; k++) {
    i = (buffer[k] & 0xff000000) >> 24;
    q = (buffer[k] & 0xff0000) >> 16;
    fprintf(f, "%d ", i);
    fprintf(f, "%d\n", q);
    i = (buffer[k] & 0xff00) >> 8;
    q = (buffer[k] & 0xff);
    fprintf(f, "%d ", i);
    fprintf(f, "%d\n", q);
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<debug>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8020,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xe74(%rip),%rdi
lea    0xe74(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x8020(%rbp)
cmpq   $0x0,-0x8020(%rbp)
jne    11c0 <debug+0x50>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1308 <debug+0x198>
mov    -0x4(%rbp),%edi
call   1040 <reset_read_ptr@plt>
mov    -0x4(%rbp),%edi
call   1080 <start_acq@plt>
mov    -0x4(%rbp),%edi
lea    -0x8010(%rbp),%rsi
mov    $0x2000,%edx
call   1060 <read@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x2000,-0xc(%rbp)
jae    1216 <debug+0xa6>
mov    -0xc(%rbp),%esi
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8020(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1308 <debug+0x198>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    12fc <debug+0x18c>
mov    -0x8(%rbp),%eax
mov    -0x8010(%rbp,%rax,4),%eax
and    $0xff000000,%eax
shr    $0x18,%eax
mov    %al,-0x8011(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x8010(%rbp,%rax,4),%eax
and    $0xff0000,%eax
sar    $0x10,%eax
mov    %al,-0x8012(%rbp)
mov    -0x8020(%rbp),%rdi
lea    0xdcf(%rip),%rsi
movsbl -0x8011(%rbp),%edx
call   1070 <fprintf@plt>
mov    -0x8020(%rbp),%rdi
lea    0xdb9(%rip),%rsi
movsbl -0x8012(%rbp),%edx
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%eax
mov    -0x8010(%rbp,%rax,4),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %al,-0x8011(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x8010(%rbp,%rax,4),%eax
and    $0xff,%eax
mov    %al,-0x8012(%rbp)
mov    -0x8020(%rbp),%rdi
lea    0xd6e(%rip),%rsi
movsbl -0x8011(%rbp),%edx
call   1070 <fprintf@plt>
mov    -0x8020(%rbp),%rdi
lea    0xd58(%rip),%rsi
movsbl -0x8012(%rbp),%edx
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    121d <debug+0xad>
mov    -0x8020(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x8020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<debug>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x8018,%rsp
mov    %edi,%ebp
lea    0xe66(%rip),%rdi
lea    0xe66(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     11e9 <debug+0x69>
mov    %rax,%r13
mov    %ebp,%edi
call   1050 <reset_read_ptr@plt>
mov    %ebp,%edi
call   1090 <start_acq@plt>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x2000,%edx
call   1070 <read@plt>
cmp    $0x2000,%eax
jae    1206 <debug+0x86>
lea    0xe2e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1278 <debug+0xf8>
lea    0xe37(%rip),%rdi
add    $0x8018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>
mov    %eax,%eax
mov    %rax,0x8(%rsp)
xor    %ebp,%ebp
lea    0xe09(%rip),%r14
lea    0xe06(%rip),%r15
nopl   (%rax)
mov    0x10(%rsp,%rbp,4),%r12d
mov    %r12d,%ebx
shr    $0x10,%ebx
mov    %r12d,%edx
sar    $0x18,%edx
mov    %r13,%rdi
mov    %r14,%rsi
call   1080 <fprintf@plt>
movsbl %bl,%edx
mov    %r13,%rdi
mov    %r15,%rsi
call   1080 <fprintf@plt>
mov    %r12d,%eax
shr    $0x8,%eax
movsbl %al,%edx
mov    %r13,%rdi
mov    %r14,%rsi
call   1080 <fprintf@plt>
movsbl %r12b,%edx
mov    %r13,%rdi
mov    %r15,%rsi
call   1080 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,0x8(%rsp)
jne    1220 <debug+0xa0>
mov    %r13,%rdi
add    $0x8018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"iq.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [23 x i8] c"error opening iq.dat\0D\0A\00"
@.str.3 = [22 x i8] c"read failed with %d\0D\0A\00"
@.str.4 = [4 x i8] c"%d \00"
@.str.5 = [4 x i8] c"%d\0A\00"
define void @debug(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [8192 x i32]
%6 = alloca i8
%7 = alloca i8
%8 = alloca i32*
store i32 %0, i32* %2
store i32 0, i32* %4
%9 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %8
%10 = load i32*, i32** %8
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %80
14: ; preds = %1
%15 = load i32, i32* %2
%16 = call i32 @reset_read_ptr(i32 %15)
%17 = load i32, i32* %2
%18 = call i32 @start_acq(i32 %17)
%19 = load i32, i32* %2
%20 = getelementptr inbounds [8192 x i32], [8192 x i32]* %5, i64 0, i64 0
%21 = call i32 @read(i32 %19, i32* %20, i32 8192)
store i32 %21, i32* %4
%22 = load i32, i32* %4
%23 = icmp ult i32 %22, 8192
br i1 %23, label %24, label %29
24: ; preds = %14
%25 = load i32, i32* %4
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%27 = load i32*, i32** %8
%28 = call i32 @fclose(i32* %27)
br label %80
29: ; preds = %14
store i32 0, i32* %3
br label %30
30: ; preds = %74, %29
%31 = load i32, i32* %3
%32 = load i32, i32* %4
%33 = icmp ult i32 %31, %32
br i1 %33, label %34, label %77
34: ; preds = %30
%35 = load i32, i32* %3
%36 = zext i32 %35 to i64
%37 = getelementptr inbounds [8192 x i32], [8192 x i32]* %5, i64 0, i64 %36
%38 = load i32, i32* %37
%39 = and i32 %38, -16777216
%40 = lshr i32 %39, 24
%41 = trunc i32 %40 to i8
store i8 %41, i8* %6
%42 = load i32, i32* %3
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds [8192 x i32], [8192 x i32]* %5, i64 0, i64 %43
%45 = load i32, i32* %44
%46 = and i32 %45, 16711680
%47 = ashr i32 %46, 16
%48 = trunc i32 %47 to i8
store i8 %48, i8* %7
%49 = load i32*, i32** %8
%50 = load i8, i8* %6
%51 = call i32 @fprintf(i32* %49, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8 signext %50)
%52 = load i32*, i32** %8
%53 = load i8, i8* %7
%54 = call i32 @fprintf(i32* %52, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8 signext %53)
%55 = load i32, i32* %3
%56 = zext i32 %55 to i64
%57 = getelementptr inbounds [8192 x i32], [8192 x i32]* %5, i64 0, i64 %56
%58 = load i32, i32* %57
%59 = and i32 %58, 65280
%60 = ashr i32 %59, 8
%61 = trunc i32 %60 to i8
store i8 %61, i8* %6
%62 = load i32, i32* %3
%63 = zext i32 %62 to i64
%64 = getelementptr inbounds [8192 x i32], [8192 x i32]* %5, i64 0, i64 %63
%65 = load i32, i32* %64
%66 = and i32 %65, 255
%67 = trunc i32 %66 to i8
store i8 %67, i8* %7
%68 = load i32*, i32** %8
%69 = load i8, i8* %6
%70 = call i32 @fprintf(i32* %68, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8 signext %69)
%71 = load i32*, i32** %8
%72 = load i8, i8* %7
%73 = call i32 @fprintf(i32* %71, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8 signext %72)
br label %74
74: ; preds = %34
%75 = load i32, i32* %3
%76 = add i32 %75, 1
store i32 %76, i32* %3
br label %30
77: ; preds = %30
%78 = load i32*, i32** %8
%79 = call i32 @fclose(i32* %78)
br label %80
80: ; preds = %77, %24, %12
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"iq.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.3 = [22 x i8] c"read failed with %d\0D\0A\00"
@.str.4 = [4 x i8] c"%d \00"
@.str.5 = [4 x i8] c"%d\0A\00"
@str = [22 x i8] c"error opening iq.dat\0D\00"
define void @debug(i32 %0) {
%2 = alloca [8192 x i32]
%3 = bitcast [8192 x i32]* %2 to i8*
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %38
8: ; preds = %1
%9 = tail call i32 @reset_read_ptr(i32 %0)
%10 = tail call i32 @start_acq(i32 %0)
%11 = getelementptr inbounds [8192 x i32], [8192 x i32]* %2, i64 0, i64 0
%12 = call i32 @read(i32 %0, i32* %11, i32 8192)
%13 = icmp ult i32 %12, 8192
br i1 %13, label %16, label %14
14: ; preds = %8
%15 = zext i32 %12 to i64
br label %19
16: ; preds = %8
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%18 = tail call i32 @fclose(i32* %4)
br label %38
19: ; preds = %14, %19
%20 = phi i64 [ 0, %14 ], [ %34, %19 ]
%21 = getelementptr inbounds [8192 x i32], [8192 x i32]* %2, i64 0, i64 %20
%22 = load i32, i32* %21
%23 = lshr i32 %22, 24
%24 = trunc i32 %23 to i8
%25 = lshr i32 %22, 16
%26 = trunc i32 %25 to i8
%27 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8 signext %24)
%28 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8 signext %26)
%29 = lshr i32 %22, 8
%30 = trunc i32 %29 to i8
%31 = trunc i32 %22 to i8
%32 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8 signext %30)
%33 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8 signext %31)
%34 = add nuw nsw i64 %20, 1
%35 = icmp eq i64 %34, %15
br i1 %35, label %36, label %19
36: ; preds = %19
%37 = tail call i32 @fclose(i32* %4)
br label %38
38: ; preds = %36, %16, %6
ret void
}