#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*/ abort();
scalar_t__ grantpt(int);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ unlockpt(int);
int make_pty() {
  int pty;
  if ((pty = open("/dev/ptmx", O_RDWR | O_NOCTTY)) < 0) {
    perror(("Unable to open /dev/ptmx: %m"));
    abort();
  };
  if ((unlockpt(pty)) < 0) {
    perror(("Unable to unlockpt: %m"));
    abort();
  };
  if ((grantpt(pty)) < 0) {
    perror(("Unable to grantpt: %m"));
    abort();
  };
  return pty;
}


x86 assembly (clang, -O0):
<make_pty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
mov    0x2e70(%rip),%rax
or     (%rax),%esi
lea    0xe8f(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jge    1195 <make_pty+0x45>
lea    0xe81(%rip),%rdi
call   1060 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x4(%rbp),%edi
call   1040 <unlockpt@plt>
cmp    $0x0,%rax
jge    11ba <make_pty+0x6a>
lea    0xe79(%rip),%rdi
call   1060 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x4(%rbp),%edi
call   1070 <grantpt@plt>
cmp    $0x0,%rax
jge    11df <make_pty+0x8f>
lea    0xe6b(%rip),%rdi
call   1060 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_pty>:
push   %rbx
mov    0x2e90(%rip),%rax
mov    0x2e79(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe96(%rip),%rdi
call   1050 <open@plt>
test   %eax,%eax
js     1191 <make_pty+0x41>
mov    %eax,%ebx
mov    %eax,%edi
call   1040 <unlockpt@plt>
test   %rax,%rax
js     119a <make_pty+0x4a>
mov    %ebx,%edi
call   1070 <grantpt@plt>
test   %rax,%rax
js     11a3 <make_pty+0x53>
mov    %ebx,%eax
pop    %rbx
ret
lea    0xe72(%rip),%rdi
jmp    11aa <make_pty+0x5a>
lea    0xe86(%rip),%rdi
jmp    11aa <make_pty+0x5a>
lea    0xe94(%rip),%rdi
call   1060 <perror@plt>
xor    %eax,%eax
call   1030 <abort@plt>

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

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/ptmx\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@.str.1 = [29 x i8] c"Unable to open /dev/ptmx: %m\00"
@.str.2 = [23 x i8] c"Unable to unlockpt: %m\00"
@.str.3 = [22 x i8] c"Unable to grantpt: %m\00"
define i32 @make_pty() {
%1 = load i32, i32* @O_RDWR
%2 = load i32, i32* @O_NOCTTY
%3 = or i32 %2, %1
%4 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 (...) @abort()
unreachable
9: ; preds = %0
%10 = tail call i64 @unlockpt(i32 %4)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%14 = tail call i32 (...) @abort()
unreachable
15: ; preds = %9
%16 = tail call i64 @grantpt(i32 %4)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%20 = tail call i32 (...) @abort()
unreachable
21: ; preds = %15
ret i32 %4
}