#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 */
unsigned char *ErCheck_malloc(int);
unsigned char aptx4869_kg();
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/);
unsigned char *aptx4869_encrypt(unsigned char onechar, int rank) {
  int scale = (int)rank;
  unsigned char *result = ErCheck_malloc(scale);
  int count = 0;
  srand(time(0));
  unsigned char key;
  int randnum;
  randnum = rand() % scale;
  for (count = 0; count < scale; count++) {
    key = aptx4869_kg();
    if (count == randnum) {
      result[randnum] = onechar ^ key;
    } else {
      result[count] = key;
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<aptx4869_encrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <ErCheck_malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
mov    $0x0,%al
call   1070 <rand@plt>
cltd
idivl  -0xc(%rbp)
mov    %edx,-0x24(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11fc <aptx4869_encrypt+0xac>
mov    $0x0,%al
call   1050 <aptx4869_kg@plt>
mov    %al,-0x1d(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jne    11db <aptx4869_encrypt+0x8b>
movzbl -0x1(%rbp),%eax
movzbl -0x1d(%rbp),%ecx
xor    %ecx,%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11e9 <aptx4869_encrypt+0x99>
mov    -0x1d(%rbp),%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11ee <aptx4869_encrypt+0x9e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    119d <aptx4869_encrypt+0x4d>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aptx4869_encrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%r15d
mov    %esi,%edi
call   1060 <ErCheck_malloc@plt>
mov    %rax,%r13
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
xor    %eax,%eax
call   1070 <rand@plt>
cltd
idiv   %ebx
test   %ebx,%ebx
jle    11c4 <aptx4869_encrypt+0x74>
movslq %edx,%r12
mov    %r12d,%r14d
mov    %ebx,%ebx
xor    %ebp,%ebp
jmp    11ae <aptx4869_encrypt+0x5e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %al,0x0(%r13,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%rbx
je     11c4 <aptx4869_encrypt+0x74>
xor    %eax,%eax
call   1050 <aptx4869_kg@plt>
cmp    %rbp,%r14
jne    11a0 <aptx4869_encrypt+0x50>
xor    %r15b,%al
mov    %al,0x0(%r13,%r12,1)
jmp    11a5 <aptx4869_encrypt+0x55>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @aptx4869_encrypt(i8 zeroext %0, i32 %1) {
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8
%9 = alloca i32
store i8 %0, i8* %3
store i32 %1, i32* %4
%10 = load i32, i32* %4
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = call i8* @ErCheck_malloc(i32 %11)
store i8* %12, i8** %6
store i32 0, i32* %7
%13 = call i32 @time(i32 0)
%14 = call i32 @srand(i32 %13)
%15 = call i32 (...) @rand()
%16 = load i32, i32* %5
%17 = srem i32 %15, %16
store i32 %17, i32* %9
store i32 0, i32* %7
br label %18
18: ; preds = %45, %2
%19 = load i32, i32* %7
%20 = load i32, i32* %5
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %48
22: ; preds = %18
%23 = call zeroext i8 (...) @aptx4869_kg()
store i8 %23, i8* %8
%24 = load i32, i32* %7
%25 = load i32, i32* %9
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %38
27: ; preds = %22
%28 = load i8, i8* %3
%29 = zext i8 %28 to i32
%30 = load i8, i8* %8
%31 = zext i8 %30 to i32
%32 = xor i32 %29, %31
%33 = trunc i32 %32 to i8
%34 = load i8*, i8** %6
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 %33, i8* %37
br label %44
38: ; preds = %22
%39 = load i8, i8* %8
%40 = load i8*, i8** %6
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
store i8 %39, i8* %43
br label %44
44: ; preds = %38, %27
br label %45
45: ; preds = %44
%46 = load i32, i32* %7
%47 = add nsw i32 %46, 1
store i32 %47, i32* %7
br label %18
48: ; preds = %18
%49 = load i8*, i8** %6
ret i8* %49
}

LLVM IR (-O2):
define i8* @aptx4869_encrypt(i8 zeroext %0, i32 %1) {
%3 = tail call i8* @ErCheck_malloc(i32 %1)
%4 = tail call i32 @time(i32 0)
%5 = tail call i32 @srand(i32 %4)
%6 = tail call i32 (...) @rand()
%7 = srem i32 %6, %1
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %25
9: ; preds = %2
%10 = sext i32 %7 to i64
%11 = getelementptr inbounds i8, i8* %3, i64 %10
%12 = zext i32 %7 to i64
%13 = zext i32 %1 to i64
br label %14
14: ; preds = %9, %22
%15 = phi i64 [ 0, %9 ], [ %23, %22 ]
%16 = tail call zeroext i8 (...) @aptx4869_kg()
%17 = icmp eq i64 %15, %12
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = xor i8 %16, %0
store i8 %19, i8* %11
br label %22
20: ; preds = %14
%21 = getelementptr inbounds i8, i8* %3, i64 %15
store i8 %16, i8* %21
br label %22
22: ; preds = %18, %20
%23 = add nuw nsw i64 %15, 1
%24 = icmp eq i64 %23, %13
br i1 %24, label %25, label %14
25: ; preds = %22, %2
ret i8* %3
}