#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main(int argc, char *argv[]) {
  char s0[] = "magma";
  char *s1 = "volcano";
  char s2[100];
  char *s3;
  printf("s0: %s\n", s0);
  printf("s1: %s\n\n", s1);
  s1 = s0;
  printf("s0: %s\n", s0);
  printf("s1: %s\n\n", s1);
  s0[2] = 'n';
  s0[3] = 'g';
  s0[4] = 'o';
  printf("s0: %s\n", s0);
  printf("s1: %s\n\n", s1);
  strncpy(s2, s1, 3);
  printf("s1: %s\n", s1);
  printf("s2: %s\n\n", s2);
  s3 = (char *)malloc(sizeof(char) * (strlen(s1) + 1));
  strcpy(s3, s0);
  s0[0] = 't';
  printf("s0: %s\n", s0);
  printf("s3: %s\n\n", s3);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe91(%rip),%eax
mov    %eax,-0x16(%rbp)
mov    0xe8b(%rip),%ax
mov    %ax,-0x12(%rbp)
lea    0xe82(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    -0x16(%rbp),%rsi
lea    0xe7b(%rip),%rdi
call   1060 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xe73(%rip),%rdi
call   1060 <printf@plt>
lea    -0x16(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x16(%rbp),%rsi
lea    0xe53(%rip),%rdi
call   1060 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xe4b(%rip),%rdi
call   1060 <printf@plt>
movb   $0x6e,-0x14(%rbp)
movb   $0x67,-0x13(%rbp)
movb   $0x6f,-0x12(%rbp)
lea    -0x16(%rbp),%rsi
lea    0xe27(%rip),%rdi
call   1060 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xe1f(%rip),%rdi
call   1060 <printf@plt>
lea    -0x90(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rsi
lea    0xe03(%rip),%rdi
call   1060 <printf@plt>
lea    -0x90(%rbp),%rsi
lea    0xdf8(%rip),%rdi
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rdi
lea    -0x16(%rbp),%rsi
call   1040 <strcpy@plt>
movb   $0x74,-0x16(%rbp)
lea    -0x16(%rbp),%rsi
lea    0xd9b(%rip),%rdi
call   1060 <printf@plt>
mov    -0x98(%rbp),%rsi
lea    0xdaa(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x78,%rsp
movw   $0x61,0xc(%rsp)
movl   $0x6d67616d,0x8(%rsp)
6d
lea    0xe9d(%rip),%r14
lea    0x8(%rsp),%r12
mov    %r14,%rdi
mov    %r12,%rsi
call   1060 <printf@plt>
lea    0xe8e(%rip),%r15
lea    0xe77(%rip),%rsi
mov    %r15,%rdi
call   1060 <printf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <printf@plt>
movw   $0x676e,0xa(%rsp)
movb   $0x6f,0xc(%rsp)
mov    %r14,%rdi
mov    %r12,%rsi
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <printf@plt>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
lea    0xe34(%rip),%rdi
mov    %r12,%rsi
call   1060 <printf@plt>
lea    0xe2d(%rip),%rdi
mov    %r15,%rsi
call   1060 <printf@plt>
mov    %r12,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
movb   $0x74,0x8(%rsp)
mov    %r14,%rdi
mov    %r12,%rsi
call   1060 <printf@plt>
lea    0xdf9(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.s0 = [6 x i8] c"magma\00"
@.str = [8 x i8] c"volcano\00"
@.str.1 = [8 x i8] c"s0: %s\0A\00"
@.str.2 = [9 x i8] c"s1: %s\0A\0A\00"
@.str.3 = [8 x i8] c"s1: %s\0A\00"
@.str.4 = [9 x i8] c"s2: %s\0A\0A\00"
@.str.5 = [9 x i8] c"s3: %s\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [6 x i8]
%7 = alloca i8*
%8 = alloca [100 x i8]
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [6 x i8]* %6 to i8*
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %7
%11 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%12 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = load i8*, i8** %7
%14 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
store i8* %15, i8** %7
%16 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%17 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %7
%19 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 2
store i8 110, i8* %20
%21 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 3
store i8 103, i8* %21
%22 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 4
store i8 111, i8* %22
%23 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%24 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = load i8*, i8** %7
%26 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%28 = load i8*, i8** %7
%29 = call i32 @strncpy(i8* %27, i8* %28, i32 3)
%30 = load i8*, i8** %7
%31 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %30)
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%33 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %32)
%34 = load i8*, i8** %7
%35 = call i32 @strlen(i8* %34)
%36 = add nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = mul i64 1, %37
%39 = trunc i64 %38 to i32
%40 = call i64 @malloc(i32 %39)
%41 = inttoptr i64 %40 to i8*
store i8* %41, i8** %9
%42 = load i8*, i8** %9
%43 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%44 = call i32 @strcpy(i8* %42, i8* %43)
%45 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
store i8 116, i8* %45
%46 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%47 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %46)
%48 = load i8*, i8** %9
%49 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %48)
ret i32 0
}

LLVM IR (-O2):
@__const.main.s0 = [6 x i8] c"magma\00"
@.str = [8 x i8] c"volcano\00"
@.str.1 = [8 x i8] c"s0: %s\0A\00"
@.str.2 = [9 x i8] c"s1: %s\0A\0A\00"
@.str.3 = [8 x i8] c"s1: %s\0A\00"
@.str.4 = [9 x i8] c"s2: %s\0A\0A\00"
@.str.5 = [9 x i8] c"s3: %s\0A\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [6 x i8]
%4 = alloca [100 x i8]
%5 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%7 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%8 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%10 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%11 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 2
store i8 110, i8* %11
%12 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 3
store i8 103, i8* %12
%13 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 4
store i8 111, i8* %13
%14 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%15 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%16 = call i32 @strncpy(i8* %6, i8* %5, i32 3)
%17 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%18 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%19 = call i32 @strlen(i8* %5)
%20 = add nsw i32 %19, 1
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i8*
%23 = call i32 @strcpy(i8* %22, i8* %5)
store i8 116, i8* %5
%24 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%25 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %22)
ret i32 0
}