#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 unsigned int uint8_t;
typedef int uint32_t;

/* Variables and functions */
unsigned int spi_recv_byte();
int /*<<< orphan*/ spi_send_byte(unsigned int volatile);
uint8_t sd_send_cmd_param(uint8_t cmd, uint32_t param) {
  uint8_t r1, cnt;
  (*(volatile uint8_t *)(void *)(0xffffff10)) &= ~(1U << (6));
  spi_recv_byte();
  (*(volatile uint8_t *)(void *)(0xfffee414)) = 0;
  spi_send_byte(0x40 | cmd);
  spi_send_byte(param >> 24);
  spi_send_byte(param >> 16);
  spi_send_byte(param >> 8);
  spi_send_byte(param);
  spi_send_byte((*(volatile uint8_t *)(void *)(0xfffee414)));
  if (cmd == 12)
    spi_send_byte(0xff);
  (*(volatile uint8_t *)(void *)(0xfffee400)) = 31;
  r1 = spi_recv_byte();
  (*(volatile uint8_t *)(void *)(0xfffee400)) = 7;
  return r1;
}


x86 assembly (clang, -O0):
<sd_send_cmd_param>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    $0xffffff10,%eax
mov    (%rax),%ecx
and    $0xffffffbf,%ecx
mov    $0xffffff10,%eax
mov    %ecx,(%rax)
mov    $0x0,%al
call   1030 <spi_recv_byte@plt>
mov    $0xfffee414,%eax
movl   $0x0,(%rax)
mov    -0x4(%rbp),%edi
or     $0x40,%edi
call   1040 <spi_send_byte@plt>
mov    -0x8(%rbp),%edi
sar    $0x18,%edi
call   1040 <spi_send_byte@plt>
mov    -0x8(%rbp),%edi
sar    $0x10,%edi
call   1040 <spi_send_byte@plt>
mov    -0x8(%rbp),%edi
sar    $0x8,%edi
call   1040 <spi_send_byte@plt>
mov    -0x8(%rbp),%edi
call   1040 <spi_send_byte@plt>
mov    $0xfffee414,%eax
mov    (%rax),%edi
call   1040 <spi_send_byte@plt>
cmpl   $0xc,-0x4(%rbp)
jne    11a5 <sd_send_cmd_param+0x85>
mov    $0xff,%edi
call   1040 <spi_send_byte@plt>
mov    $0xfffee400,%eax
movl   $0x1f,(%rax)
mov    $0x0,%al
call   1030 <spi_recv_byte@plt>
mov    %eax,-0xc(%rbp)
mov    $0xfffee400,%eax
movl   $0x7,(%rax)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sd_send_cmd_param>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %edi,%ebx
mov    $0xfffee400,%r14d
andl   $0xffffffbf,0x11b10(%r14)
bf
xor    %eax,%eax
call   1030 <spi_recv_byte@plt>
movl   $0x0,0x14(%r14)
mov    %ebx,%edi
or     $0x40,%edi
call   1040 <spi_send_byte@plt>
mov    %ebp,%edi
sar    $0x18,%edi
call   1040 <spi_send_byte@plt>
mov    %ebp,%edi
sar    $0x10,%edi
call   1040 <spi_send_byte@plt>
mov    %ebp,%edi
sar    $0x8,%edi
call   1040 <spi_send_byte@plt>
mov    %ebp,%edi
call   1040 <spi_send_byte@plt>
mov    0x14(%r14),%edi
call   1040 <spi_send_byte@plt>
cmp    $0xc,%ebx
jne    118c <sd_send_cmd_param+0x6c>
mov    $0xff,%edi
call   1040 <spi_send_byte@plt>
movl   $0x1f,(%r14)
xor    %eax,%eax
call   1030 <spi_recv_byte@plt>
movl   $0x7,(%r14)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @sd_send_cmd_param(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load volatile i32, i32* inttoptr (i64 4294967056 to i32*)
%8 = and i32 %7, -65
store volatile i32 %8, i32* inttoptr (i64 4294967056 to i32*)
%9 = call i32 (...) @spi_recv_byte()
store volatile i32 0, i32* inttoptr (i64 4294894612 to i32*)
%10 = load i32, i32* %3
%11 = or i32 64, %10
%12 = call i32 @spi_send_byte(i32 %11)
%13 = load i32, i32* %4
%14 = ashr i32 %13, 24
%15 = call i32 @spi_send_byte(i32 %14)
%16 = load i32, i32* %4
%17 = ashr i32 %16, 16
%18 = call i32 @spi_send_byte(i32 %17)
%19 = load i32, i32* %4
%20 = ashr i32 %19, 8
%21 = call i32 @spi_send_byte(i32 %20)
%22 = load i32, i32* %4
%23 = call i32 @spi_send_byte(i32 %22)
%24 = load volatile i32, i32* inttoptr (i64 4294894612 to i32*)
%25 = call i32 @spi_send_byte(i32 %24)
%26 = load i32, i32* %3
%27 = icmp eq i32 %26, 12
br i1 %27, label %28, label %30
28: ; preds = %2
%29 = call i32 @spi_send_byte(i32 255)
br label %30
30: ; preds = %28, %2
store volatile i32 31, i32* inttoptr (i64 4294894592 to i32*)
%31 = call i32 (...) @spi_recv_byte()
store i32 %31, i32* %5
store volatile i32 7, i32* inttoptr (i64 4294894592 to i32*)
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
define i32 @sd_send_cmd_param(i32 %0, i32 %1) {
%3 = load volatile i32, i32* inttoptr (i64 4294967056 to i32*)
%4 = and i32 %3, -65
store volatile i32 %4, i32* inttoptr (i64 4294967056 to i32*)
%5 = tail call i32 (...) @spi_recv_byte()
store volatile i32 0, i32* inttoptr (i64 4294894612 to i32*)
%6 = or i32 %0, 64
%7 = tail call i32 @spi_send_byte(i32 %6)
%8 = ashr i32 %1, 24
%9 = tail call i32 @spi_send_byte(i32 %8)
%10 = ashr i32 %1, 16
%11 = tail call i32 @spi_send_byte(i32 %10)
%12 = ashr i32 %1, 8
%13 = tail call i32 @spi_send_byte(i32 %12)
%14 = tail call i32 @spi_send_byte(i32 %1)
%15 = load volatile i32, i32* inttoptr (i64 4294894612 to i32*)
%16 = tail call i32 @spi_send_byte(i32 %15)
%17 = icmp eq i32 %0, 12
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = tail call i32 @spi_send_byte(i32 255)
br label %20
20: ; preds = %18, %2
store volatile i32 31, i32* inttoptr (i64 4294894592 to i32*)
%21 = tail call i32 (...) @spi_recv_byte()
store volatile i32 7, i32* inttoptr (i64 4294894592 to i32*)
ret i32 %21
}