#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main(int argc, char *argv[]) {
  int unchangeable = 0xdeadbeef;
  char buf[100];
  fgets(buf, 100, stdin);
  printf(buf);
  fprintf(stderr, "unchangeable @ %p\n", &unchangeable);
  if (unchangeable == 0xcafebabe) {
    printf("Success!\n");
  } else {
    printf("Failure!\n");
    printf("unchangeable is %#x", unchangeable);
    exit(EXIT_FAILURE);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xdeadbeef,-0x14(%rbp)
lea    -0x80(%rbp),%rdi
mov    0x2e7d(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1040 <fgets@plt>
lea    -0x80(%rbp),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
lea    0xe6e(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <fprintf@plt>
cmpl   $0xcafebabe,-0x14(%rbp)
jne    11bb <main+0x7b>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e8 <main+0xa8>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x80,%rsp
movl   $0xdeadbeef,0xc(%rsp)
de
mov    0x2e81(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1050 <fgets@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
lea    0xe6b(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1060 <fprintf@plt>
cmpl   $0xcafebabe,0xc(%rsp)
ca
jne    11c7 <main+0x77>
lea    0xe80(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%eax
add    $0x80,%rsp
pop    %rbx
ret
lea    0xe59(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%esi
lea    0xe35(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stdin = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"unchangeable @ %p\0A\00"
@.str.1 = [10 x i8] c"Success!\0A\00"
@.str.2 = [10 x i8] c"Failure!\0A\00"
@.str.3 = [20 x i8] c"unchangeable is %#x\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [100 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -559038737, i32* %6
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%9 = load i32, i32* @stdin
%10 = call i32 @fgets(i8* %8, i32 100, i32 %9)
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%12 = call i32 (i8*, ...) @printf(i8* %11)
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32* %6)
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, -889275714
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %25
19: ; preds = %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%21 = load i32, i32* %6
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %17
%26 = load i32, i32* @EXIT_SUCCESS
ret i32 %26
}

LLVM IR (-O2):
@stdin = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"unchangeable @ %p\0A\00"
@.str.3 = [20 x i8] c"unchangeable is %#x\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
@str = [9 x i8] c"Failure!\00"
@str.4 = [9 x i8] c"Success!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca [100 x i8]
%5 = bitcast i32* %3 to i8*
store i32 -559038737, i32* %3
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* @stdin
%8 = call i32 @fgets(i8* %6, i32 100, i32 %7)
%9 = call i32 (i8*, ...) @printf(i8* %6)
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32* %3)
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, -889275714
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.4, i64 0, i64 0))
%16 = load i32, i32* @EXIT_SUCCESS
ret i32 %16
17: ; preds = %2
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%19 = load i32, i32* %3
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
}