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

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
scalar_t__ RSA2048_Decrypt_CRT(int);
scalar_t__ RSA2048_export_result(int, unsigned char *);
scalar_t__ RSA2048_load_text(int, unsigned char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int RSA_is8_private_decrypt(int flen, const unsigned char *from,
                            unsigned char *to, RSA *rsa, int padding) {
  int ret = 0;
  int fd;
  unsigned char tmp[256] = {0};
  memcpy(tmp, from, 256);
  fd = open("/dev/spidev1.1", O_RDWR);
  if (fd < 0) {
    printf("D:open device  failed!\n");
    exit(1);
  }
  ret += RSA2048_load_text(fd, tmp);
  ret += RSA2048_Decrypt_CRT(fd);
  ret += RSA2048_export_result(fd, to);
  close(fd);
  if (ret == 0)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<RSA_is8_private_decrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x100,%edx
call   1080 <memcpy@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
lea    0xe13(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1215 <RSA_is8_private_decrypt+0x85>
lea    0xe09(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x2c(%rbp),%edi
lea    -0x130(%rbp),%rsi
call   1040 <RSA2048_load_text@plt>
mov    %rax,%rcx
movslq -0x28(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%edi
call   1030 <RSA2048_Decrypt_CRT@plt>
mov    %rax,%rcx
movslq -0x28(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1090 <RSA2048_export_result@plt>
mov    %rax,%rcx
movslq -0x28(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%edi
call   1070 <close@plt>
cmpl   $0x0,-0x28(%rbp)
jne    127d <RSA_is8_private_decrypt+0xed>
movl   $0x1,-0x4(%rbp)
jmp    1284 <RSA_is8_private_decrypt+0xf4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RSA_is8_private_decrypt>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdx,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
mov    $0x100,%edx
call   1070 <memcpy@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
lea    0xde9(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
js     1266 <RSA_is8_private_decrypt+0xe6>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
call   1050 <RSA2048_load_text@plt>
mov    %rax,%r15
mov    %ebp,%edi
call   1040 <RSA2048_Decrypt_CRT@plt>
mov    %rax,%rbx
add    %r15d,%ebx
mov    %ebp,%edi
mov    %r14,%rsi
call   1080 <RSA2048_export_result@plt>
mov    %rax,%r14
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    %ebx,%r14d
sete   %al
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xda2(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"/dev/spidev1.1\00"
@O_RDWR = global i32 0
@.str.1 = [24 x i8] c"D:open device failed!\0A\00"
define i32 @RSA_is8_private_decrypt(i32 %0, i8* %1, i8* %2, i32* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca [256 x i8]
store i32 %0, i32* %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i32* %3, i32** %10
store i32 %4, i32* %11
store i32 0, i32* %12
%15 = bitcast [256 x i8]* %14 to i8*
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%17 = load i8*, i8** %8
%18 = call i32 @memcpy(i8* %16, i8* %17, i32 256)
%19 = load i32, i32* @O_RDWR
%20 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %19)
store i32 %20, i32* %13
%21 = load i32, i32* %13
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %5
%24 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %5
%27 = load i32, i32* %13
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%29 = call i64 @RSA2048_load_text(i32 %27, i8* %28)
%30 = load i32, i32* %12
%31 = sext i32 %30 to i64
%32 = add nsw i64 %31, %29
%33 = trunc i64 %32 to i32
store i32 %33, i32* %12
%34 = load i32, i32* %13
%35 = call i64 @RSA2048_Decrypt_CRT(i32 %34)
%36 = load i32, i32* %12
%37 = sext i32 %36 to i64
%38 = add nsw i64 %37, %35
%39 = trunc i64 %38 to i32
store i32 %39, i32* %12
%40 = load i32, i32* %13
%41 = load i8*, i8** %9
%42 = call i64 @RSA2048_export_result(i32 %40, i8* %41)
%43 = load i32, i32* %12
%44 = sext i32 %43 to i64
%45 = add nsw i64 %44, %42
%46 = trunc i64 %45 to i32
store i32 %46, i32* %12
%47 = load i32, i32* %13
%48 = call i32 @close(i32 %47)
%49 = load i32, i32* %12
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %26
store i32 1, i32* %6
br label %53
52: ; preds = %26
store i32 0, i32* %6
br label %53
53: ; preds = %52, %51
%54 = load i32, i32* %6
ret i32 %54
}

LLVM IR (-O2):
@.str = [15 x i8] c"/dev/spidev1.1\00"
@O_RDWR = global i32 0
@str = [23 x i8] c"D:open device failed!\00"
define i32 @RSA_is8_private_decrypt(i32 %0, i8* %1, i8* %2, i32* nocapture readnone %3, i32 %4) {
%6 = alloca [256 x i8]
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%8 = call i32 @memcpy(i8* %7, i8* %1, i32 256)
%9 = load i32, i32* @O_RDWR
%10 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %5
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %5
%16 = call i64 @RSA2048_load_text(i32 %10, i8* %7)
%17 = call i64 @RSA2048_Decrypt_CRT(i32 %10)
%18 = add i64 %17, %16
%19 = call i64 @RSA2048_export_result(i32 %10, i8* %2)
%20 = add i64 %18, %19
%21 = trunc i64 %20 to i32
%22 = call i32 @close(i32 %10)
%23 = icmp eq i32 %21, 0
%24 = zext i1 %23 to i32
ret i32 %24
}