#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 check(char *, int /*<<< orphan*/);
int /*<<< orphan*/ grantpt(int);
int /*<<< orphan*/ posix_openpt(int);
int /*<<< orphan*/ unlockpt(int);
int open_pty() {
  int fd = check("posix_openpt", posix_openpt(O_RDWR | O_NOCTTY));
  check("grantpt", grantpt(fd));
  check("unlockpt", unlockpt(fd));
  return fd;
}


x86 assembly (clang, -O0):
<open_pty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%edi
mov    0x2e80(%rip),%rax
or     (%rax),%edi
call   1060 <posix_openpt@plt>
mov    %eax,%esi
lea    0xe98(%rip),%rdi
call   1040 <check@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <grantpt@plt>
mov    %eax,%esi
lea    0xe8c(%rip),%rdi
call   1040 <check@plt>
mov    -0x4(%rbp),%edi
call   1030 <unlockpt@plt>
mov    %eax,%esi
lea    0xe7e(%rip),%rdi
call   1040 <check@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_pty>:
push   %rbx
mov    0x2ea0(%rip),%rax
mov    0x2e89(%rip),%rcx
mov    (%rcx),%edi
or     (%rax),%edi
call   1060 <posix_openpt@plt>
lea    0xea1(%rip),%rdi
mov    %eax,%esi
call   1040 <check@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1050 <grantpt@plt>
lea    0xe97(%rip),%rdi
mov    %eax,%esi
call   1040 <check@plt>
mov    %ebx,%edi
call   1030 <unlockpt@plt>
lea    0xe8a(%rip),%rdi
mov    %eax,%esi
call   1040 <check@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"posix_openpt\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@.str.1 = [8 x i8] c"grantpt\00"
@.str.2 = [9 x i8] c"unlockpt\00"
define i32 @open_pty() {
%1 = alloca i32
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @O_NOCTTY
%4 = or i32 %2, %3
%5 = call i32 @posix_openpt(i32 %4)
%6 = call i32 @check(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %1
%7 = load i32, i32* %1
%8 = call i32 @grantpt(i32 %7)
%9 = call i32 @check(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = load i32, i32* %1
%11 = call i32 @unlockpt(i32 %10)
%12 = call i32 @check(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = load i32, i32* %1
ret i32 %13
}

LLVM IR (-O2):
@.str = [13 x i8] c"posix_openpt\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@.str.1 = [8 x i8] c"grantpt\00"
@.str.2 = [9 x i8] c"unlockpt\00"
define i32 @open_pty() {
%1 = load i32, i32* @O_RDWR
%2 = load i32, i32* @O_NOCTTY
%3 = or i32 %2, %1
%4 = tail call i32 @posix_openpt(i32 %3)
%5 = tail call i32 @check(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = tail call i32 @grantpt(i32 %5)
%7 = tail call i32 @check(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = tail call i32 @unlockpt(i32 %5)
%9 = tail call i32 @check(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %8)
ret i32 %5
}