#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 open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int getpseudotty(char *ttydev, char *ptydev) {
  static int devindex = 0, letter = 0;
  int fd;
  strcpy(ttydev, "/dev/ttyxx");
  strcpy(ptydev, "/dev/ptyxx");
  while ("abcdepqrstuvwxyz"[letter]) {
    ttydev[strlen(ttydev) - 2] = ptydev[strlen(ptydev) - 2] =
        "abcdepqrstuvwxyz"[letter];
    while ("0123456789abcdef"[devindex]) {
      ttydev[strlen(ttydev) - 1] = ptydev[strlen(ptydev) - 1] =
          "0123456789abcdef"[devindex];
      devindex++;
      if ((fd = open(ptydev, O_RDWR)) >= 0)
        return fd;
    }
    devindex = 0;
    letter++;
  }
  return -1;
}


x86 assembly (clang, -O0):
<getpseudotty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
lea    0xeb0(%rip),%rsi
call   1030 <strcpy@plt>
movslq 0x2ed9(%rip),%rcx
lea    0xea8(%rip),%rax
cmpb   $0x0,(%rax,%rcx,1)
je     129f <getpseudotty+0x16f>
movslq 0x2ec1(%rip),%rcx
lea    0xe90(%rip),%rax
mov    (%rax,%rcx,1),%al
mov    %al,-0x29(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x29(%rbp),%dl
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
sub    $0x2,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x29(%rbp),%dl
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x2,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
movslq 0x2e63(%rip),%rcx
lea    0xe47(%rip),%rax
cmpb   $0x0,(%rax,%rcx,1)
je     1281 <getpseudotty+0x151>
movslq 0x2e4b(%rip),%rcx
lea    0xe2f(%rip),%rax
mov    (%rax,%rcx,1),%al
mov    %al,-0x41(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x41(%rbp),%dl
mov    %eax,%ecx
mov    -0x50(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x41(%rbp),%dl
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    0x2df2(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2de9(%rip)
mov    -0x18(%rbp),%rdi
mov    0x2d8a(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jl     127c <getpseudotty+0x14c>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12a6 <getpseudotty+0x176>
jmp    11d2 <getpseudotty+0xa2>
movl   $0x0,0x2db1(%rip)
mov    0x2daf(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2da6(%rip)
jmp    1160 <getpseudotty+0x30>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getpseudotty>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r14
lea    0xeb8(%rip),%rsi
call   1030 <strcpy@plt>
lea    0xeb7(%rip),%rsi
mov    %r12,%rdi
call   1030 <strcpy@plt>
mov    0x2ede(%rip),%ecx
mov    $0xffffffff,%eax
cmp    $0x10,%ecx
jne    117b <getpseudotty+0x4b>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe94(%rip),%rdx
lea    0xe9e(%rip),%r13
mov    0x2e58(%rip),%rbp
movslq %ecx,%rax
mov    (%rax,%rdx,1),%r15b
mov    %r12,%rdi
call   1040 <strlen@plt>
cltq
mov    %r15b,-0x2(%rax,%r12,1)
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
mov    %r15b,-0x2(%rax,%r14,1)
cs nopw 0x0(%rax,%rax,1)
nop
movslq 0x2e75(%rip),%rax
cmp    $0x10,%rax
je     1210 <getpseudotty+0xe0>
movzbl (%rax,%r13,1),%ebx
mov    %r12,%rdi
call   1040 <strlen@plt>
cltq
mov    %bl,-0x1(%rax,%r12,1)
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
mov    %bl,-0x1(%rax,%r14,1)
addl   $0x1,0x2e45(%rip)
mov    0x0(%rbp),%esi
mov    %r12,%rdi
call   1050 <open@plt>
test   %eax,%eax
js     11c0 <getpseudotty+0x90>
jmp    116c <getpseudotty+0x3c>
nopl   0x0(%rax,%rax,1)
movl   $0x0,0x2e22(%rip)
mov    0x2e20(%rip),%ecx
add    $0x1,%ecx
mov    %ecx,0x2e17(%rip)
cmp    $0x10,%ecx
lea    0xde3(%rip),%rdx
jne    1190 <getpseudotty+0x60>
mov    $0xffffffff,%eax
jmp    116c <getpseudotty+0x3c>

LLVM IR (-O0):
@getpseudotty.devindex = internal global i32 0
@getpseudotty.letter = internal global i32 0
@.str = [11 x i8] c"/dev/ttyxx\00"
@.str.1 = [11 x i8] c"/dev/ptyxx\00"
@.str.2 = [17 x i8] c"abcdepqrstuvwxyz\00"
@.str.3 = [17 x i8] c"0123456789abcdef\00"
@O_RDWR = global i32 0
define i32 @getpseudotty(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%9 = load i8*, i8** %5
%10 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %66, %2
%12 = load i32, i32* @getpseudotty.letter
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [17 x i8], [17 x i8]* @.str.2, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %69
17: ; preds = %11
%18 = load i32, i32* @getpseudotty.letter
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [17 x i8], [17 x i8]* @.str.2, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = load i8*, i8** %5
%23 = load i8*, i8** %5
%24 = call i32 @strlen(i8* %23)
%25 = sub nsw i32 %24, 2
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %22, i64 %26
store i8 %21, i8* %27
%28 = load i8*, i8** %4
%29 = load i8*, i8** %4
%30 = call i32 @strlen(i8* %29)
%31 = sub nsw i32 %30, 2
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %28, i64 %32
store i8 %21, i8* %33
br label %34
34: ; preds = %65, %17
%35 = load i32, i32* @getpseudotty.devindex
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [17 x i8], [17 x i8]* @.str.3, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = icmp ne i8 %38, 0
br i1 %39, label %40, label %66
40: ; preds = %34
%41 = load i32, i32* @getpseudotty.devindex
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [17 x i8], [17 x i8]* @.str.3, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = load i8*, i8** %5
%46 = load i8*, i8** %5
%47 = call i32 @strlen(i8* %46)
%48 = sub nsw i32 %47, 1
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %45, i64 %49
store i8 %44, i8* %50
%51 = load i8*, i8** %4
%52 = load i8*, i8** %4
%53 = call i32 @strlen(i8* %52)
%54 = sub nsw i32 %53, 1
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %51, i64 %55
store i8 %44, i8* %56
%57 = load i32, i32* @getpseudotty.devindex
%58 = add nsw i32 %57, 1
store i32 %58, i32* @getpseudotty.devindex
%59 = load i8*, i8** %5
%60 = load i32, i32* @O_RDWR
%61 = call i32 @open(i8* %59, i32 %60)
store i32 %61, i32* %6
%62 = icmp sge i32 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %40
%64 = load i32, i32* %6
store i32 %64, i32* %3
br label %70
65: ; preds = %40
br label %34
66: ; preds = %34
store i32 0, i32* @getpseudotty.devindex
%67 = load i32, i32* @getpseudotty.letter
%68 = add nsw i32 %67, 1
store i32 %68, i32* @getpseudotty.letter
br label %11
69: ; preds = %11
store i32 -1, i32* %3
br label %70
70: ; preds = %69, %63
%71 = load i32, i32* %3
ret i32 %71
}

LLVM IR (-O2):
@getpseudotty.devindex = internal unnamed_addr global i32 0
@getpseudotty.letter = internal unnamed_addr global i32 0
@.str = [11 x i8] c"/dev/ttyxx\00"
@.str.1 = [11 x i8] c"/dev/ptyxx\00"
@.str.2 = [17 x i8] c"abcdepqrstuvwxyz\00"
@.str.3 = [17 x i8] c"0123456789abcdef\00"
@O_RDWR = global i32 0
define i32 @getpseudotty(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 = tail call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%5 = load i32, i32* @getpseudotty.letter
%6 = icmp eq i32 %5, 16
br i1 %6, label %44, label %7
7: ; preds = %2, %40
%8 = phi i32 [ %42, %40 ], [ %5, %2 ]
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [17 x i8], [17 x i8]* @.str.2, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = tail call i32 @strlen(i8* %1)
%13 = add nsw i32 %12, -2
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %1, i64 %14
store i8 %11, i8* %15
%16 = tail call i32 @strlen(i8* %0)
%17 = add nsw i32 %16, -2
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %0, i64 %18
store i8 %11, i8* %19
br label %20
20: ; preds = %26, %7
%21 = load i32, i32* @getpseudotty.devindex
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [17 x i8], [17 x i8]* @.str.3, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = icmp eq i32 %21, 16
br i1 %25, label %40, label %26
26: ; preds = %20
%27 = tail call i32 @strlen(i8* %1)
%28 = add nsw i32 %27, -1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %1, i64 %29
store i8 %24, i8* %30
%31 = tail call i32 @strlen(i8* %0)
%32 = add nsw i32 %31, -1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %0, i64 %33
store i8 %24, i8* %34
%35 = load i32, i32* @getpseudotty.devindex
%36 = add nsw i32 %35, 1
store i32 %36, i32* @getpseudotty.devindex
%37 = load i32, i32* @O_RDWR
%38 = tail call i32 @open(i8* %1, i32 %37)
%39 = icmp sgt i32 %38, -1
br i1 %39, label %44, label %20
40: ; preds = %20
store i32 0, i32* @getpseudotty.devindex
%41 = load i32, i32* @getpseudotty.letter
%42 = add nsw i32 %41, 1
store i32 %42, i32* @getpseudotty.letter
%43 = icmp eq i32 %42, 16
br i1 %43, label %44, label %7
44: ; preds = %40, %26, %2
%45 = phi i32 [ -1, %2 ], [ %38, %26 ], [ -1, %40 ]
ret i32 %45
}