#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 /*<<< orphan*/ uint32_t;

/* Variables and functions */
int dbg_ctrl_read(int *, int *);
int dbg_set_chain(int);
int dbg_cpu0_read_ctrl(uint32_t adr, unsigned char *data) {
  int err;
  int r, s;
  if ((err = dbg_set_chain(1)))
    return err;
  if ((err = dbg_ctrl_read(&r, &s)))
    return err;
  *data = (r << 1) | s;
  return 0;
}


x86 assembly (clang, -O0):
<dbg_cpu0_read_ctrl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1,%edi
call   1030 <dbg_set_chain@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     1150 <dbg_cpu0_read_ctrl+0x30>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118c <dbg_cpu0_read_ctrl+0x6c>
lea    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1040 <dbg_ctrl_read@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     1174 <dbg_cpu0_read_ctrl+0x54>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118c <dbg_cpu0_read_ctrl+0x6c>
mov    -0x18(%rbp),%eax
shl    $0x1,%eax
or     -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dbg_cpu0_read_ctrl>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    $0x1,%edi
call   1030 <dbg_set_chain@plt>
test   %eax,%eax
jne    1157 <dbg_cpu0_read_ctrl+0x37>
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1040 <dbg_ctrl_read@plt>
test   %eax,%eax
jne    1157 <dbg_cpu0_read_ctrl+0x37>
mov    0xc(%rsp),%eax
add    %eax,%eax
or     0x8(%rsp),%eax
mov    %al,(%rbx)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @dbg_cpu0_read_ctrl(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%9 = call i32 @dbg_set_chain(i32 1)
store i32 %9, i32* %6
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = load i32, i32* %6
store i32 %12, i32* %3
br label %25
13: ; preds = %2
%14 = call i32 @dbg_ctrl_read(i32* %7, i32* %8)
store i32 %14, i32* %6
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = load i32, i32* %6
store i32 %17, i32* %3
br label %25
18: ; preds = %13
%19 = load i32, i32* %7
%20 = shl i32 %19, 1
%21 = load i32, i32* %8
%22 = or i32 %20, %21
%23 = trunc i32 %22 to i8
%24 = load i8*, i8** %5
store i8 %23, i8* %24
store i32 0, i32* %3
br label %25
25: ; preds = %18, %16, %11
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
define i32 @dbg_cpu0_read_ctrl(i32 %0, i8* nocapture writeonly %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = tail call i32 @dbg_set_chain(i32 1)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %18
9: ; preds = %2
%10 = call i32 @dbg_ctrl_read(i32* %3, i32* %4)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = load i32, i32* %3
%14 = shl i32 %13, 1
%15 = load i32, i32* %4
%16 = or i32 %14, %15
%17 = trunc i32 %16 to i8
store i8 %17, i8* %1
br label %18
18: ; preds = %9, %2, %12
%19 = phi i32 [ 0, %12 ], [ %7, %2 ], [ %10, %9 ]
ret i32 %19
}