#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 EXIT_SUCCESS;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ printf(char *, char *, char *);
int ptym_open(char *, char *, int);
int read(int, char *, int);
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  char master1[1024];
  char slave1[1024];
  char master2[1024];
  char slave2[1024];
  int fd1;
  int fd2;
  char c1, c2;
  fd1 = ptym_open(master1, slave1, 1024);
  fd2 = ptym_open(master2, slave2, 1024);
  printf("(%s) <=> (%s)\n", slave1, slave2);
  while (1) {
    if (read(fd1, &c1, 1) == 1)
      write(fd2, &c1, 1);
    usleep(20);
    if (read(fd2, &c2, 1) == 1)
      write(fd1, &c2, 1);
    usleep(20);
  };
  close(fd1);
  close(fd2);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x410(%rbp),%rdi
lea    -0x810(%rbp),%rsi
mov    $0x400,%edx
call   1060 <ptym_open@plt>
mov    %eax,-0x1014(%rbp)
lea    -0xc10(%rbp),%rdi
lea    -0x1010(%rbp),%rsi
mov    $0x400,%edx
call   1060 <ptym_open@plt>
mov    %eax,-0x1018(%rbp)
lea    -0x810(%rbp),%rsi
lea    -0x1010(%rbp),%rdx
lea    0xe4d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1014(%rbp),%edi
lea    -0x1019(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0x1,%eax
jne    11ef <main+0x9f>
mov    -0x1018(%rbp),%edi
lea    -0x1019(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    $0x14,%edi
call   1070 <usleep@plt>
mov    -0x1018(%rbp),%edi
lea    -0x101a(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0x1,%eax
jne    1230 <main+0xe0>
mov    -0x1014(%rbp),%edi
lea    -0x101a(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    $0x14,%edi
call   1070 <usleep@plt>
jmp    11b8 <main+0x68>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1018,%rsp
lea    0xc10(%rsp),%rdi
lea    0x810(%rsp),%r14
mov    %r14,%rsi
mov    $0x400,%edx
call   1060 <ptym_open@plt>
mov    %eax,%ebx
lea    0x410(%rsp),%rdi
lea    0x10(%rsp),%r15
mov    %r15,%rsi
mov    $0x400,%edx
call   1060 <ptym_open@plt>
mov    %eax,%ebp
lea    0xe61(%rip),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <printf@plt>
lea    0xf(%rsp),%r14
lea    0xe(%rsp),%r15
jmp    11ca <main+0x7a>
cs nopw 0x0(%rax,%rax,1)
mov    $0x14,%edi
call   1070 <usleep@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0x1,%eax
jne    11ed <main+0x9d>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    $0x14,%edi
call   1070 <usleep@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0x1,%eax
jne    11c0 <main+0x70>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    11c0 <main+0x70>

LLVM IR (-O0):
@.str = [15 x i8] c"(%s) <=> (%s)\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
%9 = alloca i8
store i32 0, i32* %1
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%12 = call i32 @ptym_open(i8* %10, i8* %11, i32 1024)
store i32 %12, i32* %6
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%15 = call i32 @ptym_open(i8* %13, i8* %14, i32 1024)
store i32 %15, i32* %7
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%18 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %16, i8* %17)
br label %19
19: ; preds = %0, %34
%20 = load i32, i32* %6
%21 = call i32 @read(i32 %20, i8* %8, i32 1)
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i32, i32* %7
%25 = call i32 @write(i32 %24, i8* %8, i32 1)
br label %26
26: ; preds = %23, %19
%27 = call i32 @usleep(i32 20)
%28 = load i32, i32* %7
%29 = call i32 @read(i32 %28, i8* %9, i32 1)
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = load i32, i32* %6
%33 = call i32 @write(i32 %32, i8* %9, i32 1)
br label %34
34: ; preds = %31, %26
%35 = call i32 @usleep(i32 20)
br label %19
}

LLVM IR (-O2):
@.str = [15 x i8] c"(%s) <=> (%s)\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca i8
%6 = alloca i8
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%11 = call i32 @ptym_open(i8* %7, i8* %8, i32 1024)
%12 = call i32 @ptym_open(i8* %9, i8* %10, i32 1024)
%13 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %8, i8* %10)
br label %14
14: ; preds = %25, %0
%15 = call i32 @read(i32 %11, i8* %5, i32 1)
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @write(i32 %12, i8* %5, i32 1)
br label %19
19: ; preds = %17, %14
%20 = call i32 @usleep(i32 20)
%21 = call i32 @read(i32 %12, i8* %6, i32 1)
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 @write(i32 %11, i8* %6, i32 1)
br label %25
25: ; preds = %23, %19
%26 = call i32 @usleep(i32 20)
br label %14
}