#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ debug(int);
scalar_t__ fpga_test_comm(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read_ram(int);
int /*<<< orphan*/ reset_read_ptr(int);
int /*<<< orphan*/ set_decim_factor(int, int);
int /*<<< orphan*/ start_acq(int);
int /*<<< orphan*/ stop_acq(int);
scalar_t__ strcmp(char *, char *);
int main(int argc, char **argv) {
  int value;
  int iq, i1, i2, q1, q2;
  int fd;
  int buffer[8192];
  char logfile[10];
  fd = open("/dev/iqram", O_RDWR);
  if (fd < 0) {
    printf("error opening /dev/iqram\r\n");
    goto fail;
  }
  if (fpga_test_comm(fd) < 0) {
    printf("fpga ip comm failed\r\n");
    goto fail;
  }
  if (strcmp(argv[1], "debug") == 0) {
    iq = read_ram(fd);
    printf("iq 0x%x \r\n", iq);
    i1 = (iq & 0xff000000) >> 24;
    q1 = (iq & 0xff0000) >> 16;
    i2 = (iq & 0xff00) >> 8;
    q2 = (iq & 0x00ff);
    printf("i1: 0x%x q1: 0x%x i2: 0x%x q2: 0x%x\r\n", i1, q1, i2, q2);
  } else if (strcmp(argv[1], "start") == 0)
    start_acq(fd);
  else if (strcmp(argv[1], "stop") == 0)
    stop_acq(fd);
  else if (strcmp(argv[1], "reset") == 0)
    reset_read_ptr(fd);
  else if (strcmp(argv[1], "decim") == 0) {
    value = atoi(argv[2]);
    set_decim_factor(fd, value);
  } else if (strcmp(argv[1], "debug") == 0)
    debug(fd);
  else
    printf("use ./ram [start/stop/reset/decim/debug] [decim_factor] \r\n");
  close(fd);
  return 0;
fail:
  return -1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
lea    0xe17(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    120e <main+0x4e>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    13e7 <main+0x227>
mov    -0x2c(%rbp),%edi
call   1080 <fpga_test_comm@plt>
cmp    $0x0,%rax
jge    1233 <main+0x73>
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    13e7 <main+0x227>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdfa(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    12c2 <main+0x102>
mov    -0x2c(%rbp),%edi
call   10c0 <read_ram@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%eax
and    $0xff000000,%eax
shr    $0x18,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
and    $0xff0000,%eax
sar    $0x10,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x28(%rbp),%r8d
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    13d3 <main+0x213>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xda2(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    12ed <main+0x12d>
mov    -0x2c(%rbp),%edi
call   10a0 <start_acq@plt>
jmp    13ce <main+0x20e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd7d(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    1318 <main+0x158>
mov    -0x2c(%rbp),%edi
call   10e0 <stop_acq@plt>
jmp    13c9 <main+0x209>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd57(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    1343 <main+0x183>
mov    -0x2c(%rbp),%edi
call   1040 <reset_read_ptr@plt>
jmp    13c4 <main+0x204>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd32(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    1381 <main+0x1c1>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <set_decim_factor@plt>
jmp    13bf <main+0x1ff>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xcac(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    13ac <main+0x1ec>
mov    -0x2c(%rbp),%edi
call   1050 <debug@plt>
jmp    13ba <main+0x1fa>
lea    0xcd7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    13bf <main+0x1ff>
jmp    13c4 <main+0x204>
jmp    13c9 <main+0x209>
jmp    13ce <main+0x20e>
jmp    13d3 <main+0x213>
mov    -0x2c(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    13ee <main+0x22e>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x8040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
lea    0xe1a(%rip),%rdi
call   10c0 <open@plt>
test   %eax,%eax
js     12ac <main+0xdc>
mov    %eax,%ebp
mov    %eax,%edi
call   1090 <fpga_test_comm@plt>
test   %rax,%rax
js     12b5 <main+0xe5>
mov    0x8(%rbx),%rdi
lea    0xdfb(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     12c8 <main+0xf8>
mov    0x8(%rbx),%rdi
lea    0xe19(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1307 <main+0x137>
mov    0x8(%rbx),%rdi
lea    0xe06(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1310 <main+0x140>
mov    0x8(%rbx),%rdi
lea    0xdf2(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1319 <main+0x149>
mov    0x8(%rbx),%rdi
lea    0xddf(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1322 <main+0x152>
mov    0x8(%rbx),%rdi
lea    0xd7e(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1336 <main+0x166>
lea    0xdb7(%rip),%rdi
call   1040 <puts@plt>
jmp    133d <main+0x16d>
lea    0xdf5(%rip),%rdi
jmp    12bc <main+0xec>
lea    0xdd7(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
jmp    1346 <main+0x176>
mov    %ebp,%edi
call   10d0 <read_ram@plt>
mov    %eax,%ebx
lea    0xd39(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebx,%eax
shr    $0x18,%eax
mov    %ebx,%ecx
shr    $0x10,%ecx
movzbl %cl,%edx
movzbl %bh,%ecx
movzbl %bl,%r8d
lea    0xd20(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    133d <main+0x16d>
mov    %ebp,%edi
call   10b0 <start_acq@plt>
jmp    133d <main+0x16d>
mov    %ebp,%edi
call   10f0 <stop_acq@plt>
jmp    133d <main+0x16d>
mov    %ebp,%edi
call   1050 <reset_read_ptr@plt>
jmp    133d <main+0x16d>
mov    0x10(%rbx),%rdi
call   10e0 <atoi@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1030 <set_decim_factor@plt>
jmp    133d <main+0x16d>
mov    %ebp,%edi
call   1060 <debug@plt>
mov    %ebp,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/iqram\00"
@O_RDWR = global i32 0
@.str.1 = [27 x i8] c"error opening /dev/iqram\0D\0A\00"
@.str.2 = [22 x i8] c"fpga ip comm failed\0D\0A\00"
@.str.3 = [6 x i8] c"debug\00"
@.str.4 = [11 x i8] c"iq 0x%x \0D\0A\00"
@.str.5 = [38 x i8] c"i1: 0x%x q1: 0x%x i2: 0x%x q2: 0x%x\0D\0A\00"
@.str.6 = [6 x i8] c"start\00"
@.str.7 = [5 x i8] c"stop\00"
@.str.8 = [6 x i8] c"reset\00"
@.str.9 = [6 x i8] c"decim\00"
@.str.10 = [59 x i8] c"use ./ram [start/stop/reset/decim/debug] [decim_factor] \0D\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca [8192 x i32]
%14 = alloca [10 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* @O_RDWR
%16 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %15)
store i32 %16, i32* %12
%17 = load i32, i32* %12
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %114
21: ; preds = %2
%22 = load i32, i32* %12
%23 = call i64 @fpga_test_comm(i32 %22)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %114
27: ; preds = %21
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %54
33: ; preds = %27
%34 = load i32, i32* %12
%35 = call i32 @read_ram(i32 %34)
store i32 %35, i32* %7
%36 = load i32, i32* %7
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %7
%39 = and i32 %38, -16777216
%40 = lshr i32 %39, 24
store i32 %40, i32* %8
%41 = load i32, i32* %7
%42 = and i32 %41, 16711680
%43 = ashr i32 %42, 16
store i32 %43, i32* %10
%44 = load i32, i32* %7
%45 = and i32 %44, 65280
%46 = ashr i32 %45, 8
store i32 %46, i32* %9
%47 = load i32, i32* %7
%48 = and i32 %47, 255
store i32 %48, i32* %11
%49 = load i32, i32* %8
%50 = load i32, i32* %10
%51 = load i32, i32* %9
%52 = load i32, i32* %11
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i32 %49, i32 %50, i32 %51, i32 %52)
br label %111
54: ; preds = %27
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 1
%57 = load i8*, i8** %56
%58 = call i64 @strcmp(i8* %57, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %63
60: ; preds = %54
%61 = load i32, i32* %12
%62 = call i32 @start_acq(i32 %61)
br label %110
63: ; preds = %54
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 1
%66 = load i8*, i8** %65
%67 = call i64 @strcmp(i8* %66, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%68 = icmp eq i64 %67, 0
br i1 %68, label %69, label %72
69: ; preds = %63
%70 = load i32, i32* %12
%71 = call i32 @stop_acq(i32 %70)
br label %109
72: ; preds = %63
%73 = load i8**, i8*** %5
%74 = getelementptr inbounds i8*, i8** %73, i64 1
%75 = load i8*, i8** %74
%76 = call i64 @strcmp(i8* %75, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%77 = icmp eq i64 %76, 0
br i1 %77, label %78, label %81
78: ; preds = %72
%79 = load i32, i32* %12
%80 = call i32 @reset_read_ptr(i32 %79)
br label %108
81: ; preds = %72
%82 = load i8**, i8*** %5
%83 = getelementptr inbounds i8*, i8** %82, i64 1
%84 = load i8*, i8** %83
%85 = call i64 @strcmp(i8* %84, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%86 = icmp eq i64 %85, 0
br i1 %86, label %87, label %95
87: ; preds = %81
%88 = load i8**, i8*** %5
%89 = getelementptr inbounds i8*, i8** %88, i64 2
%90 = load i8*, i8** %89
%91 = call i32 @atoi(i8* %90)
store i32 %91, i32* %6
%92 = load i32, i32* %12
%93 = load i32, i32* %6
%94 = call i32 @set_decim_factor(i32 %92, i32 %93)
br label %107
95: ; preds = %81
%96 = load i8**, i8*** %5
%97 = getelementptr inbounds i8*, i8** %96, i64 1
%98 = load i8*, i8** %97
%99 = call i64 @strcmp(i8* %98, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%100 = icmp eq i64 %99, 0
br i1 %100, label %101, label %104
101: ; preds = %95
%102 = load i32, i32* %12
%103 = call i32 @debug(i32 %102)
br label %106
104: ; preds = %95
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.10, i64 0, i64 0))
br label %106
106: ; preds = %104, %101
br label %107
107: ; preds = %106, %87
br label %108
108: ; preds = %107, %78
br label %109
109: ; preds = %108, %69
br label %110
110: ; preds = %109, %60
br label %111
111: ; preds = %110, %33
%112 = load i32, i32* %12
%113 = call i32 @close(i32 %112)
store i32 0, i32* %3
br label %115
114: ; preds = %25, %19
store i32 -1, i32* %3
br label %115
115: ; preds = %114, %111
%116 = load i32, i32* %3
ret i32 %116
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/iqram\00"
@O_RDWR = global i32 0
@.str.3 = [6 x i8] c"debug\00"
@.str.4 = [11 x i8] c"iq 0x%x \0D\0A\00"
@.str.5 = [38 x i8] c"i1: 0x%x q1: 0x%x i2: 0x%x q2: 0x%x\0D\0A\00"
@.str.6 = [6 x i8] c"start\00"
@.str.7 = [5 x i8] c"stop\00"
@.str.8 = [6 x i8] c"reset\00"
@.str.9 = [6 x i8] c"decim\00"
@str = [58 x i8] c"use ./ram [start/stop/reset/decim/debug] [decim_factor] \0D\00"
@str.11 = [21 x i8] c"fpga ip comm failed\0D\00"
@str.12 = [26 x i8] c"error opening /dev/iqram\0D\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.12, i64 0, i64 0))
br label %65
8: ; preds = %2
%9 = tail call i64 @fpga_test_comm(i32 %4)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.11, i64 0, i64 0))
br label %65
13: ; preds = %8
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %28
18: ; preds = %13
%19 = tail call i32 @read_ram(i32 %4)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %19)
%21 = lshr i32 %19, 24
%22 = lshr i32 %19, 16
%23 = and i32 %22, 255
%24 = lshr i32 %19, 8
%25 = and i32 %24, 255
%26 = and i32 %19, 255
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i32 %21, i32 %23, i32 %25, i32 %26)
br label %63
28: ; preds = %13
%29 = load i8*, i8** %14
%30 = tail call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = tail call i32 @start_acq(i32 %4)
br label %63
34: ; preds = %28
%35 = load i8*, i8** %14
%36 = tail call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = tail call i32 @stop_acq(i32 %4)
br label %63
40: ; preds = %34
%41 = load i8*, i8** %14
%42 = tail call i64 @strcmp(i8* %41, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = tail call i32 @reset_read_ptr(i32 %4)
br label %63
46: ; preds = %40
%47 = load i8*, i8** %14
%48 = tail call i64 @strcmp(i8* %47, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %55
50: ; preds = %46
%51 = getelementptr inbounds i8*, i8** %1, i64 2
%52 = load i8*, i8** %51
%53 = tail call i32 @atoi(i8* %52)
%54 = tail call i32 @set_decim_factor(i32 %4, i32 %53)
br label %63
55: ; preds = %46
%56 = load i8*, i8** %14
%57 = tail call i64 @strcmp(i8* %56, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %55
%60 = tail call i32 @debug(i32 %4)
br label %63
61: ; preds = %55
%62 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str, i64 0, i64 0))
br label %63
63: ; preds = %32, %44, %59, %61, %50, %38, %18
%64 = tail call i32 @close(i32 %4)
br label %65
65: ; preds = %6, %11, %63
%66 = phi i32 [ 0, %63 ], [ -1, %11 ], [ -1, %6 ]
ret i32 %66
}