#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*/ assert(int);
int open(int /*<<< orphan*/, int);
int posix_openpt(int);
int /*<<< orphan*/ ptsname(int);
void open_pty(int *master_fd, int *slave_fd) {
  *master_fd = posix_openpt(O_NOCTTY | O_RDWR);
  assert(*master_fd >= 0);
  *slave_fd = open(ptsname(*master_fd), O_NOCTTY | O_RDWR);
  assert(*slave_fd >= 0);
}


x86 assembly (clang, -O0):
<open_pty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
mov    0x2e88(%rip),%rax
or     (%rax),%edi
call   1060 <posix_openpt@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
cmpl   $0x0,(%rax)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1030 <ptsname@plt>
mov    %eax,%edi
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
mov    0x2e48(%rip),%rax
or     (%rax),%esi
call   1050 <open@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_pty>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e83(%rip),%r15
mov    0x2e8c(%rip),%r12
mov    (%r12),%edi
or     (%r15),%edi
call   1060 <posix_openpt@plt>
mov    %eax,(%rbx)
not    %eax
shr    $0x1f,%eax
mov    %eax,%edi
call   1040 <assert@plt>
mov    (%rbx),%edi
call   1030 <ptsname@plt>
mov    (%r12),%esi
or     (%r15),%esi
mov    %eax,%edi
call   1050 <open@plt>
mov    %eax,(%r14)
not    %eax
shr    $0x1f,%eax
mov    %eax,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <assert@plt>

LLVM IR (-O0):
@O_NOCTTY = global i32 0
@O_RDWR = global i32 0
define void @open_pty(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
store i32* %0, i32** %3
store i32* %1, i32** %4
%5 = load i32, i32* @O_NOCTTY
%6 = load i32, i32* @O_RDWR
%7 = or i32 %5, %6
%8 = call i32 @posix_openpt(i32 %7)
%9 = load i32*, i32** %3
store i32 %8, i32* %9
%10 = load i32*, i32** %3
%11 = load i32, i32* %10
%12 = icmp sge i32 %11, 0
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i32*, i32** %3
%16 = load i32, i32* %15
%17 = call i32 @ptsname(i32 %16)
%18 = load i32, i32* @O_NOCTTY
%19 = load i32, i32* @O_RDWR
%20 = or i32 %18, %19
%21 = call i32 @open(i32 %17, i32 %20)
%22 = load i32*, i32** %4
store i32 %21, i32* %22
%23 = load i32*, i32** %4
%24 = load i32, i32* %23
%25 = icmp sge i32 %24, 0
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
ret void
}

LLVM IR (-O2):
@O_NOCTTY = global i32 0
@O_RDWR = global i32 0
define void @open_pty(i32* nocapture %0, i32* nocapture writeonly %1) {
%3 = load i32, i32* @O_NOCTTY
%4 = load i32, i32* @O_RDWR
%5 = or i32 %4, %3
%6 = tail call i32 @posix_openpt(i32 %5)
store i32 %6, i32* %0
%7 = xor i32 %6, -1
%8 = lshr i32 %7, 31
%9 = tail call i32 @assert(i32 %8)
%10 = load i32, i32* %0
%11 = tail call i32 @ptsname(i32 %10)
%12 = load i32, i32* @O_NOCTTY
%13 = load i32, i32* @O_RDWR
%14 = or i32 %13, %12
%15 = tail call i32 @open(i32 %11, i32 %14)
store i32 %15, i32* %1
%16 = xor i32 %15, -1
%17 = lshr i32 %16, 31
%18 = tail call i32 @assert(i32 %17)
ret void
}