#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 /*<<< orphan*/ getpid();
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int strlen(char *);
void swap_chars_in_string(int *a, int *b, char *string) {
  srand(getpid());
  *a = rand() % strlen(string);
  *b = rand() % strlen(string);
  while (*a == *b)
    *b = rand() % strlen(string);
  char temp = string[*a];
  string[*a] = string[*b];
  string[*b] = temp;
}


x86 assembly (clang, -O0):
<swap_chars_in_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    $0x0,%al
call   1060 <rand@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cltd
idiv   %ecx
mov    -0x8(%rbp),%rax
mov    %edx,(%rax)
mov    $0x0,%al
call   1060 <rand@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cltd
idiv   %ecx
mov    -0x10(%rbp),%rax
mov    %edx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jne    11dc <swap_chars_in_string+0x9c>
mov    $0x0,%al
call   1060 <rand@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cltd
idiv   %ecx
mov    -0x10(%rbp),%rax
mov    %edx,(%rax)
jmp    11a4 <swap_chars_in_string+0x64>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq (%rcx),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x19(%rbp),%dl
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
mov    %dl,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<swap_chars_in_string>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%edi
call   1050 <srand@plt>
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
mov    %edx,(%r15)
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
mov    %edx,(%r14)
mov    (%r15),%eax
cmp    %edx,%eax
je     1180 <swap_chars_in_string+0x40>
cltq
mov    (%rbx,%rax,1),%cl
movslq %edx,%rdx
mov    (%rbx,%rdx,1),%dl
mov    %dl,(%rbx,%rax,1)
movslq (%r14),%rax
mov    %cl,(%rbx,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @swap_chars_in_string(i32* nocapture %0, i32* nocapture %1, i8* %2) {
%4 = tail call i32 (...) @getpid()
%5 = tail call i32 @srand(i32 %4)
%6 = tail call i32 (...) @rand()
%7 = tail call i32 @strlen(i8* %2)
%8 = srem i32 %6, %7
store i32 %8, i32* %0
%9 = tail call i32 (...) @rand()
%10 = tail call i32 @strlen(i8* %2)
%11 = srem i32 %9, %10
store i32 %11, i32* %1
%12 = load i32, i32* %0
%13 = icmp eq i32 %12, %11
br i1 %13, label %14, label %20
14: ; preds = %3, %14
%15 = tail call i32 (...) @rand()
%16 = tail call i32 @strlen(i8* %2)
%17 = srem i32 %15, %16
store i32 %17, i32* %1
%18 = load i32, i32* %0
%19 = icmp eq i32 %18, %17
br i1 %19, label %14, label %20
20: ; preds = %14, %3
%21 = phi i32 [ %11, %3 ], [ %17, %14 ]
%22 = phi i32 [ %12, %3 ], [ %18, %14 ]
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %2, i64 %23
%25 = load i8, i8* %24
%26 = sext i32 %21 to i64
%27 = getelementptr inbounds i8, i8* %2, i64 %26
%28 = load i8, i8* %27
store i8 %28, i8* %24
%29 = load i32, i32* %1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %2, i64 %30
store i8 %25, i8* %31
ret void
}