#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 EXIT_SUCCESS;
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  char rw[] = "this string is allocated "
              "in the stack and can be changed.";
  char *ro = "this string may be in read-only "
             "memory.";
  rw[2] = 'A';
  rw[3] = 'T';
  printf("%s\n\n", rw);
  printf("will now try to change a read-only "
         "memory location.\nsayonara.\n\n");
  ro[2] = 'A';
  ro[3] = 'T';
  printf("%s\n", ro);
  return EXIT_SUCCESS;
}


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)
lea    -0x50(%rbp),%rdi
lea    0xebf(%rip),%rsi
mov    $0x3a,%edx
call   1040 <memcpy@plt>
lea    0xee8(%rip),%rax
mov    %rax,-0x58(%rbp)
movb   $0x41,-0x4e(%rbp)
movb   $0x54,-0x4d(%rbp)
lea    -0x50(%rbp),%rsi
lea    0xef9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x58(%rbp),%rax
movb   $0x41,0x2(%rax)
mov    -0x58(%rbp),%rax
movb   $0x54,0x3(%rax)
mov    -0x58(%rbp),%rsi
lea    0xf0e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x48,%rsp
movaps 0xed5(%rip),%xmm0
movaps %xmm0,(%rsp)
movups 0xef4(%rip),%xmm0
movups %xmm0,0x2a(%rsp)
movaps 0xede(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xec2(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movw   $0x5441,0x2(%rsp)
lea    0xf01(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xef5(%rip),%rdi
call   1030 <puts@plt>
lea    0xebc(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e56(%rip),%rax
mov    (%rax),%eax
add    $0x48,%rsp
ret

LLVM IR (-O0):
@__const.main.rw = [58 x i8] c"this string is allocated in the stack and can be changed.\00"
@.str = [40 x i8] c"this string may be in read-only memory.\00"
@.str.1 = [5 x i8] c"%s\0A\0A\00"
@.str.2 = [64 x i8] c"will now try to change a read-only memory location.\0Asayonara.\0A\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [58 x i8]
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = bitcast [58 x i8]* %6 to i8*
store i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8** %7
%9 = getelementptr inbounds [58 x i8], [58 x i8]* %6, i64 0, i64 2
store i8 65, i8* %9
%10 = getelementptr inbounds [58 x i8], [58 x i8]* %6, i64 0, i64 3
store i8 84, i8* %10
%11 = getelementptr inbounds [58 x i8], [58 x i8]* %6, i64 0, i64 0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0))
%14 = load i8*, i8** %7
%15 = getelementptr inbounds i8, i8* %14, i64 2
store i8 65, i8* %15
%16 = load i8*, i8** %7
%17 = getelementptr inbounds i8, i8* %16, i64 3
store i8 84, i8* %17
%18 = load i8*, i8** %7
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_SUCCESS
ret i32 %20
}

LLVM IR (-O2):
@__const.main.rw = [58 x i8] c"this string is allocated in the stack and can be changed.\00"
@.str = [40 x i8] c"this string may be in read-only memory.\00"
@.str.1 = [5 x i8] c"%s\0A\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [63 x i8] c"will now try to change a read-only memory location.\0Asayonara.\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [58 x i8]
%4 = getelementptr inbounds [58 x i8], [58 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds [58 x i8], [58 x i8]* %3, i64 0, i64 2
store i8 65, i8* %5
%6 = getelementptr inbounds [58 x i8], [58 x i8]* %3, i64 0, i64 3
store i8 84, i8* %6
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @str, i64 0, i64 0))
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_SUCCESS
ret i32 %10
}