#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 getPtyMaster(char *tty10, char *tty01) {
  char *p10;
  char *p01;
  static char dev[] = "/dev/ptyXX";
  int fd;
  for (p10 = "pqrs"; *p10 != '\0'; p10++) {
    dev[8] = *p10;
    for (p01 = "0123456789abcdef"; *p01 != '\0'; p01++) {
      dev[9] = *p01;
      fd = open(dev, O_RDWR);
      if (fd >= 0) {
        *tty10 = *p10;
        *tty01 = *p01;
        return fd;
      }
    }
  }
  fprintf(stderr, "Ran out of pty.\n");
  exit(1);
  return fd;
}


x86 assembly (clang, -O0):
<getPtyMaster>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeb9(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11fd <getPtyMaster+0xcd>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    %al,0x2ed9(%rip)
lea    0xe97(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11e7 <getPtyMaster+0xb7>
mov    -0x20(%rbp),%rax
mov    (%rax),%al
mov    %al,0x2eb3(%rip)
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
lea    0x2e9a(%rip),%rdi
call   1040 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     11d1 <getPtyMaster+0xa1>
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret
jmp    11d6 <getPtyMaster+0xa6>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1172 <getPtyMaster+0x42>
jmp    11ec <getPtyMaster+0xbc>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    114b <getPtyMaster+0x1b>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
lea    0xe09(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<getPtyMaster>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x70,%al
xor    %r12d,%r12d
lea    0x2eeb(%rip),%rbx
mov    0x2e94(%rip),%r13
lea    0xeaa(%rip),%rbp
mov    %al,0x2edf(%rip)
movb   $0x30,0x2ed9(%rip)
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1040 <open@plt>
test   %eax,%eax
jns    13d0 <getPtyMaster+0x2a0>
movb   $0x31,0x2ebe(%rip)
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1040 <open@plt>
test   %eax,%eax
jns    134b <getPtyMaster+0x21b>
movb   $0x32,0x2ea3(%rip)
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1040 <open@plt>
test   %eax,%eax
jns    1354 <getPtyMaster+0x224>
movb   $0x33,0x2e88(%rip)
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1040 <open@plt>
test   %eax,%eax
jns    135d <getPtyMaster+0x22d>
movb   $0x34,0x2e6d(%rip)
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1040 <open@plt>
test   %eax,%eax
jns    1366 <getPtyMaster+0x236>
movb   $0x35,0x2e52(%rip)
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1040 <open@plt>
test   %eax,%eax
jns    136f <getPtyMaster+0x23f>
movb   $0x36,0x2e37(%rip)
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1040 <open@plt>
test   %eax,%eax
jns    1378 <getPtyMaster+0x248>
movb   $0x37,0x2e1c(%rip)
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1040 <open@plt>
test   %eax,%eax
jns    1381 <getPtyMaster+0x251>
movb   $0x38,0x2e01(%rip)
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1040 <open@plt>
test   %eax,%eax
jns    138a <getPtyMaster+0x25a>
movb   $0x39,0x2de6(%rip)
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1040 <open@plt>
test   %eax,%eax
jns    1393 <getPtyMaster+0x263>
movb   $0x61,0x2dcb(%rip)
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1040 <open@plt>
test   %eax,%eax
jns    139c <getPtyMaster+0x26c>
movb   $0x62,0x2db0(%rip)
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1040 <open@plt>
test   %eax,%eax
jns    13a5 <getPtyMaster+0x275>
movb   $0x63,0x2d95(%rip)
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1040 <open@plt>
test   %eax,%eax
jns    13ae <getPtyMaster+0x27e>
movb   $0x64,0x2d7a(%rip)
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1040 <open@plt>
test   %eax,%eax
jns    13b7 <getPtyMaster+0x287>
movb   $0x65,0x2d5f(%rip)
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1040 <open@plt>
test   %eax,%eax
jns    13c0 <getPtyMaster+0x290>
movb   $0x66,0x2d44(%rip)
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1040 <open@plt>
test   %eax,%eax
jns    13c9 <getPtyMaster+0x299>
lea    0xce8(%rip),%rax
movzbl 0x1(%r12,%rax,1),%eax
add    $0x1,%r12
cmp    $0x4,%r12
jne    115b <getPtyMaster+0x2b>
mov    0x2ca5(%rip),%rax
mov    (%rax),%edi
lea    0xcda(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
lea    0xcb4(%rip),%rbp
jmp    13d0 <getPtyMaster+0x2a0>
lea    0xcac(%rip),%rbp
jmp    13d0 <getPtyMaster+0x2a0>
lea    0xca4(%rip),%rbp
jmp    13d0 <getPtyMaster+0x2a0>
lea    0xc9c(%rip),%rbp
jmp    13d0 <getPtyMaster+0x2a0>
lea    0xc94(%rip),%rbp
jmp    13d0 <getPtyMaster+0x2a0>
lea    0xc8c(%rip),%rbp
jmp    13d0 <getPtyMaster+0x2a0>
lea    0xc84(%rip),%rbp
jmp    13d0 <getPtyMaster+0x2a0>
lea    0xc7c(%rip),%rbp
jmp    13d0 <getPtyMaster+0x2a0>
lea    0xc74(%rip),%rbp
jmp    13d0 <getPtyMaster+0x2a0>
lea    0xc6c(%rip),%rbp
jmp    13d0 <getPtyMaster+0x2a0>
lea    0xc64(%rip),%rbp
jmp    13d0 <getPtyMaster+0x2a0>
lea    0xc5c(%rip),%rbp
jmp    13d0 <getPtyMaster+0x2a0>
lea    0xc54(%rip),%rbp
jmp    13d0 <getPtyMaster+0x2a0>
lea    0xc4c(%rip),%rbp
jmp    13d0 <getPtyMaster+0x2a0>
lea    0xc44(%rip),%rbp
lea    0xc29(%rip),%rcx
mov    (%r12,%rcx,1),%cl
mov    %cl,(%r15)
mov    0x0(%rbp),%cl
mov    %cl,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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