#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_RDONLY;
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, short);
int read(int, short *, int);
int main(int rgc, char *argv[]) {
  int fp, cnt, n;
  short buf[1024];
  n = 0;
  fp = open("/dev/usrp1_e0", O_RDONLY);
  printf("fp = %d\n", fp);
  do {
    cnt = read(fp, buf, 2048);
    n++;
  } while (n < 10 * 512);
  printf("Data - %hX\n", buf[0]);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
lea    0xea0(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
lea    0xe9c(%rip),%rdi
movswl %ax,%esi
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    $0x800,%edx
call   1040 <read@plt>
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x1400,-0x1c(%rbp)
jl     117a <main+0x4a>
lea    0xe69(%rip),%rdi
movswl -0x820(%rbp),%esi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x800,%rsp
mov    0x2ea6(%rip),%rax
mov    (%rax),%esi
lea    0xeb5(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
movswl %bx,%esi
lea    0xeb2(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1400,%ebp
mov    %rsp,%r14
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x800,%edx
call   1040 <read@plt>
add    $0xffffffff,%ebp
jne    1170 <main+0x40>
movswl (%rsp),%esi
lea    0xe88(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/dev/usrp1_e0\00"
@O_RDONLY = global i32 0
@.str.1 = [9 x i8] c"fp = %d\0A\00"
@.str.2 = [12 x i8] c"Data - %hX\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 [1024 x i16]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = trunc i32 %12 to i16
%14 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i16 signext %13)
br label %15
15: ; preds = %21, %2
%16 = load i32, i32* %6
%17 = getelementptr inbounds [1024 x i16], [1024 x i16]* %9, i64 0, i64 0
%18 = call i32 @read(i32 %16, i16* %17, i32 2048)
store i32 %18, i32* %7
%19 = load i32, i32* %8
%20 = add nsw i32 %19, 1
store i32 %20, i32* %8
br label %21
21: ; preds = %15
%22 = load i32, i32* %8
%23 = icmp slt i32 %22, 5120
br i1 %23, label %15, label %24
24: ; preds = %21
%25 = getelementptr inbounds [1024 x i16], [1024 x i16]* %9, i64 0, i64 0
%26 = load i16, i16* %25
%27 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i16 signext %26)
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@.str = [14 x i8] c"/dev/usrp1_e0\00"
@O_RDONLY = global i32 0
@.str.1 = [9 x i8] c"fp = %d\0A\00"
@.str.2 = [12 x i8] c"Data - %hX\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i16]
%4 = bitcast [1024 x i16]* %3 to i8*
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = trunc i32 %6 to i16
%8 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i16 signext %7)
%9 = getelementptr inbounds [1024 x i16], [1024 x i16]* %3, i64 0, i64 0
br label %10
10: ; preds = %10, %2
%11 = phi i32 [ 0, %2 ], [ %13, %10 ]
%12 = call i32 @read(i32 %6, i16* %9, i32 2048)
%13 = add nuw nsw i32 %11, 1
%14 = icmp eq i32 %13, 5120
br i1 %14, label %15, label %10
15: ; preds = %10
%16 = load i16, i16* %9
%17 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i16 signext %16)
ret i32 0
}