#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ stdout;
int proc(void *dummy) {
  char line[1024];
  int n = 1024;
  char *fgets(char *s, int size, FILE *stream);
  while (fgets(line, n, stdin)) {
    fprintf(stdout, "%s", line);
    fprintf(stdout, "xx = %s", line);
  }
}


x86 assembly (clang, -O0):
<proc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x400,-0x414(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x414(%rbp),%esi
mov    0x2e9b(%rip),%rax
mov    (%rax),%rdx
call   1030 <fgets@plt>
cmp    $0x0,%rax
je     119c <proc+0x7c>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rdx
lea    0xe8f(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rdx
lea    0xe6e(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1139 <proc+0x19>
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<proc>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    0x2eb1(%rip),%r12
mov    (%r12),%rdx
mov    %rsp,%rdi
mov    $0x400,%esi
call   1030 <fgets@plt>
test   %rax,%rax
je     11a4 <proc+0x84>
mov    0x2e84(%rip),%r13
lea    0xeaa(%rip),%r14
mov    %rsp,%rbx
lea    0xe9b(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x0(%r13),%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    0x0(%r13),%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    (%r12),%rdx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1030 <fgets@plt>
test   %rax,%rax
jne    1170 <proc+0x50>
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32* null
@stdout = global i32 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [8 x i8] c"xx = %s\00"
define i32 @proc(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [1024 x i8]
%5 = alloca i32
store i8* %0, i8** %3
store i32 1024, i32* %5
br label %6
6: ; preds = %12, %1
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = load i32, i32* %5
%9 = load i32*, i32** @stdin
%10 = call i8* @fgets(i8* %7, i32 %8, i32* %9)
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %19
12: ; preds = %6
%13 = load i32, i32* @stdout
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @stdout
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %6
19: ; preds = %6
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
@stdin = global i32* null
@stdout = global i32 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [8 x i8] c"xx = %s\00"
define i32 @proc(i8* nocapture readnone %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = load i32*, i32** @stdin
%5 = call i8* @fgets(i8* %3, i32 1024, i32* %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %15, label %7
7: ; preds = %1, %7
%8 = load i32, i32* @stdout
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
%10 = load i32, i32* @stdout
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%12 = load i32*, i32** @stdin
%13 = call i8* @fgets(i8* %3, i32 1024, i32* %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %7
15: ; preds = %7, %1
ret i32 undef
}