#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 EOF;
int /*<<< orphan*/ close(int);
int dup(int /*<<< orphan*/);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/);
int /*<<< orphan*/ fdopen(int /*<<< orphan*/, char *);
int /*<<< orphan*/ *freopen(char *, char *, int /*<<< orphan*/);
int getchar();
int /*<<< orphan*/ putchar(int);
int /*<<< orphan*/ stdin;
int main() {
  int c;
  int oldStdin = dup(0);
  FILE *file = freopen(
      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
      "2022-01-22/02-19-57/repos/smarr/Truffle/refs/heads/debugger/"
      "truffle-update/sulong/tests/com.oracle.truffle.llvm.tests.libc.native/"
      "libc/getchar/getchar.c",
      "r", stdin);
  while ((c = getchar()) != EOF) {
    putchar(c);
  }
  fclose(stdin);
  dup2(oldStdin, 0);
  close(oldStdin);
  stdin = fdopen(0, "r");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1060 <dup@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e48(%rip),%rax
mov    (%rax),%edx
lea    0xe57(%rip),%rdi
lea    0xf29(%rip),%rsi
call   1070 <freopen@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1090 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e16(%rip),%rcx
cmp    (%rcx),%eax
je     11df <main+0x5f>
mov    -0x8(%rbp),%edi
call   1030 <putchar@plt>
jmp    11b9 <main+0x39>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   1040 <fclose@plt>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
call   1050 <dup2@plt>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
xor    %edi,%edi
lea    0xed1(%rip),%rsi
call   10a0 <fdopen@plt>
mov    %eax,%ecx
mov    0x2dd2(%rip),%rax
mov    %ecx,(%rax)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %edi,%edi
call   1060 <dup@plt>
mov    %eax,%ebp
mov    0x2e54(%rip),%r14
mov    (%r14),%edx
lea    0xe62(%rip),%rdi
lea    0xf34(%rip),%rsi
call   1070 <freopen@plt>
xor    %eax,%eax
call   1090 <getchar@plt>
mov    0x2e28(%rip),%rbx
cmp    (%rbx),%eax
je     11d2 <main+0x52>
nopl   0x0(%rax)
mov    %eax,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1090 <getchar@plt>
cmp    (%rbx),%eax
jne    11c0 <main+0x40>
mov    (%r14),%edi
call   1040 <fclose@plt>
mov    %ebp,%edi
xor    %esi,%esi
call   1050 <dup2@plt>
mov    %ebp,%edi
call   1080 <close@plt>
lea    0xee8(%rip),%rsi
xor    %edi,%edi
call   10a0 <fdopen@plt>
mov    %eax,(%r14)
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [217 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/smarr/Truffle/refs/heads/debugger/truffle-update/sulong/tests/com.oracle.truffle.llvm.tests.libc.native/libc/getchar/getchar.c\00"
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32 0
@EOF = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
store i32 0, i32* %1
%5 = call i32 @dup(i32 0)
store i32 %5, i32* %3
%6 = load i32, i32* @stdin
%7 = call i32* @freopen(i8* getelementptr inbounds ([217 x i8], [217 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %6)
store i32* %7, i32** %4
br label %8
8: ; preds = %12, %0
%9 = call i32 (...) @getchar()
store i32 %9, i32* %2
%10 = load i32, i32* @EOF
%11 = icmp ne i32 %9, %10
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i32, i32* %2
%14 = call i32 @putchar(i32 %13)
br label %8
15: ; preds = %8
%16 = load i32, i32* @stdin
%17 = call i32 @fclose(i32 %16)
%18 = load i32, i32* %3
%19 = call i32 @dup2(i32 %18, i32 0)
%20 = load i32, i32* %3
%21 = call i32 @close(i32 %20)
%22 = call i32 @fdopen(i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 %22, i32* @stdin
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@.str = [217 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/smarr/Truffle/refs/heads/debugger/truffle-update/sulong/tests/com.oracle.truffle.llvm.tests.libc.native/libc/getchar/getchar.c\00"
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32 0
@EOF = global i32 0
define i32 @main() {
%1 = tail call i32 @dup(i32 0)
%2 = load i32, i32* @stdin
%3 = tail call i32* @freopen(i8* getelementptr inbounds ([217 x i8], [217 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%4 = tail call i32 (...) @getchar()
%5 = load i32, i32* @EOF
%6 = icmp eq i32 %4, %5
br i1 %6, label %13, label %7
7: ; preds = %0, %7
%8 = phi i32 [ %10, %7 ], [ %4, %0 ]
%9 = tail call i32 @putchar(i32 %8)
%10 = tail call i32 (...) @getchar()
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %7
13: ; preds = %7, %0
%14 = load i32, i32* @stdin
%15 = tail call i32 @fclose(i32 %14)
%16 = tail call i32 @dup2(i32 %1, i32 0)
%17 = tail call i32 @close(i32 %1)
%18 = tail call i32 @fdopen(i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 %18, i32* @stdin
ret i32 0
}