#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*/ OS_mdelay(int);
int sio_read_reg(int, unsigned long *);
int sio_write_reg(int, unsigned long);
int wake_up(void) {
  int err;
  unsigned long reg;
  err = sio_read_reg(0x0C, &reg);
  if (err)
    return err;
  reg |= 0x0001;
  reg &= ~0x0002;
  err = sio_write_reg(0x0C, reg);
  if (err)
    return err;
  reg &= ~0x0001;
  err = sio_write_reg(0x0C, reg);
  if (err)
    return err;
  OS_mdelay(10);
  return 0;
}


x86 assembly (clang, -O0):
<wake_up>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0xc,%edi
lea    -0x10(%rbp),%rsi
call   1040 <sio_read_reg@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     115e <wake_up+0x2e>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11df <wake_up+0xaf>
mov    -0x10(%rbp),%rax
or     $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
and    $0xfffffffffffffffd,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
mov    $0xc,%edi
call   1030 <sio_write_reg@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     119c <wake_up+0x6c>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11df <wake_up+0xaf>
mov    -0x10(%rbp),%rax
and    $0xfffffffffffffffe,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
mov    $0xc,%edi
call   1030 <sio_write_reg@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11ce <wake_up+0x9e>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11df <wake_up+0xaf>
mov    $0xa,%edi
call   1050 <OS_mdelay@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wake_up>:
push   %rax
mov    %rsp,%rsi
mov    $0xc,%edi
call   1040 <sio_read_reg@plt>
test   %eax,%eax
je     1144 <wake_up+0x14>
pop    %rcx
ret
mov    (%rsp),%rsi
and    $0xfffffffffffffffc,%rsi
or     $0x1,%rsi
mov    %rsi,(%rsp)
mov    $0xc,%edi
call   1030 <sio_write_reg@plt>
test   %eax,%eax
jne    1142 <wake_up+0x12>
mov    (%rsp),%rsi
and    $0xfffffffffffffffe,%rsi
mov    %rsi,(%rsp)
mov    $0xc,%edi
call   1030 <sio_write_reg@plt>
test   %eax,%eax
jne    1142 <wake_up+0x12>
mov    $0xa,%edi
call   1050 <OS_mdelay@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @wake_up() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = call i32 @sio_read_reg(i32 12, i64* %3)
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = load i32, i32* %2
store i32 %8, i32* %1
br label %31
9: ; preds = %0
%10 = load i64, i64* %3
%11 = or i64 %10, 1
store i64 %11, i64* %3
%12 = load i64, i64* %3
%13 = and i64 %12, -3
store i64 %13, i64* %3
%14 = load i64, i64* %3
%15 = call i32 @sio_write_reg(i32 12, i64 %14)
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %9
%19 = load i32, i32* %2
store i32 %19, i32* %1
br label %31
20: ; preds = %9
%21 = load i64, i64* %3
%22 = and i64 %21, -2
store i64 %22, i64* %3
%23 = load i64, i64* %3
%24 = call i32 @sio_write_reg(i32 12, i64 %23)
store i32 %24, i32* %2
%25 = load i32, i32* %2
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %20
%28 = load i32, i32* %2
store i32 %28, i32* %1
br label %31
29: ; preds = %20
%30 = call i32 @OS_mdelay(i32 10)
store i32 0, i32* %1
br label %31
31: ; preds = %29, %27, %18, %7
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
define i32 @wake_up() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = call i32 @sio_read_reg(i32 12, i64* %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %18
5: ; preds = %0
%6 = load i64, i64* %1
%7 = and i64 %6, -4
%8 = or i64 %7, 1
store i64 %8, i64* %1
%9 = call i32 @sio_write_reg(i32 12, i64 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %5
%12 = load i64, i64* %1
%13 = and i64 %12, -2
store i64 %13, i64* %1
%14 = call i32 @sio_write_reg(i32 12, i64 %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 @OS_mdelay(i32 10)
br label %18
18: ; preds = %11, %5, %0, %16
%19 = phi i32 [ 0, %16 ], [ %3, %0 ], [ %9, %5 ], [ %14, %11 ]
ret i32 %19
}