#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 O_NOCTTY;
int O_RDWR;
int /*<<< orphan*/ grantpt(int);
int open(char const *, int);
char *ptsname(int);
int /*<<< orphan*/ unlockpt(int);
int get_master_slave_ptmx(int *master, int *slave) {
  const char *pts;
  *master = open("/dev/ptmx", O_RDWR);
  if (*master < 0)
    return -1;
  grantpt(*master);
  unlockpt(*master);
  pts = ptsname(*master);
  *slave = open(pts, O_RDWR | O_NOCTTY);
  if (*slave < 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<get_master_slave_ptmx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
lea    0xea0(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jge    1186 <get_master_slave_ptmx+0x46>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ee <get_master_slave_ptmx+0xae>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1060 <grantpt@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1040 <unlockpt@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1030 <ptsname@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
mov    0x2e19(%rip),%rax
or     (%rax),%esi
call   1050 <open@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jge    11e7 <get_master_slave_ptmx+0xa7>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ee <get_master_slave_ptmx+0xae>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_master_slave_ptmx>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e96(%rip),%r15
mov    (%r15),%esi
lea    0xea4(%rip),%rdi
call   1050 <open@plt>
mov    %eax,(%rbx)
test   %eax,%eax
js     1198 <get_master_slave_ptmx+0x58>
mov    %eax,%edi
call   1060 <grantpt@plt>
mov    (%rbx),%edi
call   1040 <unlockpt@plt>
mov    (%rbx),%edi
call   1030 <ptsname@plt>
mov    0x2e55(%rip),%rcx
mov    (%rcx),%esi
or     (%r15),%esi
mov    %rax,%rdi
call   1050 <open@plt>
mov    %eax,(%r14)
sar    $0x1f,%eax
jmp    119d <get_master_slave_ptmx+0x5d>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/ptmx\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
define i32 @get_master_slave_ptmx(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i8*
store i32* %0, i32** %4
store i32* %1, i32** %5
%7 = load i32, i32* @O_RDWR
%8 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i32*, i32** %4
store i32 %8, i32* %9
%10 = load i32*, i32** %4
%11 = load i32, i32* %10
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -1, i32* %3
br label %35
14: ; preds = %2
%15 = load i32*, i32** %4
%16 = load i32, i32* %15
%17 = call i32 @grantpt(i32 %16)
%18 = load i32*, i32** %4
%19 = load i32, i32* %18
%20 = call i32 @unlockpt(i32 %19)
%21 = load i32*, i32** %4
%22 = load i32, i32* %21
%23 = call i8* @ptsname(i32 %22)
store i8* %23, i8** %6
%24 = load i8*, i8** %6
%25 = load i32, i32* @O_RDWR
%26 = load i32, i32* @O_NOCTTY
%27 = or i32 %25, %26
%28 = call i32 @open(i8* %24, i32 %27)
%29 = load i32*, i32** %5
store i32 %28, i32* %29
%30 = load i32*, i32** %5
%31 = load i32, i32* %30
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %14
store i32 -1, i32* %3
br label %35
34: ; preds = %14
store i32 0, i32* %3
br label %35
35: ; preds = %34, %33, %13
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/ptmx\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
define i32 @get_master_slave_ptmx(i32* nocapture %0, i32* nocapture writeonly %1) {
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
store i32 %4, i32* %0
%5 = icmp slt i32 %4, 0
br i1 %5, label %17, label %6
6: ; preds = %2
%7 = tail call i32 @grantpt(i32 %4)
%8 = load i32, i32* %0
%9 = tail call i32 @unlockpt(i32 %8)
%10 = load i32, i32* %0
%11 = tail call i8* @ptsname(i32 %10)
%12 = load i32, i32* @O_RDWR
%13 = load i32, i32* @O_NOCTTY
%14 = or i32 %13, %12
%15 = tail call i32 @open(i8* %11, i32 %14)
store i32 %15, i32* %1
%16 = ashr i32 %15, 31
br label %17
17: ; preds = %6, %2
%18 = phi i32 [ -1, %2 ], [ %16, %6 ]
ret i32 %18
}