#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 *);
void libwebsockets_00_spam(char *key, int count, int seed) {
  char *p;
  key++;
  while (count--) {
    if (*key && (seed & 1))
      key++;
    seed >>= 1;
    p = key + strlen(key);
    while (p >= key) {
      p[1] = p[0];
      p--;
    }
    *key++ = 0x21 + ((seed & 0xffff) % 15);
    seed >>= 1;
  }
}


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
je     11f7 <libwebsockets_00_spam+0xe7>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     116d <libwebsockets_00_spam+0x5d>
mov    -0x10(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     116d <libwebsockets_00_spam+0x5d>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jb     11c3 <libwebsockets_00_spam+0xb3>
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1197 <libwebsockets_00_spam+0x87>
mov    -0x10(%rbp),%eax
and    $0xffff,%eax
mov    $0xf,%ecx
cltd
idiv   %ecx
add    $0x21,%edx
mov    %dl,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112e <libwebsockets_00_spam+0x1e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
je     11a1 <libwebsockets_00_spam+0x91>
mov    %edx,%r15d
mov    %esi,%r14d
mov    %rdi,%rbp
jmp    1153 <libwebsockets_00_spam+0x43>
nopw   0x0(%rax,%rax,1)
movzwl %bx,%eax
imul   $0x8889,%eax,%eax
shr    $0x13,%eax
lea    (%rax,%rax,4),%eax
lea    (%rax,%rax,2),%eax
sub    %eax,%ebx
add    $0x21,%bl
mov    %bl,0x0(%rbp)
sar    $0x2,%r15d
test   %r14d,%r14d
je     11a1 <libwebsockets_00_spam+0x91>
lea    0x1(%rbp),%rax
add    $0xffffffff,%r14d
lea    0x2(%rbp),%rcx
test   $0x1,%r15b
cmove  %rax,%rcx
cmpb   $0x0,0x1(%rbp)
mov    %rcx,%rbp
cmove  %rax,%rbp
mov    %r15d,%ebx
shr    %ebx
mov    %rbp,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
js     1130 <libwebsockets_00_spam+0x20>
mov    %eax,%eax
add    %rbp,%rax
nopl   0x0(%rax,%rax,1)
movzbl (%rax),%ecx
mov    %cl,0x1(%rax)
add    $0xffffffffffffffff,%rax
cmp    %rbp,%rax
jae    1190 <libwebsockets_00_spam+0x80>
jmp    1130 <libwebsockets_00_spam+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @libwebsockets_00_spam(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i8*, i8** %4
%9 = getelementptr inbounds i8, i8* %8, i32 1
store i8* %9, i8** %4
br label %10
10: ; preds = %46, %3
%11 = load i32, i32* %5
%12 = add nsw i32 %11, -1
store i32 %12, i32* %5
%13 = icmp ne i32 %11, 0
br i1 %13, label %14, label %56
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %14
%20 = load i32, i32* %6
%21 = and i32 %20, 1
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %4
br label %26
26: ; preds = %23, %19, %14
%27 = load i32, i32* %6
%28 = ashr i32 %27, 1
store i32 %28, i32* %6
%29 = load i8*, i8** %4
%30 = load i8*, i8** %4
%31 = call i32 @strlen(i8* %30)
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
store i8* %33, i8** %7
br label %34
34: ; preds = %38, %26
%35 = load i8*, i8** %7
%36 = load i8*, i8** %4
%37 = icmp uge i8* %35, %36
br i1 %37, label %38, label %46
38: ; preds = %34
%39 = load i8*, i8** %7
%40 = getelementptr inbounds i8, i8* %39, i64 0
%41 = load i8, i8* %40
%42 = load i8*, i8** %7
%43 = getelementptr inbounds i8, i8* %42, i64 1
store i8 %41, i8* %43
%44 = load i8*, i8** %7
%45 = getelementptr inbounds i8, i8* %44, i32 -1
store i8* %45, i8** %7
br label %34
46: ; preds = %34
%47 = load i32, i32* %6
%48 = and i32 %47, 65535
%49 = srem i32 %48, 15
%50 = add nsw i32 33, %49
%51 = trunc i32 %50 to i8
%52 = load i8*, i8** %4
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %4
store i8 %51, i8* %52
%54 = load i32, i32* %6
%55 = ashr i32 %54, 1
store i32 %55, i32* %6
br label %10
56: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @libwebsockets_00_spam(i8* %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %1, 0
br i1 %4, label %37, label %5
5: ; preds = %3, %30
%6 = phi i32 [ %10, %30 ], [ %1, %3 ]
%7 = phi i32 [ %35, %30 ], [ %2, %3 ]
%8 = phi i8* [ %17, %30 ], [ %0, %3 ]
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = add nsw i32 %6, -1
%11 = load i8, i8* %9
%12 = icmp eq i8 %11, 0
%13 = and i32 %7, 1
%14 = icmp eq i32 %13, 0
%15 = select i1 %12, i1 true, i1 %14
%16 = getelementptr inbounds i8, i8* %8, i64 2
%17 = select i1 %15, i8* %9, i8* %16
%18 = lshr i32 %7, 1
%19 = tail call i32 @strlen(i8* %17)
%20 = icmp slt i32 %19, 0
br i1 %20, label %30, label %21
21: ; preds = %5
%22 = zext i32 %19 to i64
%23 = getelementptr inbounds i8, i8* %17, i64 %22
br label %24
24: ; preds = %21, %24
%25 = phi i8* [ %28, %24 ], [ %23, %21 ]
%26 = load i8, i8* %25
%27 = getelementptr inbounds i8, i8* %25, i64 1
store i8 %26, i8* %27
%28 = getelementptr inbounds i8, i8* %25, i64 -1
%29 = icmp ult i8* %28, %17
br i1 %29, label %30, label %24
30: ; preds = %24, %5
%31 = trunc i32 %18 to i16
%32 = urem i16 %31, 15
%33 = trunc i16 %32 to i8
%34 = add nuw nsw i8 %33, 33
store i8 %34, i8* %17
%35 = ashr i32 %7, 2
%36 = icmp eq i32 %10, 0
br i1 %36, label %37, label %5
37: ; preds = %30, %3
ret void
}