#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*/ O_RDWR;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int alloc_pty_pair(char *pty_master, char *pty_slave) {
  int master_fd;
  char *ptr1, *ptr2;
  strcpy(pty_master, "/dev/ptyXY");
  for (ptr1 = "pq"; *ptr1 != 0; ptr1++) {
    pty_master[8] = *ptr1;
    for (ptr2 = "0123456789abcdef"; *ptr2 != 0; ptr2++) {
      pty_master[9] = *ptr2;
      if ((master_fd = open(pty_master, O_RDWR)) >= 0) {
        strcpy(pty_slave, pty_master);
        pty_slave[5] = 't';
        return master_fd;
      }
    }
  }
  fprintf(stderr, "ERROR: couldn't open pseudo-terminal.\n");
  exit(1);
  return -1;
}


x86 assembly (clang, -O0):
<alloc_pty_pair>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1030 <strcpy@plt>
lea    0xea4(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1218 <alloc_pty_pair+0xd8>
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x8(%rax)
lea    0xe7f(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1202 <alloc_pty_pair+0xc2>
mov    -0x28(%rbp),%rax
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x9(%rax)
mov    -0x8(%rbp),%rdi
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jl     11ec <alloc_pty_pair+0xac>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
movb   $0x74,0x5(%rax)
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret
jmp    11f1 <alloc_pty_pair+0xb1>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1193 <alloc_pty_pair+0x53>
jmp    1207 <alloc_pty_pair+0xc7>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    116b <alloc_pty_pair+0x2b>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
lea    0xdf7(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<alloc_pty_pair>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xea8(%rip),%rsi
call   1030 <strcpy@plt>
mov    $0x70,%al
xor    %r15d,%r15d
mov    0x2e7f(%rip),%r12
lea    0xe9b(%rip),%r13
mov    %al,0x8(%rbx)
movb   $0x30,0x9(%rbx)
mov    (%r12),%esi
mov    %rbx,%rdi
call   1050 <open@plt>
test   %eax,%eax
jns    1316 <alloc_pty_pair+0x1d6>
movb   $0x31,0x9(%rbx)
mov    (%r12),%esi
mov    %rbx,%rdi
call   1050 <open@plt>
test   %eax,%eax
jns    1316 <alloc_pty_pair+0x1d6>
movb   $0x32,0x9(%rbx)
mov    (%r12),%esi
mov    %rbx,%rdi
call   1050 <open@plt>
test   %eax,%eax
jns    1316 <alloc_pty_pair+0x1d6>
movb   $0x33,0x9(%rbx)
mov    (%r12),%esi
mov    %rbx,%rdi
call   1050 <open@plt>
test   %eax,%eax
jns    1316 <alloc_pty_pair+0x1d6>
movb   $0x34,0x9(%rbx)
mov    (%r12),%esi
mov    %rbx,%rdi
call   1050 <open@plt>
test   %eax,%eax
jns    1316 <alloc_pty_pair+0x1d6>
movb   $0x35,0x9(%rbx)
mov    (%r12),%esi
mov    %rbx,%rdi
call   1050 <open@plt>
test   %eax,%eax
jns    1316 <alloc_pty_pair+0x1d6>
movb   $0x36,0x9(%rbx)
mov    (%r12),%esi
mov    %rbx,%rdi
call   1050 <open@plt>
test   %eax,%eax
jns    1316 <alloc_pty_pair+0x1d6>
movb   $0x37,0x9(%rbx)
mov    (%r12),%esi
mov    %rbx,%rdi
call   1050 <open@plt>
test   %eax,%eax
jns    1316 <alloc_pty_pair+0x1d6>
movb   $0x38,0x9(%rbx)
mov    (%r12),%esi
mov    %rbx,%rdi
call   1050 <open@plt>
test   %eax,%eax
jns    1316 <alloc_pty_pair+0x1d6>
movb   $0x39,0x9(%rbx)
mov    (%r12),%esi
mov    %rbx,%rdi
call   1050 <open@plt>
test   %eax,%eax
jns    1316 <alloc_pty_pair+0x1d6>
movb   $0x61,0x9(%rbx)
mov    (%r12),%esi
mov    %rbx,%rdi
call   1050 <open@plt>
test   %eax,%eax
jns    1316 <alloc_pty_pair+0x1d6>
movb   $0x62,0x9(%rbx)
mov    (%r12),%esi
mov    %rbx,%rdi
call   1050 <open@plt>
test   %eax,%eax
jns    1316 <alloc_pty_pair+0x1d6>
movb   $0x63,0x9(%rbx)
mov    (%r12),%esi
mov    %rbx,%rdi
call   1050 <open@plt>
test   %eax,%eax
jns    1316 <alloc_pty_pair+0x1d6>
movb   $0x64,0x9(%rbx)
mov    (%r12),%esi
mov    %rbx,%rdi
call   1050 <open@plt>
test   %eax,%eax
jns    1316 <alloc_pty_pair+0x1d6>
movb   $0x65,0x9(%rbx)
mov    (%r12),%esi
mov    %rbx,%rdi
call   1050 <open@plt>
test   %eax,%eax
jns    1316 <alloc_pty_pair+0x1d6>
movb   $0x66,0x9(%rbx)
mov    (%r12),%esi
mov    %rbx,%rdi
call   1050 <open@plt>
test   %eax,%eax
jns    1316 <alloc_pty_pair+0x1d6>
movzbl 0x1(%r15,%r13,1),%eax
add    $0x1,%r15
cmp    $0x2,%r15
jne    1170 <alloc_pty_pair+0x30>
mov    0x2cda(%rip),%rax
mov    (%rax),%edi
lea    0xd07(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
movb   $0x74,0x5(%r14)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/ptyXY\00"
@.str.1 = [3 x i8] c"pq\00"
@.str.2 = [17 x i8] c"0123456789abcdef\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.3 = [39 x i8] c"ERROR: couldn't open pseudo-terminal.\0A\00"
define i32 @alloc_pty_pair(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %6
br label %10
10: ; preds = %46, %2
%11 = load i8*, i8** %6
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %49
15: ; preds = %10
%16 = load i8*, i8** %6
%17 = load i8, i8* %16
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i64 8
store i8 %17, i8* %19
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8** %7
br label %20
20: ; preds = %42, %15
%21 = load i8*, i8** %7
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %45
25: ; preds = %20
%26 = load i8*, i8** %7
%27 = load i8, i8* %26
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i64 9
store i8 %27, i8* %29
%30 = load i8*, i8** %3
%31 = load i32, i32* @O_RDWR
%32 = call i32 @open(i8* %30, i32 %31)
store i32 %32, i32* %5
%33 = icmp sge i32 %32, 0
br i1 %33, label %34, label %41
34: ; preds = %25
%35 = load i8*, i8** %4
%36 = load i8*, i8** %3
%37 = call i32 @strcpy(i8* %35, i8* %36)
%38 = load i8*, i8** %4
%39 = getelementptr inbounds i8, i8* %38, i64 5
store i8 116, i8* %39
%40 = load i32, i32* %5
ret i32 %40
41: ; preds = %25
br label %42
42: ; preds = %41
%43 = load i8*, i8** %7
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %7
br label %20
45: ; preds = %20
br label %46
46: ; preds = %45
%47 = load i8*, i8** %6
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %6
br label %10
49: ; preds = %10
%50 = load i32, i32* @stderr
%51 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
%52 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/ptyXY\00"
@.str.1 = [3 x i8] c"pq\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.3 = [39 x i8] c"ERROR: couldn't open pseudo-terminal.\0A\00"
define i32 @alloc_pty_pair(i8* %0, i8* %1) {
%3 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds i8, i8* %0, i64 8
%5 = getelementptr inbounds i8, i8* %0, i64 9
br label %6
6: ; preds = %2, %72
%7 = phi i8 [ 112, %2 ], [ %74, %72 ]
%8 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %2 ], [ %73, %72 ]
store i8 %7, i8* %4
store i8 48, i8* %5
%9 = load i32, i32* @O_RDWR
%10 = tail call i32 @open(i8* %0, i32 %9)
%11 = icmp sgt i32 %10, -1
br i1 %11, label %76, label %12
12: ; preds = %6
store i8 49, i8* %5
%13 = load i32, i32* @O_RDWR
%14 = tail call i32 @open(i8* %0, i32 %13)
%15 = icmp sgt i32 %14, -1
br i1 %15, label %76, label %16
16: ; preds = %12
store i8 50, i8* %5
%17 = load i32, i32* @O_RDWR
%18 = tail call i32 @open(i8* %0, i32 %17)
%19 = icmp sgt i32 %18, -1
br i1 %19, label %76, label %20
20: ; preds = %16
store i8 51, i8* %5
%21 = load i32, i32* @O_RDWR
%22 = tail call i32 @open(i8* %0, i32 %21)
%23 = icmp sgt i32 %22, -1
br i1 %23, label %76, label %24
24: ; preds = %20
store i8 52, i8* %5
%25 = load i32, i32* @O_RDWR
%26 = tail call i32 @open(i8* %0, i32 %25)
%27 = icmp sgt i32 %26, -1
br i1 %27, label %76, label %28
28: ; preds = %24
store i8 53, i8* %5
%29 = load i32, i32* @O_RDWR
%30 = tail call i32 @open(i8* %0, i32 %29)
%31 = icmp sgt i32 %30, -1
br i1 %31, label %76, label %32
32: ; preds = %28
store i8 54, i8* %5
%33 = load i32, i32* @O_RDWR
%34 = tail call i32 @open(i8* %0, i32 %33)
%35 = icmp sgt i32 %34, -1
br i1 %35, label %76, label %36
36: ; preds = %32
store i8 55, i8* %5
%37 = load i32, i32* @O_RDWR
%38 = tail call i32 @open(i8* %0, i32 %37)
%39 = icmp sgt i32 %38, -1
br i1 %39, label %76, label %40
40: ; preds = %36
store i8 56, i8* %5
%41 = load i32, i32* @O_RDWR
%42 = tail call i32 @open(i8* %0, i32 %41)
%43 = icmp sgt i32 %42, -1
br i1 %43, label %76, label %44
44: ; preds = %40
store i8 57, i8* %5
%45 = load i32, i32* @O_RDWR
%46 = tail call i32 @open(i8* %0, i32 %45)
%47 = icmp sgt i32 %46, -1
br i1 %47, label %76, label %48
48: ; preds = %44
store i8 97, i8* %5
%49 = load i32, i32* @O_RDWR
%50 = tail call i32 @open(i8* %0, i32 %49)
%51 = icmp sgt i32 %50, -1
br i1 %51, label %76, label %52
52: ; preds = %48
store i8 98, i8* %5
%53 = load i32, i32* @O_RDWR
%54 = tail call i32 @open(i8* %0, i32 %53)
%55 = icmp sgt i32 %54, -1
br i1 %55, label %76, label %56
56: ; preds = %52
store i8 99, i8* %5
%57 = load i32, i32* @O_RDWR
%58 = tail call i32 @open(i8* %0, i32 %57)
%59 = icmp sgt i32 %58, -1
br i1 %59, label %76, label %60
60: ; preds = %56
store i8 100, i8* %5
%61 = load i32, i32* @O_RDWR
%62 = tail call i32 @open(i8* %0, i32 %61)
%63 = icmp sgt i32 %62, -1
br i1 %63, label %76, label %64
64: ; preds = %60
store i8 101, i8* %5
%65 = load i32, i32* @O_RDWR
%66 = tail call i32 @open(i8* %0, i32 %65)
%67 = icmp sgt i32 %66, -1
br i1 %67, label %76, label %68
68: ; preds = %64
store i8 102, i8* %5
%69 = load i32, i32* @O_RDWR
%70 = tail call i32 @open(i8* %0, i32 %69)
%71 = icmp sgt i32 %70, -1
br i1 %71, label %76, label %72
72: ; preds = %68
%73 = getelementptr inbounds i8, i8* %8, i64 1
%74 = load i8, i8* %73
%75 = icmp eq i8* %73, getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 2)
br i1 %75, label %80, label %6
76: ; preds = %68, %64, %60, %56, %52, %48, %44, %40, %36, %32, %28, %24, %20, %16, %12, %6
%77 = phi i32 [ %10, %6 ], [ %14, %12 ], [ %18, %16 ], [ %22, %20 ], [ %26, %24 ], [ %30, %28 ], [ %34, %32 ], [ %38, %36 ], [ %42, %40 ], [ %46, %44 ], [ %50, %48 ], [ %54, %52 ], [ %58, %56 ], [ %62, %60 ], [ %66, %64 ], [ %70, %68 ]
%78 = tail call i32 @strcpy(i8* %1, i8* %0)
%79 = getelementptr inbounds i8, i8* %1, i64 5
store i8 116, i8* %79
ret i32 %77
80: ; preds = %72
%81 = load i32, i32* @stderr
%82 = tail call i32 @fprintf(i32 %81, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
%83 = tail call i32 @exit(i32 1)
unreachable
}