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

/* Variables and functions */
int EXIT_SUCCESS;
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ conf_ser(int);
int /*<<< orphan*/ copydata(int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, char *);
int ptym_open(char *, char *, int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
scalar_t__ symlink(char *, char *);
int /*<<< orphan*/ unlink(char *);
int main(int argc, char *argv[]) {
  char master1[1024];
  char slave1[1024];
  char master2[1024];
  char slave2[1024];
  int fd1;
  int fd2;
  fd_set rfds;
  int retval;
  fd1 = ptym_open(master1, slave1, 1024);
  fd2 = ptym_open(master2, slave2, 1024);
  if (argc >= 3) {
    unlink(argv[1]);
    unlink(argv[2]);
    if (symlink(slave1, argv[1]) < 0) {
      fprintf(stderr, "Cannot create: %s\n", argv[1]);
      return 1;
    }
    if (symlink(slave2, argv[2]) < 0) {
      fprintf(stderr, "Cannot create: %s\n", argv[2]);
      return 1;
    }
    printf("(%s) <=> (%s)\n", argv[1], argv[2]);
  } else {
    printf("(%s) <=> (%s)\n", slave1, slave2);
  }
  conf_ser(fd1);
  conf_ser(fd2);
  while (1) {
    FD_ZERO(&rfds);
    FD_SET(fd1, &rfds);
    FD_SET(fd2, &rfds);
    retval = select(fd2 + 1, &rfds, NULL, NULL, NULL);
    if (retval == -1) {
      perror("select");
      return 1;
    }
    if (FD_ISSET(fd1, &rfds)) {
      copydata(fd1, fd2);
    }
    if (FD_ISSET(fd2, &rfds)) {
      copydata(fd2, fd1);
    }
  }
  close(fd1);
  close(fd2);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
lea    -0x810(%rbp),%rsi
mov    $0x400,%edx
call   10d0 <ptym_open@plt>
mov    %eax,-0x1014(%rbp)
lea    -0xc10(%rbp),%rdi
lea    -0x1010(%rbp),%rsi
mov    $0x400,%edx
call   10d0 <ptym_open@plt>
mov    %eax,-0x1018(%rbp)
cmpl   $0x3,-0x8(%rbp)
jl     12e8 <main+0x128>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <unlink@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <unlink@plt>
lea    -0x810(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1070 <symlink@plt>
cmp    $0x0,%rax
jge    1280 <main+0xc0>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd91(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13f2 <main+0x232>
lea    -0x1010(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1070 <symlink@plt>
cmp    $0x0,%rax
jge    12c7 <main+0x107>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xd4a(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13f2 <main+0x232>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xd35(%rip),%rdi
call   1060 <printf@plt>
jmp    1302 <main+0x142>
lea    -0x810(%rbp),%rsi
lea    -0x1010(%rbp),%rdx
lea    0xd16(%rip),%rdi
call   1060 <printf@plt>
mov    -0x1014(%rbp),%edi
call   1040 <conf_ser@plt>
mov    -0x1018(%rbp),%edi
call   1040 <conf_ser@plt>
lea    -0x101c(%rbp),%rdi
call   10a0 <FD_ZERO@plt>
mov    -0x1014(%rbp),%edi
lea    -0x101c(%rbp),%rsi
call   10e0 <FD_SET@plt>
mov    -0x1018(%rbp),%edi
lea    -0x101c(%rbp),%rsi
call   10e0 <FD_SET@plt>
mov    -0x1018(%rbp),%edi
add    $0x1,%edi
lea    -0x101c(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   10b0 <select@plt>
mov    %eax,-0x1020(%rbp)
cmpl   $0xffffffff,-0x1020(%rbp)
jne    1393 <main+0x1d3>
lea    0xca0(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13f2 <main+0x232>
mov    -0x1014(%rbp),%edi
lea    -0x101c(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     13c0 <main+0x200>
mov    -0x1014(%rbp),%edi
mov    -0x1018(%rbp),%esi
call   1090 <copydata@plt>
mov    -0x1018(%rbp),%edi
lea    -0x101c(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     13ed <main+0x22d>
mov    -0x1018(%rbp),%edi
mov    -0x1014(%rbp),%esi
call   1090 <copydata@plt>
jmp    1318 <main+0x158>
mov    -0x4(%rbp),%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1018,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
lea    0xc10(%rsp),%rdi
lea    0x410(%rsp),%rsi
mov    $0x400,%edx
call   10d0 <ptym_open@plt>
mov    %eax,%r15d
lea    0x810(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    $0x400,%edx
call   10d0 <ptym_open@plt>
mov    %eax,%ebp
cmp    $0x3,%ebx
jl     1283 <main+0xc3>
mov    0x8(%r14),%rdi
call   1030 <unlink@plt>
mov    0x10(%r14),%rdi
call   1030 <unlink@plt>
mov    0x8(%r14),%rsi
lea    0x410(%rsp),%rdi
call   1070 <symlink@plt>
test   %rax,%rax
js     1257 <main+0x97>
mov    0x10(%r14),%rsi
lea    0x10(%rsp),%rdi
call   1070 <symlink@plt>
test   %rax,%rax
jns    1299 <main+0xd9>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
mov    0x10(%r14),%rdx
jmp    1264 <main+0xa4>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xd95(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%eax
add    $0x1018,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd89(%rip),%rdi
lea    0x410(%rsp),%rsi
lea    0x10(%rsp),%rdx
jmp    12a8 <main+0xe8>
mov    0x8(%r14),%rsi
mov    0x10(%r14),%rdx
lea    0xd6b(%rip),%rdi
call   1060 <printf@plt>
mov    %r15d,%edi
call   1040 <conf_ser@plt>
mov    %ebp,%edi
call   1040 <conf_ser@plt>
mov    %ebp,%r14d
add    $0x1,%r14d
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   10a0 <FD_ZERO@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
call   10e0 <FD_SET@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   10e0 <FD_SET@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10b0 <select@plt>
cmp    $0xffffffff,%eax
jne    130d <main+0x14d>
lea    0xd1f(%rip),%rdi
call   10c0 <perror@plt>
jmp    1270 <main+0xb0>
lea    0xc(%rsp),%rbx
jmp    1354 <main+0x194>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   10a0 <FD_ZERO@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
call   10e0 <FD_SET@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   10e0 <FD_SET@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10b0 <select@plt>
cmp    $0xffffffff,%eax
je     12fc <main+0x13c>
mov    %r15d,%edi
mov    %rbx,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     136e <main+0x1ae>
mov    %r15d,%edi
mov    %ebp,%esi
call   1090 <copydata@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     1320 <main+0x160>
mov    %ebp,%edi
mov    %r15d,%esi
call   1090 <copydata@plt>
jmp    1320 <main+0x160>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [19 x i8] c"Cannot create: %s\0A\00"
@.str.1 = [15 x i8] c"(%s) <=> (%s)\0A\00"
@.str.2 = [7 x i8] c"select\00"
@EXIT_SUCCESS = global i32 0
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 [1024 x i8]
%9 = alloca [1024 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%16 = call i32 @ptym_open(i8* %14, i8* %15, i32 1024)
store i32 %16, i32* %10
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%19 = call i32 @ptym_open(i8* %17, i8* %18, i32 1024)
store i32 %19, i32* %11
%20 = load i32, i32* %4
%21 = icmp sge i32 %20, 3
br i1 %21, label %22, label %64
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @unlink(i8* %25)
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32 @unlink(i8* %29)
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i64 @symlink(i8* %31, i8* %34)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %43
37: ; preds = %22
%38 = load i32, i32* @stderr
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %41)
store i32 1, i32* %3
br label %103
43: ; preds = %22
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 2
%47 = load i8*, i8** %46
%48 = call i64 @symlink(i8* %44, i8* %47)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %56
50: ; preds = %43
%51 = load i32, i32* @stderr
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 2
%54 = load i8*, i8** %53
%55 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %54)
store i32 1, i32* %3
br label %103
56: ; preds = %43
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 1
%59 = load i8*, i8** %58
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 2
%62 = load i8*, i8** %61
%63 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %59, i8* %62)
br label %68
64: ; preds = %2
%65 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%66 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%67 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %65, i8* %66)
br label %68
68: ; preds = %64, %56
%69 = load i32, i32* %10
%70 = call i32 @conf_ser(i32 %69)
%71 = load i32, i32* %11
%72 = call i32 @conf_ser(i32 %71)
br label %73
73: ; preds = %68, %102
%74 = call i32 @FD_ZERO(i32* %12)
%75 = load i32, i32* %10
%76 = call i32 @FD_SET(i32 %75, i32* %12)
%77 = load i32, i32* %11
%78 = call i32 @FD_SET(i32 %77, i32* %12)
%79 = load i32, i32* %11
%80 = add nsw i32 %79, 1
%81 = call i32 @select(i32 %80, i32* %12, i32* null, i32* null, i32* null)
store i32 %81, i32* %13
%82 = load i32, i32* %13
%83 = icmp eq i32 %82, -1
br i1 %83, label %84, label %86
84: ; preds = %73
%85 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %103
86: ; preds = %73
%87 = load i32, i32* %10
%88 = call i64 @FD_ISSET(i32 %87, i32* %12)
%89 = icmp ne i64 %88, 0
br i1 %89, label %90, label %94
90: ; preds = %86
%91 = load i32, i32* %10
%92 = load i32, i32* %11
%93 = call i32 @copydata(i32 %91, i32 %92)
br label %94
94: ; preds = %90, %86
%95 = load i32, i32* %11
%96 = call i64 @FD_ISSET(i32 %95, i32* %12)
%97 = icmp ne i64 %96, 0
br i1 %97, label %98, label %102
98: ; preds = %94
%99 = load i32, i32* %11
%100 = load i32, i32* %10
%101 = call i32 @copydata(i32 %99, i32 %100)
br label %102
102: ; preds = %98, %94
br label %73
103: ; preds = %84, %50, %37
%104 = load i32, i32* %3
ret i32 %104
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [19 x i8] c"Cannot create: %s\0A\00"
@.str.1 = [15 x i8] c"(%s) <=> (%s)\0A\00"
@.str.2 = [7 x i8] c"select\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = alloca i32
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%12 = bitcast i32* %7 to i8*
%13 = call i32 @ptym_open(i8* %8, i8* %9, i32 1024)
%14 = call i32 @ptym_open(i8* %10, i8* %11, i32 1024)
%15 = icmp sgt i32 %0, 2
br i1 %15, label %16, label %42
16: ; preds = %2
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @unlink(i8* %18)
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = call i32 @unlink(i8* %21)
%23 = load i8*, i8** %17
%24 = call i64 @symlink(i8* %9, i8* %23)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %16
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %17
%29 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %28)
br label %71
30: ; preds = %16
%31 = load i8*, i8** %20
%32 = call i64 @symlink(i8* %11, i8* %31)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %30
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %20
%37 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %36)
br label %71
38: ; preds = %30
%39 = load i8*, i8** %17
%40 = load i8*, i8** %20
%41 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %39, i8* %40)
br label %44
42: ; preds = %2
%43 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %9, i8* %11)
br label %44
44: ; preds = %42, %38
%45 = call i32 @conf_ser(i32 %13)
%46 = call i32 @conf_ser(i32 %14)
%47 = add nsw i32 %14, 1
%48 = call i32 @FD_ZERO(i32* %7)
%49 = call i32 @FD_SET(i32 %13, i32* %7)
%50 = call i32 @FD_SET(i32 %14, i32* %7)
%51 = call i32 @select(i32 %47, i32* %7, i32* null, i32* null, i32* null)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %55
53: ; preds = %65, %44
%54 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %71
55: ; preds = %44, %65
%56 = call i64 @FD_ISSET(i32 %13, i32* %7)
%57 = icmp eq i64 %56, 0
br i1 %57, label %60, label %58
58: ; preds = %55
%59 = call i32 @copydata(i32 %13, i32 %14)
br label %60
60: ; preds = %58, %55
%61 = call i64 @FD_ISSET(i32 %14, i32* %7)
%62 = icmp eq i64 %61, 0
br i1 %62, label %65, label %63
63: ; preds = %60
%64 = call i32 @copydata(i32 %14, i32 %13)
br label %65
65: ; preds = %63, %60
%66 = call i32 @FD_ZERO(i32* %7)
%67 = call i32 @FD_SET(i32 %13, i32* %7)
%68 = call i32 @FD_SET(i32 %14, i32* %7)
%69 = call i32 @select(i32 %47, i32* %7, i32* null, i32* null, i32* null)
%70 = icmp eq i32 %69, -1
br i1 %70, label %53, label %55
71: ; preds = %53, %34, %26
ret i32 1
}