#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*/ O_WRONLY;
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int dup(int /*<<< orphan*/);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ scanf(char *, int *);
int square(int);
int main(int argc, char *argv[]) {
  int n;
  int realStdoutNo = dup(STDOUT_FILENO);
  FILE *realStdout = fdopen(realStdoutNo, "w");
  int devNull = open("/dev/null", O_WRONLY);
  dup2(devNull, STDOUT_FILENO);
  dup2(devNull, STDERR_FILENO);
  scanf("%d", &n);
  fprintf(realStdout, "[%d]\n", square(n));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
call   1050 <dup@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
lea    0xe5f(%rip),%rsi
call   1070 <fdopen@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
lea    0xe48(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
mov    -0x24(%rbp),%edi
mov    0x2dfb(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
lea    0xe21(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1080 <scanf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <square@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%edx
lea    0xdfe(%rip),%rsi
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e71(%rip),%r14
mov    (%r14),%edi
call   1050 <dup@plt>
lea    0xe72(%rip),%rsi
mov    %eax,%edi
call   1070 <fdopen@plt>
mov    %rax,%rbx
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
lea    0xe5a(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%ebp
mov    (%r14),%esi
mov    %eax,%edi
call   1040 <dup2@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1040 <dup2@plt>
lea    0xe3c(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1080 <scanf@plt>
mov    0xc(%rsp),%edi
call   1030 <square@plt>
lea    0xe25(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@STDOUT_FILENO = global i32 0
@.str = [2 x i8] c"w\00"
@.str.1 = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
@STDERR_FILENO = global i32 0
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [6 x i8] c"[%d]\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @STDOUT_FILENO
%11 = call i32 @dup(i32 %10)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = call i32* @fdopen(i32 %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %8
%14 = load i32, i32* @O_WRONLY
%15 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %14)
store i32 %15, i32* %9
%16 = load i32, i32* %9
%17 = load i32, i32* @STDOUT_FILENO
%18 = call i32 @dup2(i32 %16, i32 %17)
%19 = load i32, i32* %9
%20 = load i32, i32* @STDERR_FILENO
%21 = call i32 @dup2(i32 %19, i32 %20)
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%23 = load i32*, i32** %8
%24 = load i32, i32* %6
%25 = call i32 @square(i32 %24)
%26 = call i32 @fprintf(i32* %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %25)
ret i32 0
}

LLVM IR (-O2):
@STDOUT_FILENO = global i32 0
@.str = [2 x i8] c"w\00"
@.str.1 = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
@STDERR_FILENO = global i32 0
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [6 x i8] c"[%d]\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = load i32, i32* @STDOUT_FILENO
%6 = tail call i32 @dup(i32 %5)
%7 = tail call i32* @fdopen(i32 %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @O_WRONLY
%9 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = load i32, i32* @STDOUT_FILENO
%11 = tail call i32 @dup2(i32 %9, i32 %10)
%12 = load i32, i32* @STDERR_FILENO
%13 = tail call i32 @dup2(i32 %9, i32 %12)
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%15 = load i32, i32* %3
%16 = call i32 @square(i32 %15)
%17 = call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %16)
ret i32 0
}