#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_Encrypt(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_public_encrypt(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);
  }
  printf("\ntest test test\n");
  ret += RSA2048_load_text(fd, tmp);
  ret += RSA2048_Encrypt(fd);
  ret += RSA2048_export_result(fd, to);
  close(fd);
  if (ret == 0)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<RSA_is8_public_encrypt>:
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_public_encrypt+0x85>
lea    0xe09(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xe0b(%rip),%rdi
call   1050 <printf@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_Encrypt@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    1289 <RSA_is8_public_encrypt+0xf9>
movl   $0x1,-0x4(%rbp)
jmp    1290 <RSA_is8_public_encrypt+0x100>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RSA_is8_public_encrypt>:
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     1272 <RSA_is8_public_encrypt+0xf2>
mov    %eax,%ebp
lea    0xde6(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
call   1050 <RSA2048_load_text@plt>
mov    %rax,%r15
mov    %ebp,%edi
call   1030 <RSA2048_Encrypt@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    0xda6(%rip),%rdi
call   1040 <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"
@.str.2 = [17 x i8] c"\0Atest test test\0A\00"
define i32 @RSA_is8_public_encrypt(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 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%28 = load i32, i32* %13
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%30 = call i64 @RSA2048_load_text(i32 %28, i8* %29)
%31 = load i32, i32* %12
%32 = sext i32 %31 to i64
%33 = add nsw i64 %32, %30
%34 = trunc i64 %33 to i32
store i32 %34, i32* %12
%35 = load i32, i32* %13
%36 = call i64 @RSA2048_Encrypt(i32 %35)
%37 = load i32, i32* %12
%38 = sext i32 %37 to i64
%39 = add nsw i64 %38, %36
%40 = trunc i64 %39 to i32
store i32 %40, i32* %12
%41 = load i32, i32* %13
%42 = load i8*, i8** %9
%43 = call i64 @RSA2048_export_result(i32 %41, i8* %42)
%44 = load i32, i32* %12
%45 = sext i32 %44 to i64
%46 = add nsw i64 %45, %43
%47 = trunc i64 %46 to i32
store i32 %47, i32* %12
%48 = load i32, i32* %13
%49 = call i32 @close(i32 %48)
%50 = load i32, i32* %12
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %26
store i32 1, i32* %6
br label %54
53: ; preds = %26
store i32 0, i32* %6
br label %54
54: ; preds = %53, %52
%55 = load i32, i32* %6
ret i32 %55
}

LLVM IR (-O2):
@.str = [15 x i8] c"/dev/spidev1.1\00"
@O_RDWR = global i32 0
@str = [16 x i8] c"\0Atest test test\00"
@str.3 = [23 x i8] c"D:open device failed!\00"
define i32 @RSA_is8_public_encrypt(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.3, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %5
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%17 = call i64 @RSA2048_load_text(i32 %10, i8* %7)
%18 = call i64 @RSA2048_Encrypt(i32 %10)
%19 = add i64 %18, %17
%20 = call i64 @RSA2048_export_result(i32 %10, i8* %2)
%21 = add i64 %19, %20
%22 = trunc i64 %21 to i32
%23 = call i32 @close(i32 %10)
%24 = icmp eq i32 %22, 0
%25 = zext i1 %24 to i32
ret i32 %25
}