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

/* Variables and functions */
int atrf_rx(struct atrf_dsc *, char *, int, int /*<<< orphan*/, char *);
int /*<<< orphan*/ atrf_rx_mode(struct atrf_dsc *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ stderr;
void receive_hmac(struct atrf_dsc *dsc) {
  uint8_t buf[127];
  uint8_t lqi;
  int n, i;
  atrf_rx_mode(dsc, 1);
  n = atrf_rx(dsc, buf, sizeof(buf), 0, &lqi);
  atrf_rx_mode(dsc, 0);
  if (n < 2) {
    fprintf(stderr, "%d bytes received\n", n);
    exit(1);
  }
  for (i = 0; i != n - 2; i++)
    putchar(buf[i] < ' ' || buf[i] > '~' ? '?' : buf[i]);
  putchar('\n');
}


x86 assembly (clang, -O0):
<receive_hmac>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1060 <atrf_rx_mode@plt>
mov    -0x8(%rbp),%rdi
lea    -0x90(%rbp),%rsi
mov    $0x7f,%edx
xor    %ecx,%ecx
lea    -0x91(%rbp),%r8
call   1030 <atrf_rx@plt>
mov    %eax,-0x98(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1060 <atrf_rx_mode@plt>
cmpl   $0x2,-0x98(%rbp)
jge    11ce <receive_hmac+0x7e>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
mov    -0x98(%rbp),%edx
lea    0xe41(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x0,-0x9c(%rbp)
mov    -0x9c(%rbp),%eax
mov    -0x98(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
je     1266 <receive_hmac+0x116>
movslq -0x9c(%rbp),%rax
movsbl -0x90(%rbp,%rax,1),%eax
ff
cmp    $0x20,%eax
jl     121f <receive_hmac+0xcf>
movslq -0x9c(%rbp),%rax
movsbl -0x90(%rbp,%rax,1),%eax
ff
cmp    $0x7e,%eax
jle    122f <receive_hmac+0xdf>
mov    $0x3f,%eax
mov    %eax,-0xa0(%rbp)
jmp    1244 <receive_hmac+0xf4>
movslq -0x9c(%rbp),%rax
movsbl -0x90(%rbp,%rax,1),%eax
ff
mov    %eax,-0xa0(%rbp)
mov    -0xa0(%rbp),%eax
movsbl %al,%edi
call   1040 <putchar@plt>
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
jmp    11d8 <receive_hmac+0x88>
mov    $0xa,%edi
call   1040 <putchar@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<receive_hmac>:
push   %rbp
push   %r14
push   %rbx
sub    $0x90,%rsp
mov    %rdi,%r14
mov    $0x1,%esi
call   1060 <atrf_rx_mode@plt>
lea    0x10(%rsp),%rsi
lea    0xf(%rsp),%r8
mov    %r14,%rdi
mov    $0x7f,%edx
xor    %ecx,%ecx
call   1030 <atrf_rx@plt>
mov    %eax,%ebx
mov    %r14,%rdi
xor    %esi,%esi
call   1060 <atrf_rx_mode@plt>
cmp    $0x2,%ebx
jl     11e5 <receive_hmac+0x95>
add    $0xfffffffe,%ebx
je     11cf <receive_hmac+0x7f>
mov    %ebx,%r14d
xor    %ebx,%ebx
mov    $0x3f,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl 0x10(%rsp,%rbx,1),%eax
lea    -0x7f(%rax),%ecx
cmp    $0xa1,%cl
cmovb  %ebp,%eax
movsbl %al,%edi
call   1040 <putchar@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    11b0 <receive_hmac+0x60>
mov    $0xa,%edi
call   1040 <putchar@plt>
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
lea    0xe0b(%rip),%rsi
mov    %ebx,%edx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.atrf_dsc = type { i32 }
@stderr = global i32 0
@.str = [19 x i8] c"%d bytes received\0A\00"
define void @receive_hmac(%struct.atrf_dsc* %0) {
%2 = alloca %struct.atrf_dsc*
%3 = alloca [127 x i8]
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
store %struct.atrf_dsc* %0, %struct.atrf_dsc** %2
%7 = load %struct.atrf_dsc*, %struct.atrf_dsc** %2
%8 = call i32 @atrf_rx_mode(%struct.atrf_dsc* %7, i32 1)
%9 = load %struct.atrf_dsc*, %struct.atrf_dsc** %2
%10 = getelementptr inbounds [127 x i8], [127 x i8]* %3, i64 0, i64 0
%11 = call i32 @atrf_rx(%struct.atrf_dsc* %9, i8* %10, i32 127, i32 0, i8* %4)
store i32 %11, i32* %5
%12 = load %struct.atrf_dsc*, %struct.atrf_dsc** %2
%13 = call i32 @atrf_rx_mode(%struct.atrf_dsc* %12, i32 0)
%14 = load i32, i32* %5
%15 = icmp slt i32 %14, 2
br i1 %15, label %16, label %21
16: ; preds = %1
%17 = load i32, i32* @stderr
%18 = load i32, i32* %5
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %1
store i32 0, i32* %6
br label %22
22: ; preds = %52, %21
%23 = load i32, i32* %6
%24 = load i32, i32* %5
%25 = sub nsw i32 %24, 2
%26 = icmp ne i32 %23, %25
br i1 %26, label %27, label %55
27: ; preds = %22
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [127 x i8], [127 x i8]* %3, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp slt i32 %32, 32
br i1 %33, label %41, label %34
34: ; preds = %27
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [127 x i8], [127 x i8]* %3, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp sgt i32 %39, 126
br i1 %40, label %41, label %42
41: ; preds = %34, %27
br label %48
42: ; preds = %34
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [127 x i8], [127 x i8]* %3, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
br label %48
48: ; preds = %42, %41
%49 = phi i32 [ 63, %41 ], [ %47, %42 ]
%50 = trunc i32 %49 to i8
%51 = call i32 @putchar(i8 signext %50)
br label %52
52: ; preds = %48
%53 = load i32, i32* %6
%54 = add nsw i32 %53, 1
store i32 %54, i32* %6
br label %22
55: ; preds = %22
%56 = call i32 @putchar(i8 signext 10)
ret void
}

LLVM IR (-O2):
%struct.atrf_dsc = type { i32 }
@stderr = global i32 0
@.str = [19 x i8] c"%d bytes received\0A\00"
define void @receive_hmac(%struct.atrf_dsc* %0) {
%2 = alloca [127 x i8]
%3 = alloca i8
%4 = getelementptr inbounds [127 x i8], [127 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @atrf_rx_mode(%struct.atrf_dsc* %0, i32 1)
%6 = call i32 @atrf_rx(%struct.atrf_dsc* %0, i8* %4, i32 127, i32 0, i8* %3)
%7 = call i32 @atrf_rx_mode(%struct.atrf_dsc* %0, i32 0)
%8 = icmp slt i32 %6, 2
br i1 %8, label %14, label %9
9: ; preds = %1
%10 = add nsw i32 %6, -2
%11 = icmp eq i32 %10, 0
br i1 %11, label %28, label %12
12: ; preds = %9
%13 = zext i32 %10 to i64
br label %18
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %6)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %12, %18
%19 = phi i64 [ 0, %12 ], [ %26, %18 ]
%20 = getelementptr inbounds [127 x i8], [127 x i8]* %2, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = add i8 %21, -127
%23 = icmp ult i8 %22, -95
%24 = select i1 %23, i8 63, i8 %21
%25 = call i32 @putchar(i8 signext %24)
%26 = add nuw nsw i64 %19, 1
%27 = icmp eq i64 %26, %13
br i1 %27, label %28, label %18
28: ; preds = %18, %9
%29 = call i32 @putchar(i8 signext 10)
ret void
}