#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*/ conf_ser(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);
  conf_ser(fd1);
  conf_ser(fd2);
  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   1070 <ptym_open@plt>
mov    %eax,-0x1014(%rbp)
lea    -0xc10(%rbp),%rdi
lea    -0x1010(%rbp),%rsi
mov    $0x400,%edx
call   1070 <ptym_open@plt>
mov    %eax,-0x1018(%rbp)
lea    -0x810(%rbp),%rsi
lea    -0x1010(%rbp),%rdx
lea    0xe3d(%rip),%rdi
call   1050 <printf@plt>
mov    -0x1014(%rbp),%edi
call   1030 <conf_ser@plt>
mov    -0x1018(%rbp),%edi
call   1030 <conf_ser@plt>
mov    -0x1014(%rbp),%edi
lea    -0x1019(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
cmp    $0x1,%eax
jne    1215 <main+0xb5>
mov    -0x1018(%rbp),%edi
lea    -0x1019(%rbp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    $0x14,%edi
call   1080 <usleep@plt>
mov    -0x1018(%rbp),%edi
lea    -0x101a(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
cmp    $0x1,%eax
jne    1256 <main+0xf6>
mov    -0x1014(%rbp),%edi
lea    -0x101a(%rbp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    $0x14,%edi
call   1080 <usleep@plt>
jmp    11de <main+0x7e>

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   1070 <ptym_open@plt>
mov    %eax,%ebx
lea    0x410(%rsp),%rdi
lea    0x10(%rsp),%r15
mov    %r15,%rsi
mov    $0x400,%edx
call   1070 <ptym_open@plt>
mov    %eax,%ebp
lea    0xe51(%rip),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <printf@plt>
mov    %ebx,%edi
call   1030 <conf_ser@plt>
mov    %ebp,%edi
call   1030 <conf_ser@plt>
lea    0xf(%rsp),%r14
lea    0xe(%rsp),%r15
jmp    11ea <main+0x8a>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x14,%edi
call   1080 <usleep@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
cmp    $0x1,%eax
jne    120d <main+0xad>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    $0x14,%edi
call   1080 <usleep@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
cmp    $0x1,%eax
jne    11e0 <main+0x80>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
jmp    11e0 <main+0x80>

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)
%19 = load i32, i32* %6
%20 = call i32 @conf_ser(i32 %19)
%21 = load i32, i32* %7
%22 = call i32 @conf_ser(i32 %21)
br label %23
23: ; preds = %0, %38
%24 = load i32, i32* %6
%25 = call i32 @read(i32 %24, i8* %8, i32 1)
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i32, i32* %7
%29 = call i32 @write(i32 %28, i8* %8, i32 1)
br label %30
30: ; preds = %27, %23
%31 = call i32 @usleep(i32 20)
%32 = load i32, i32* %7
%33 = call i32 @read(i32 %32, i8* %9, i32 1)
%34 = icmp eq i32 %33, 1
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = load i32, i32* %6
%37 = call i32 @write(i32 %36, i8* %9, i32 1)
br label %38
38: ; preds = %35, %30
%39 = call i32 @usleep(i32 20)
br label %23
}

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)
%14 = call i32 @conf_ser(i32 %11)
%15 = call i32 @conf_ser(i32 %12)
br label %16
16: ; preds = %27, %0
%17 = call i32 @read(i32 %11, i8* %5, i32 1)
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 @write(i32 %12, i8* %5, i32 1)
br label %21
21: ; preds = %19, %16
%22 = call i32 @usleep(i32 20)
%23 = call i32 @read(i32 %12, i8* %6, i32 1)
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @write(i32 %11, i8* %6, i32 1)
br label %27
27: ; preds = %25, %21
%28 = call i32 @usleep(i32 20)
br label %16
}