#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 /*<<< orphan*/ close(int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ mkfifo(char *, int);
int open_for_reading(char *);
int open_for_writing(char *);
int /*<<< orphan*/ printf(char *, char *);
int read_command(int, char *);
int /*<<< orphan*/ run_command(char *, char *);
int /*<<< orphan*/ send_response(int, char *);
int /*<<< orphan*/ unlink(char *);
int main(int argc, char *argv[]) {
  char command[1024], response[1024];
  memset(command, '\0', 1024);
  int success, in_pipe, out_pipe;
  mkfifo("/tmp/lurk_commands", 0666);
  mkfifo("/tmp/lurk_data", 0666);
  in_pipe = open_for_reading("/tmp/lurk_commands");
  out_pipe = open_for_writing("/tmp/lurk_data");
  int i = 0;
  while (1) {
    success = read_command(in_pipe, command);
    if (success) {
      run_command(command, response);
      send_response(out_pipe, response);
      printf("command: %s\n", command);
      printf("response: %s\n", response);
      success = 0;
    }
  }
  unlink("/tmp/lurk_commands");
  unlink("/tmp/lurk_data");
  close(in_pipe);
  close(out_pipe);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
lea    0xe4d(%rip),%rdi
mov    $0x1b6,%esi
call   1090 <mkfifo@plt>
lea    0xe4f(%rip),%rdi
mov    $0x1b6,%esi
call   1090 <mkfifo@plt>
lea    0xe2b(%rip),%rdi
call   1030 <open_for_reading@plt>
mov    %eax,-0x818(%rbp)
lea    0xe2c(%rip),%rdi
call   1040 <open_for_writing@plt>
mov    %eax,-0x81c(%rbp)
movl   $0x0,-0x820(%rbp)
mov    -0x818(%rbp),%edi
lea    -0x410(%rbp),%rsi
call   1050 <read_command@plt>
mov    %eax,-0x814(%rbp)
cmpl   $0x0,-0x814(%rbp)
je     1276 <main+0xf6>
lea    -0x410(%rbp),%rdi
lea    -0x810(%rbp),%rsi
call   10a0 <run_command@plt>
mov    -0x81c(%rbp),%edi
lea    -0x810(%rbp),%rsi
call   1060 <send_response@plt>
lea    -0x410(%rbp),%rsi
lea    0xdce(%rip),%rdi
call   1070 <printf@plt>
lea    -0x810(%rbp),%rsi
lea    0xdc8(%rip),%rdi
call   1070 <printf@plt>
movl   $0x0,-0x814(%rbp)
jmp    11fc <main+0x7c>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
lea    0x400(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
lea    0xe51(%rip),%rbp
mov    %rbp,%rdi
mov    $0x1b6,%esi
call   1090 <mkfifo@plt>
lea    0xe50(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1b6,%esi
call   1090 <mkfifo@plt>
mov    %rbp,%rdi
call   1030 <open_for_reading@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <open_for_writing@plt>
mov    %eax,%r14d
mov    %rsp,%rbx
lea    0xe33(%rip),%r12
lea    0xe39(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r15,%rsi
call   1050 <read_command@plt>
test   %eax,%eax
je     1200 <main+0x80>
mov    %r15,%rdi
mov    %rbx,%rsi
call   10a0 <run_command@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
call   1060 <send_response@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1070 <printf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1070 <printf@plt>
jmp    1200 <main+0x80>

LLVM IR (-O0):
@.str = [19 x i8] c"/tmp/lurk_commands\00"
@.str.1 = [15 x i8] c"/tmp/lurk_data\00"
@.str.2 = [13 x i8] c"command: %s\0A\00"
@.str.3 = [14 x i8] c"response: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%13 = call i32 @memset(i8* %12, i8 signext 0, i32 1024)
%14 = call i32 @mkfifo(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 438)
%15 = call i32 @mkfifo(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 438)
%16 = call i32 @open_for_reading(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 %16, i32* %9
%17 = call i32 @open_for_writing(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 %17, i32* %10
store i32 0, i32* %11
br label %18
18: ; preds = %2, %35
%19 = load i32, i32* %9
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%21 = call i32 @read_command(i32 %19, i8* %20)
store i32 %21, i32* %8
%22 = load i32, i32* %8
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %35
24: ; preds = %18
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%27 = call i32 @run_command(i8* %25, i8* %26)
%28 = load i32, i32* %10
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%30 = call i32 @send_response(i32 %28, i8* %29)
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%32 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%34 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %33)
store i32 0, i32* %8
br label %35
35: ; preds = %24, %18
br label %18
}

LLVM IR (-O2):
@.str = [19 x i8] c"/tmp/lurk_commands\00"
@.str.1 = [15 x i8] c"/tmp/lurk_data\00"
@.str.2 = [13 x i8] c"command: %s\0A\00"
@.str.3 = [14 x i8] c"response: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = call i32 @memset(i8* %5, i8 signext 0, i32 1024)
%8 = call i32 @mkfifo(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 438)
%9 = call i32 @mkfifo(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 438)
%10 = call i32 @open_for_reading(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @open_for_writing(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %20, %2
%13 = call i32 @read_command(i32 %10, i8* %5)
%14 = icmp eq i32 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %12
%16 = call i32 @run_command(i8* %5, i8* %6)
%17 = call i32 @send_response(i32 %11, i8* %6)
%18 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%19 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %6)
br label %20
20: ; preds = %15, %12
br label %12
}