#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*/ pid_t;

/* Variables and functions */
int PATH_MAX;
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read_file(int /*<<< orphan*/, char *);
int /*<<< orphan*/ redirect_file(int /*<<< orphan*/, char const *);
scalar_t__ strcmp(char const *, char *);
scalar_t__ wait_for_open(int /*<<< orphan*/);
void process_signals(pid_t child) {
  const char *file_to_redirect = "ONE.txt";
  const char *file_to_avoid = "TWO.txt";
  while (1) {
    char orig_file[PATH_MAX];
    if (wait_for_open(child) != 0)
      break;
    read_file(child, orig_file);
    printf("[Opening %s]\n", orig_file);
    if (strcmp(file_to_avoid, orig_file) == 0)
      redirect_file(child, file_to_redirect);
  }
}


x86 assembly (clang, -O0):
<process_signals>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
lea    0xe9e(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xe9b(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e78(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <wait_for_open@plt>
cmp    $0x0,%rax
je     11bb <process_signals+0x6b>
movl   $0x3,-0x2c(%rbp)
jmp    1201 <process_signals+0xb1>
mov    -0x38(%rbp),%rsi
mov    -0x4(%rbp),%edi
call   1070 <read_file@plt>
mov    -0x38(%rbp),%rsi
lea    0xe3e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x38(%rbp),%rsi
mov    -0x18(%rbp),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11fa <process_signals+0xaa>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <redirect_file@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x2c(%rbp),%eax
test   %eax,%eax
je     121d <process_signals+0xcd>
jmp    1218 <process_signals+0xc8>
jmp    1222 <process_signals+0xd2>
jmp    1171 <process_signals+0x21>
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_signals>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r13d
mov    %rsp,%r12
mov    0x2e85(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
call   1030 <wait_for_open@plt>
test   %rax,%rax
je     1197 <process_signals+0x47>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe72(%rip),%r14
lea    0xe63(%rip),%r15
jmp    11dd <process_signals+0x8d>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rsp
mov    %rsp,%r12
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %r13d,%edi
call   1030 <wait_for_open@plt>
test   %rax,%rax
jne    1188 <process_signals+0x38>
mov    %r13d,%edi
mov    %rbx,%rsi
call   1070 <read_file@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11b0 <process_signals+0x60>
mov    %r13d,%edi
lea    0xdf3(%rip),%rsi
call   1050 <redirect_file@plt>
jmp    11b0 <process_signals+0x60>

LLVM IR (-O0):
@.str = [8 x i8] c"ONE.txt\00"
@.str.1 = [8 x i8] c"TWO.txt\00"
@PATH_MAX = global i32 0
@.str.2 = [14 x i8] c"[Opening %s]\0A\00"
define void @process_signals(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i32 %0, i32* %2
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %3
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %4
br label %8
8: ; preds = %1, %32
%9 = load i32, i32* @PATH_MAX
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %5
%12 = alloca i8, i64 %10
store i64 %10, i64* %6
%13 = load i32, i32* %2
%14 = call i64 @wait_for_open(i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %8
store i32 3, i32* %7
br label %29
17: ; preds = %8
%18 = load i32, i32* %2
%19 = call i32 @read_file(i32 %18, i8* %12)
%20 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%21 = load i8*, i8** %4
%22 = call i64 @strcmp(i8* %21, i8* %12)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %17
%25 = load i32, i32* %2
%26 = load i8*, i8** %3
%27 = call i32 @redirect_file(i32 %25, i8* %26)
br label %28
28: ; preds = %24, %17
store i32 0, i32* %7
br label %29
29: ; preds = %28, %16
%30 = load i8*, i8** %5
%31 = load i32, i32* %7
switch i32 %31, label %34 [
i32 0, label %32
i32 3, label %33
]
32: ; preds = %29
br label %8
33: ; preds = %29
ret void
34: ; preds = %29
unreachable
}

LLVM IR (-O2):
@.str = [8 x i8] c"ONE.txt\00"
@.str.1 = [8 x i8] c"TWO.txt\00"
@PATH_MAX = global i32 0
@.str.2 = [14 x i8] c"[Opening %s]\0A\00"
define void @process_signals(i32 %0) {
%2 = load i32, i32* @PATH_MAX
%3 = zext i32 %2 to i64
%4 = call i8* @llvm.stacksave()
%5 = alloca i8, i64 %3
%6 = call i64 @wait_for_open(i32 %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %24
8: ; preds = %1, %17
%9 = phi i8* [ %21, %17 ], [ %5, %1 ]
%10 = phi i8* [ %20, %17 ], [ %4, %1 ]
%11 = call i32 @read_file(i32 %0, i8* %9)
%12 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%13 = call i64 @strcmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %8
%16 = call i32 @redirect_file(i32 %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %8, %15
%18 = load i32, i32* @PATH_MAX
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
%21 = alloca i8, i64 %19
%22 = call i64 @wait_for_open(i32 %0)
%23 = icmp eq i64 %22, 0
br i1 %23, label %8, label %24
24: ; preds = %17, %1
ret void
}