#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 getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int rand();
int /*<<< orphan*/ stdin;
int main(int arg, char **argv) {
  char *string = NULL;
  int rand_array[10];
  int i, n;
  int length = 10;
  size_t j = 0;
  printf("Enter a line: ");
  n = getline(&string, &j, stdin);
  printf("You entered the %d character line %s", n, string);
  for (i = 0; i < length; i++) {
    rand_array[i] = rand() % (length);
  }
  printf("The randomized string is \"");
  for (i = 0; i < length; i++) {
    putchar(string[rand_array[i]]);
  }
  printf("\"\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0xa,-0x4c(%rbp)
movq   $0x0,-0x58(%rbp)
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e66(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rdi
lea    -0x58(%rbp),%rsi
call   1050 <getline@plt>
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x4c(%rbp),%eax
jge    11dd <main+0x9d>
mov    $0x0,%al
call   1060 <rand@plt>
cltd
idivl  -0x4c(%rbp)
movslq -0x44(%rbp),%rax
mov    %edx,-0x40(%rbp,%rax,4)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11b0 <main+0x70>
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x4c(%rbp),%eax
jge    1222 <main+0xe2>
mov    -0x18(%rbp),%rax
movslq -0x44(%rbp),%rcx
movslq -0x40(%rbp,%rcx,4),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <putchar@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11f2 <main+0xb2>
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movq   $0x0,0x8(%rsp)
movq   $0x0,0x30(%rsp)
lea    0xe89(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e63(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rdi
lea    0x30(%rsp),%rsi
call   1060 <getline@plt>
mov    0x8(%rsp),%rdx
lea    0xe6d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%rcx
imul   $0x66666667,%rcx,%rax
mov    %rcx,%rdx
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edx
mov    %rdx,0x28(%rsp)
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%rcx
imul   $0x66666667,%rcx,%rax
mov    %rcx,%rdx
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edx
mov    %rdx,0x20(%rsp)
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%rcx
imul   $0x66666667,%rcx,%rax
mov    %rcx,%rdx
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edx
mov    %rdx,0x18(%rsp)
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%rcx
imul   $0x66666667,%rcx,%rax
mov    %rcx,%rdx
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edx
mov    %rdx,0x10(%rsp)
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%rbx
imul   $0x66666667,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebx
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%rbp
imul   $0x66666667,%rbp,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebp
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%r14
imul   $0x66666667,%r14,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%r14d
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%r15
imul   $0x66666667,%r15,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%r15d
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%r12
imul   $0x66666667,%r12,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%r12d
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%r13
imul   $0x66666667,%r13,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%r13d
lea    0xcec(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%rax
movslq 0x28(%rsp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%rax
movslq 0x20(%rsp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%rax
movslq 0x18(%rsp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%rax
movslq 0x10(%rsp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%rax
movslq %ebx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%rax
movslq %ebp,%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%rax
movslq %r14d,%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%rax
movslq %r15d,%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%rax
movslq %r12d,%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%rax
movslq %r13d,%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <putchar@plt>
lea    0xc45(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Enter a line: \00"
@stdin = global i32 0
@.str.1 = [37 x i8] c"You entered the %d character line %s\00"
@.str.2 = [27 x i8] c"The randomized string is \22\00"
@.str.3 = [3 x i8] c"\22\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [10 x i32]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i32 10, i32* %10
store i64 0, i64* %11
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @stdin
%14 = call i32 @getline(i8** %6, i64* %11, i32 %13)
store i32 %14, i32* %9
%15 = load i32, i32* %9
%16 = load i8*, i8** %6
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %15, i8* %16)
store i32 0, i32* %8
br label %18
18: ; preds = %29, %2
%19 = load i32, i32* %8
%20 = load i32, i32* %10
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %32
22: ; preds = %18
%23 = call i32 (...) @rand()
%24 = load i32, i32* %10
%25 = srem i32 %23, %24
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [10 x i32], [10 x i32]* %7, i64 0, i64 %27
store i32 %25, i32* %28
br label %29
29: ; preds = %22
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 1
store i32 %31, i32* %8
br label %18
32: ; preds = %18
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %8
br label %34
34: ; preds = %48, %32
%35 = load i32, i32* %8
%36 = load i32, i32* %10
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %51
38: ; preds = %34
%39 = load i8*, i8** %6
%40 = load i32, i32* %8
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [10 x i32], [10 x i32]* %7, i64 0, i64 %41
%43 = load i32, i32* %42
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %39, i64 %44
%46 = load i8, i8* %45
%47 = call i32 @putchar(i8 signext %46)
br label %48
48: ; preds = %38
%49 = load i32, i32* %8
%50 = add nsw i32 %49, 1
store i32 %50, i32* %8
br label %34
51: ; preds = %34
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"Enter a line: \00"
@stdin = global i32 0
@.str.1 = [37 x i8] c"You entered the %d character line %s\00"
@.str.2 = [27 x i8] c"The randomized string is \22\00"
@str = [2 x i8] c"\22\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @stdin
%9 = call i32 @getline(i8** %3, i64* %4, i32 %8)
%10 = load i8*, i8** %3
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %9, i8* %10)
%12 = call i32 (...) @rand()
%13 = srem i32 %12, 10
%14 = call i32 (...) @rand()
%15 = srem i32 %14, 10
%16 = call i32 (...) @rand()
%17 = srem i32 %16, 10
%18 = call i32 (...) @rand()
%19 = srem i32 %18, 10
%20 = call i32 (...) @rand()
%21 = srem i32 %20, 10
%22 = call i32 (...) @rand()
%23 = srem i32 %22, 10
%24 = call i32 (...) @rand()
%25 = srem i32 %24, 10
%26 = call i32 (...) @rand()
%27 = srem i32 %26, 10
%28 = call i32 (...) @rand()
%29 = srem i32 %28, 10
%30 = call i32 (...) @rand()
%31 = srem i32 %30, 10
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%33 = load i8*, i8** %3
%34 = sext i32 %13 to i64
%35 = getelementptr inbounds i8, i8* %33, i64 %34
%36 = load i8, i8* %35
%37 = call i32 @putchar(i8 signext %36)
%38 = load i8*, i8** %3
%39 = sext i32 %15 to i64
%40 = getelementptr inbounds i8, i8* %38, i64 %39
%41 = load i8, i8* %40
%42 = call i32 @putchar(i8 signext %41)
%43 = load i8*, i8** %3
%44 = sext i32 %17 to i64
%45 = getelementptr inbounds i8, i8* %43, i64 %44
%46 = load i8, i8* %45
%47 = call i32 @putchar(i8 signext %46)
%48 = load i8*, i8** %3
%49 = sext i32 %19 to i64
%50 = getelementptr inbounds i8, i8* %48, i64 %49
%51 = load i8, i8* %50
%52 = call i32 @putchar(i8 signext %51)
%53 = load i8*, i8** %3
%54 = sext i32 %21 to i64
%55 = getelementptr inbounds i8, i8* %53, i64 %54
%56 = load i8, i8* %55
%57 = call i32 @putchar(i8 signext %56)
%58 = load i8*, i8** %3
%59 = sext i32 %23 to i64
%60 = getelementptr inbounds i8, i8* %58, i64 %59
%61 = load i8, i8* %60
%62 = call i32 @putchar(i8 signext %61)
%63 = load i8*, i8** %3
%64 = sext i32 %25 to i64
%65 = getelementptr inbounds i8, i8* %63, i64 %64
%66 = load i8, i8* %65
%67 = call i32 @putchar(i8 signext %66)
%68 = load i8*, i8** %3
%69 = sext i32 %27 to i64
%70 = getelementptr inbounds i8, i8* %68, i64 %69
%71 = load i8, i8* %70
%72 = call i32 @putchar(i8 signext %71)
%73 = load i8*, i8** %3
%74 = sext i32 %29 to i64
%75 = getelementptr inbounds i8, i8* %73, i64 %74
%76 = load i8, i8* %75
%77 = call i32 @putchar(i8 signext %76)
%78 = load i8*, i8** %3
%79 = sext i32 %31 to i64
%80 = getelementptr inbounds i8, i8* %78, i64 %79
%81 = load i8, i8* %80
%82 = call i32 @putchar(i8 signext %81)
%83 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret i32 0
}