#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 strlen(char const *);
void safe_text(int value, int vector, const char *plain_text,
               char *text_to_safe) {
  for (int i = 0; i < strlen(plain_text); i++) {
    text_to_safe[i] = (char)((char)(plain_text[i] * value + vector) % 256);
  }
}


x86 assembly (clang, -O0):
<safe_text>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    1180 <safe_text+0x70>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
imul   -0x4(%rbp),%eax
add    -0x8(%rbp),%eax
movsbl %al,%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112d <safe_text+0x1d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safe_text>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %esi,%r15d
mov    %edi,%r12d
mov    %rdx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1162 <safe_text+0x52>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rbx,%rbp,1),%eax
imul   %r12d,%eax
add    %r15d,%eax
mov    %al,(%r14,%rbp,1)
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     1140 <safe_text+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @safe_text(i32 %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
store i32 0, i32* %9
br label %10
10: ; preds = %34, %4
%11 = load i32, i32* %9
%12 = load i8*, i8** %7
%13 = call i32 @strlen(i8* %12)
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %37
15: ; preds = %10
%16 = load i8*, i8** %7
%17 = load i32, i32* %9
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = load i32, i32* %5
%23 = mul nsw i32 %21, %22
%24 = load i32, i32* %6
%25 = add nsw i32 %23, %24
%26 = trunc i32 %25 to i8
%27 = sext i8 %26 to i32
%28 = srem i32 %27, 256
%29 = trunc i32 %28 to i8
%30 = load i8*, i8** %8
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 %29, i8* %33
br label %34
34: ; preds = %15
%35 = load i32, i32* %9
%36 = add nsw i32 %35, 1
store i32 %36, i32* %9
br label %10
37: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @safe_text(i32 %0, i32 %1, i8* %2, i8* nocapture writeonly %3) {
%5 = tail call i32 @strlen(i8* %2)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %8, label %7
7: ; preds = %8, %4
ret void
8: ; preds = %4, %8
%9 = phi i64 [ %17, %8 ], [ 0, %4 ]
%10 = getelementptr inbounds i8, i8* %2, i64 %9
%11 = load i8, i8* %10
%12 = zext i8 %11 to i32
%13 = mul i32 %12, %0
%14 = add i32 %13, %1
%15 = trunc i32 %14 to i8
%16 = getelementptr inbounds i8, i8* %3, i64 %9
store i8 %15, i8* %16
%17 = add nuw nsw i64 %9, 1
%18 = tail call i32 @strlen(i8* %2)
%19 = sext i32 %18 to i64
%20 = icmp slt i64 %17, %19
br i1 %20, label %8, label %7
}