#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 unsafe_text(int value, int vector, const char *safe_text,
                 char *text_to_unsafe) {
  int j = 0;
  do {
    j++;
  } while ((value * j) % 256 != 1);
  for (int i = 0; i < strlen(safe_text); i++) {
    text_to_unsafe[i] = (char)(j * (safe_text[i] - vector) % 256);
  }
}


x86 assembly (clang, -O0):
<unsafe_text>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
imul   -0x1c(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    112d <unsafe_text+0x1d>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    11a7 <unsafe_text+0x97>
mov    -0x1c(%rbp),%eax
mov    -0x10(%rbp),%rcx
movslq -0x20(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
sub    -0x8(%rbp),%ecx
imul   %ecx,%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1155 <unsafe_text+0x45>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unsafe_text>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r12
mov    %esi,%r15d
xor    %ebp,%ebp
mov    %edi,%eax
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebp
lea    0xff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xffffff00,%ecx
mov    %eax,%edx
sub    %ecx,%edx
add    %edi,%eax
cmp    $0x1,%edx
jne    1130 <unsafe_text+0x20>
mov    %r12,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1182 <unsafe_text+0x72>
xor    %ebx,%ebx
nopl   (%rax)
movzbl (%r12,%rbx,1),%eax
sub    %r15d,%eax
imul   %ebp,%eax
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
mov    %r12,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1160 <unsafe_text+0x50>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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