#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 EOF;
int /*<<< orphan*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
int O_NONBLOCK;
int /*<<< orphan*/ PR_SET_SECCOMP;
int /*<<< orphan*/ _exit(int);
int fcntl(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int fgetc(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int prctl(int /*<<< orphan*/, int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ real_init();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/);
void reimp_init(void) {
  int stdin_flags;
  int c;
  fprintf(stdout, "<<entering SECCOMP mode>>\n");
  fflush(stdout);
  fprintf(stderr, "<<entering SECCOMP mode>>\n");
  fflush(stderr);
  stdin_flags = fcntl(0, F_GETFL, 0);
  fcntl(0, F_SETFL, stdin_flags | O_NONBLOCK);
  c = fgetc(stdin);
  if (c != EOF)
    ungetc(c, stdin);
  fcntl(0, F_SETFL, stdin_flags);
  if (prctl(PR_SET_SECCOMP, 1, 0, 0) == -1)
    _exit(121);
  real_init();
}


x86 assembly (clang, -O0):
<reimp_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
lea    0xe45(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
mov    %edx,%edi
call   1050 <fcntl@plt>
mov    %eax,-0x4(%rbp)
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
mov    -0x4(%rbp),%edx
mov    0x2df2(%rip),%rax
or     (%rax),%edx
xor    %edi,%edi
call   1050 <fcntl@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
call   1060 <fgetc@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2dbe(%rip),%rcx
cmp    (%rcx),%eax
je     1233 <reimp_init+0xb3>
mov    -0x8(%rbp),%edi
mov    0x2db4(%rip),%rax
mov    (%rax),%esi
call   10a0 <ungetc@plt>
mov    0x2d7e(%rip),%rax
mov    (%rax),%esi
mov    -0x4(%rbp),%edx
xor    %edi,%edi
call   1050 <fcntl@plt>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1080 <prctl@plt>
cmp    $0xffffffff,%eax
jne    1270 <reimp_init+0xf0>
mov    $0x79,%edi
call   1040 <_exit@plt>
mov    $0x0,%al
call   1030 <real_init@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reimp_init>:
push   %r15
push   %r14
push   %rbx
mov    0x2e1c(%rip),%rbx
mov    (%rbx),%edi
lea    0xe6b(%rip),%r14
mov    %r14,%rsi
call   1070 <fprintf@plt>
mov    (%rbx),%edi
call   1090 <fflush@plt>
mov    0x2e15(%rip),%rbx
mov    (%rbx),%edi
mov    %r14,%rsi
call   1070 <fprintf@plt>
mov    (%rbx),%edi
call   1090 <fflush@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
xor    %edx,%edx
call   1050 <fcntl@plt>
mov    %eax,%ebx
mov    0x2de1(%rip),%r14
mov    (%r14),%esi
mov    0x2e07(%rip),%rax
mov    %ebx,%edx
or     (%rax),%edx
xor    %edi,%edi
call   1050 <fcntl@plt>
mov    0x2ded(%rip),%r15
mov    (%r15),%edi
call   1060 <fgetc@plt>
mov    0x2dd6(%rip),%rcx
cmp    (%rcx),%eax
je     1210 <reimp_init+0x90>
mov    (%r15),%esi
mov    %eax,%edi
call   10a0 <ungetc@plt>
mov    (%r14),%esi
xor    %edi,%edi
mov    %ebx,%edx
call   1050 <fcntl@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1080 <prctl@plt>
cmp    $0xffffffff,%eax
je     1244 <reimp_init+0xc4>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <real_init@plt>
mov    $0x79,%edi
call   1040 <_exit@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [27 x i8] c"<<entering SECCOMP mode>>\0A\00"
@stderr = global i32 0
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@stdin = global i32 0
@EOF = global i32 0
@PR_SET_SECCOMP = global i32 0
define void @reimp_init() {
%1 = alloca i32
%2 = alloca i32
%3 = load i32, i32* @stdout
%4 = call i32 @fprintf(i32 %3, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @stdout
%6 = call i32 @fflush(i32 %5)
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @stderr
%10 = call i32 @fflush(i32 %9)
%11 = load i32, i32* @F_GETFL
%12 = call i32 @fcntl(i32 0, i32 %11, i32 0)
store i32 %12, i32* %1
%13 = load i32, i32* @F_SETFL
%14 = load i32, i32* %1
%15 = load i32, i32* @O_NONBLOCK
%16 = or i32 %14, %15
%17 = call i32 @fcntl(i32 0, i32 %13, i32 %16)
%18 = load i32, i32* @stdin
%19 = call i32 @fgetc(i32 %18)
store i32 %19, i32* %2
%20 = load i32, i32* %2
%21 = load i32, i32* @EOF
%22 = icmp ne i32 %20, %21
br i1 %22, label %23, label %27
23: ; preds = %0
%24 = load i32, i32* %2
%25 = load i32, i32* @stdin
%26 = call i32 @ungetc(i32 %24, i32 %25)
br label %27
27: ; preds = %23, %0
%28 = load i32, i32* @F_SETFL
%29 = load i32, i32* %1
%30 = call i32 @fcntl(i32 0, i32 %28, i32 %29)
%31 = load i32, i32* @PR_SET_SECCOMP
%32 = call i32 @prctl(i32 %31, i32 1, i32 0, i32 0)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %36
34: ; preds = %27
%35 = call i32 @_exit(i32 121)
unreachable
36: ; preds = %27
%37 = call i32 (...) @real_init()
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [27 x i8] c"<<entering SECCOMP mode>>\0A\00"
@stderr = global i32 0
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@stdin = global i32 0
@EOF = global i32 0
@PR_SET_SECCOMP = global i32 0
define void @reimp_init() {
%1 = load i32, i32* @stdout
%2 = tail call i32 @fprintf(i32 %1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%3 = load i32, i32* @stdout
%4 = tail call i32 @fflush(i32 %3)
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @stderr
%8 = tail call i32 @fflush(i32 %7)
%9 = load i32, i32* @F_GETFL
%10 = tail call i32 @fcntl(i32 0, i32 %9, i32 0)
%11 = load i32, i32* @F_SETFL
%12 = load i32, i32* @O_NONBLOCK
%13 = or i32 %12, %10
%14 = tail call i32 @fcntl(i32 0, i32 %11, i32 %13)
%15 = load i32, i32* @stdin
%16 = tail call i32 @fgetc(i32 %15)
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %22, label %19
19: ; preds = %0
%20 = load i32, i32* @stdin
%21 = tail call i32 @ungetc(i32 %16, i32 %20)
br label %22
22: ; preds = %19, %0
%23 = load i32, i32* @F_SETFL
%24 = tail call i32 @fcntl(i32 0, i32 %23, i32 %10)
%25 = load i32, i32* @PR_SET_SECCOMP
%26 = tail call i32 @prctl(i32 %25, i32 1, i32 0, i32 0)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = tail call i32 @_exit(i32 121)
unreachable
30: ; preds = %22
%31 = tail call i32 (...) @real_init()
ret void
}