#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int main(void) {
  char *word;
  word = (char *)malloc(50);
  char *ptr;
  if (word == NULL) {
    printf("ERROR: There is insufficient memory to run program\n");
    return 2;
  }
  printf("Please Enter a Word:\n");
  fgets(word, 50, stdin);
  printf("You entered:\n%s\n", word);
  ptr = &word[1];
  ptr[1] = '_';
  ptr[3] = '$';
  printf("Your word has been changed by ptr to:\n%s\n", word);
  free(word);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x32,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1182 <main+0x42>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    11f7 <main+0xb7>
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e4d(%rip),%rax
mov    (%rax),%edx
mov    $0x32,%esi
call   1050 <fgets@plt>
mov    -0x10(%rbp),%rsi
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x5f,0x1(%rax)
mov    -0x18(%rbp),%rax
movb   $0x24,0x3(%rax)
mov    -0x10(%rbp),%rsi
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x32,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     11bd <main+0x6d>
mov    %rax,%rbx
lea    0xecf(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e70(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x32,%esi
call   1060 <fgets@plt>
lea    0xe72(%rip),%rdi
xor    %ebp,%ebp
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
movb   $0x5f,0x2(%rbx)
movb   $0x24,0x4(%rbx)
lea    0xe68(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    11ce <main+0x7e>
lea    0xe8c(%rip),%rdi
call   1040 <puts@plt>
mov    $0x2,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [52 x i8] c"ERROR: There is insufficient memory to run program\0A\00"
@.str.1 = [22 x i8] c"Please Enter a Word:\0A\00"
@stdin = global i32 0
@.str.2 = [17 x i8] c"You entered:\0A%s\0A\00"
@.str.3 = [42 x i8] c"Your word has been changed by ptr to:\0A%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
store i32 0, i32* %1
%4 = call i64 @malloc(i32 50)
%5 = inttoptr i64 %4 to i8*
store i8* %5, i8** %2
%6 = load i8*, i8** %2
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %1
br label %27
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%12 = load i8*, i8** %2
%13 = load i32, i32* @stdin
%14 = call i32 @fgets(i8* %12, i32 50, i32 %13)
%15 = load i8*, i8** %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = load i8*, i8** %2
%18 = getelementptr inbounds i8, i8* %17, i64 1
store i8* %18, i8** %3
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i64 1
store i8 95, i8* %20
%21 = load i8*, i8** %3
%22 = getelementptr inbounds i8, i8* %21, i64 3
store i8 36, i8* %22
%23 = load i8*, i8** %2
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i8* %23)
%25 = load i8*, i8** %2
%26 = call i32 @free(i8* %25)
store i32 0, i32* %1
br label %27
27: ; preds = %10, %8
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@stdin = global i32 0
@.str.2 = [17 x i8] c"You entered:\0A%s\0A\00"
@.str.3 = [42 x i8] c"Your word has been changed by ptr to:\0A%s\0A\00"
@str = [21 x i8] c"Please Enter a Word:\00"
@str.4 = [51 x i8] c"ERROR: There is insufficient memory to run program\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 50)
%2 = inttoptr i64 %1 to i8*
%3 = icmp eq i64 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.4, i64 0, i64 0))
br label %15
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%8 = load i32, i32* @stdin
%9 = tail call i32 @fgets(i8* %2, i32 50, i32 %8)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%11 = getelementptr inbounds i8, i8* %2, i64 2
store i8 95, i8* %11
%12 = getelementptr inbounds i8, i8* %2, i64 4
store i8 36, i8* %12
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%14 = tail call i32 @free(i8* %2)
br label %15
15: ; preds = %6, %4
%16 = phi i32 [ 2, %4 ], [ 0, %6 ]
ret i32 %16
}