#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  void *_IO_read_ptr;
  void *_IO_buf_base;
};

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, TYPE_1__ *);
int /*<<< orphan*/ memcpy(void *, char *, int);
int /*<<< orphan*/ printf(char *, char *);
TYPE_1__ *stdin;
int main() {
  while (1) {
    char x[10];
    void *ptr;
    fgets(x, 10, stdin);
    ptr = stdin->_IO_buf_base;
    memcpy(ptr, "HAHAHA", 6);
    stdin->_IO_read_ptr = ptr;
    fgets(x, 7, stdin);
    printf("%s\n", x);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xe(%rbp),%rdi
mov    0x2e9e(%rip),%rax
mov    (%rax),%rdx
mov    $0xa,%esi
call   1040 <fgets@plt>
mov    0x2e8a(%rip),%rax
mov    (%rax),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe8c(%rip),%rsi
mov    $0x6,%edx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rcx
mov    0x2e5f(%rip),%rax
mov    (%rax),%rax
mov    %rcx,(%rax)
lea    -0xe(%rbp),%rdi
mov    0x2e4e(%rip),%rax
mov    (%rax),%rdx
mov    $0x7,%esi
call   1040 <fgets@plt>
lea    -0xe(%rbp),%rsi
lea    0xe55(%rip),%rdi
call   1030 <printf@plt>
jmp    113f <main+0xf>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2ea4(%rip),%r13
lea    0x6(%rsp),%r12
lea    0xeb0(%rip),%r14
lea    0xeb0(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13),%rdx
mov    %r12,%rdi
mov    $0xa,%esi
call   1040 <fgets@plt>
mov    0x0(%r13),%rax
mov    0x8(%rax),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x6,%edx
call   1050 <memcpy@plt>
mov    0x0(%r13),%rax
mov    %rbx,(%rax)
mov    0x0(%r13),%rdx
mov    %r12,%rdi
mov    $0x7,%esi
call   1040 <fgets@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <printf@plt>
jmp    1160 <main+0x30>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i8*, i8* }
@stdin = global %struct.TYPE_3__* null
@.str = [7 x i8] c"HAHAHA\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = alloca i8*
store i32 0, i32* %1
br label %4
4: ; preds = %0, %4
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%6 = load %struct.TYPE_3__*, %struct.TYPE_3__** @stdin
%7 = call i32 @fgets(i8* %5, i32 10, %struct.TYPE_3__* %6)
%8 = load %struct.TYPE_3__*, %struct.TYPE_3__** @stdin
%9 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %8, i32 0, i32 1
%10 = load i8*, i8** %9
store i8* %10, i8** %3
%11 = load i8*, i8** %3
%12 = call i32 @memcpy(i8* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%13 = load i8*, i8** %3
%14 = load %struct.TYPE_3__*, %struct.TYPE_3__** @stdin
%15 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %14, i32 0, i32 0
store i8* %13, i8** %15
%16 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%17 = load %struct.TYPE_3__*, %struct.TYPE_3__** @stdin
%18 = call i32 @fgets(i8* %16, i32 7, %struct.TYPE_3__* %17)
%19 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %19)
br label %4
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i8*, i8* }
@stdin = global %struct.TYPE_3__* null
@.str = [7 x i8] c"HAHAHA\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %0, %3
%4 = load %struct.TYPE_3__*, %struct.TYPE_3__** @stdin
%5 = call i32 @fgets(i8* %2, i32 10, %struct.TYPE_3__* %4)
%6 = load %struct.TYPE_3__*, %struct.TYPE_3__** @stdin
%7 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i64 0, i32 1
%8 = load i8*, i8** %7
%9 = call i32 @memcpy(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%10 = load %struct.TYPE_3__*, %struct.TYPE_3__** @stdin
%11 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %10, i64 0, i32 0
store i8* %8, i8** %11
%12 = load %struct.TYPE_3__*, %struct.TYPE_3__** @stdin
%13 = call i32 @fgets(i8* %2, i32 7, %struct.TYPE_3__* %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %2)
br label %3
}