#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 */
scalar_t__ check_ack();
int /*<<< orphan*/ error(char *);
scalar_t__ stm_cmd(int);
int /*<<< orphan*/ write_addr(unsigned int);
int /*<<< orphan*/ write_one(int);
void stm_read(unsigned int addr) {
  int count;
  int i;
  int val;
  if (stm_cmd(0x11) == 0)
    error("READ command rejected");
  write_addr(addr);
  if (check_ack() == 0)
    error("READ address rejected");
  count = 128;
  val = count - 1;
  write_one(val);
  write_one(~val);
  if (check_ack() == 0)
    error("READ count rejected");
}


x86 assembly (clang, -O0):
<stm_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x11,%edi
call   1030 <stm_cmd@plt>
cmp    $0x0,%rax
jne    117b <stm_read+0x2b>
lea    0xe8a(%rip),%rdi
call   1070 <error@plt>
mov    -0x4(%rbp),%edi
call   1050 <write_addr@plt>
mov    $0x0,%al
call   1040 <check_ack@plt>
cmp    $0x0,%rax
jne    11a0 <stm_read+0x50>
lea    0xe7b(%rip),%rdi
call   1070 <error@plt>
movl   $0x80,-0x8(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1060 <write_one@plt>
mov    -0x10(%rbp),%edi
xor    $0xffffffff,%edi
call   1060 <write_one@plt>
mov    $0x0,%al
call   1040 <check_ack@plt>
cmp    $0x0,%rax
jne    11e0 <stm_read+0x90>
lea    0xe51(%rip),%rdi
call   1070 <error@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stm_read>:
push   %rbx
mov    %edi,%ebx
mov    $0x11,%edi
call   1030 <stm_cmd@plt>
test   %rax,%rax
jne    116e <stm_read+0x1e>
lea    0xe97(%rip),%rdi
call   1070 <error@plt>
mov    %ebx,%edi
call   1050 <write_addr@plt>
xor    %eax,%eax
call   1040 <check_ack@plt>
test   %rax,%rax
jne    118d <stm_read+0x3d>
lea    0xe8e(%rip),%rdi
call   1070 <error@plt>
mov    $0x7f,%edi
call   1060 <write_one@plt>
mov    $0xffffff80,%edi
call   1060 <write_one@plt>
xor    %eax,%eax
call   1040 <check_ack@plt>
test   %rax,%rax
je     11af <stm_read+0x5f>
pop    %rbx
ret
lea    0xe76(%rip),%rdi
pop    %rbx
jmp    1070 <error@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"READ command rejected\00"
@.str.1 = [22 x i8] c"READ address rejected\00"
@.str.2 = [20 x i8] c"READ count rejected\00"
define void @stm_read(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = call i64 @stm_cmd(i32 17)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %1
%11 = load i32, i32* %2
%12 = call i32 @write_addr(i32 %11)
%13 = call i64 (...) @check_ack()
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = call i32 @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %10
store i32 128, i32* %3
%18 = load i32, i32* %3
%19 = sub nsw i32 %18, 1
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = call i32 @write_one(i32 %20)
%22 = load i32, i32* %5
%23 = xor i32 %22, -1
%24 = call i32 @write_one(i32 %23)
%25 = call i64 (...) @check_ack()
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %17
%28 = call i32 @error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27, %17
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"READ command rejected\00"
@.str.1 = [22 x i8] c"READ address rejected\00"
@.str.2 = [20 x i8] c"READ count rejected\00"
define void @stm_read(i32 %0) {
%2 = tail call i64 @stm_cmd(i32 17)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %4, %1
%7 = tail call i32 @write_addr(i32 %0)
%8 = tail call i64 (...) @check_ack()
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %6
%13 = tail call i32 @write_one(i32 127)
%14 = tail call i32 @write_one(i32 -128)
%15 = tail call i64 (...) @check_ack()
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = tail call i32 @error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %17, %12
ret void
}