#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char **);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main() {
  printf("Test app\n");
  char *s;
  while (1) {
    scanf("%ms", &s);
    fprintf(stdout, "STDOUT:%s\n", s);
    fflush(stdout);
    fprintf(stderr, "STDERR:%s\n", s);
    free(s);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
lea    0xe98(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1070 <scanf@plt>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe7f(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe63(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    116b <main+0x1b>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xeb8(%rip),%rdi
call   1040 <puts@plt>
lea    0xe92(%rip),%r14
mov    %rsp,%r15
mov    0x2e60(%rip),%rbx
lea    0xe85(%rip),%r12
mov    0x2e5a(%rip),%rbp
lea    0xe82(%rip),%r13
nopl   (%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <scanf@plt>
mov    (%rbx),%edi
mov    (%rsp),%rdx
mov    %r12,%rsi
call   1050 <fprintf@plt>
mov    (%rbx),%edi
call   1060 <fflush@plt>
mov    0x0(%rbp),%edi
mov    (%rsp),%rdx
mov    %r13,%rsi
call   1050 <fprintf@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
jmp    1190 <main+0x40>

LLVM IR (-O0):
@.str = [10 x i8] c"Test app\0A\00"
@.str.1 = [4 x i8] c"%ms\00"
@stdout = global i32 0
@.str.2 = [11 x i8] c"STDOUT:%s\0A\00"
@stderr = global i32 0
@.str.3 = [11 x i8] c"STDERR:%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
store i32 0, i32* %1
%3 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %0, %4
%5 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %2)
%6 = load i32, i32* @stdout
%7 = load i8*, i8** %2
%8 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%9 = load i32, i32* @stdout
%10 = call i32 @fflush(i32 %9)
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %2
%13 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %2
%15 = call i32 @free(i8* %14)
br label %4
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"%ms\00"
@stdout = global i32 0
@.str.2 = [11 x i8] c"STDOUT:%s\0A\00"
@stderr = global i32 0
@.str.3 = [11 x i8] c"STDERR:%s\0A\00"
@str = [9 x i8] c"Test app\00"
define i32 @main() {
%1 = alloca i8*
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%3 = bitcast i8** %1 to i8*
br label %4
4: ; preds = %4, %0
%5 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %1)
%6 = load i32, i32* @stdout
%7 = load i8*, i8** %1
%8 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%9 = load i32, i32* @stdout
%10 = call i32 @fflush(i32 %9)
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %1
%13 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %1
%15 = call i32 @free(i8* %14)
br label %4
}