#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*/ errno;
int /*<<< orphan*/ errorf(char *, int /*<<< orphan*/);
scalar_t__ my_openpty(int *, int *, char *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
scalar_t__ stty_raw(int);
int find_ptyxx(char *ptyname) {
  int fd, ttyfd;
  if (my_openpty(&fd, &ttyfd, ptyname) < 0)
    errorf("Couldn't openpty: %s\n", strerror(errno));
  if (stty_raw(ttyfd) != 0)
    errorf("Couldn't put pty into raw mode: %s\n", strerror(errno));
  return fd;
}


x86 assembly (clang, -O0):
<find_ptyxx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdx
lea    -0xc(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <my_openpty@plt>
cmp    $0x0,%rax
jge    1183 <find_ptyxx+0x43>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %eax,%esi
lea    0xe82(%rip),%rdi
call   1050 <errorf@plt>
mov    -0x10(%rbp),%edi
call   1040 <stty_raw@plt>
cmp    $0x0,%rax
je     11b1 <find_ptyxx+0x71>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %eax,%esi
lea    0xe6a(%rip),%rdi
call   1050 <errorf@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_ptyxx>:
push   %rax
mov    %rdi,%rdx
lea    0x4(%rsp),%rdi
mov    %rsp,%rsi
call   1030 <my_openpty@plt>
test   %rax,%rax
jns    1172 <find_ptyxx+0x32>
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe95(%rip),%rdi
mov    %eax,%esi
call   1050 <errorf@plt>
mov    (%rsp),%edi
call   1040 <stty_raw@plt>
test   %rax,%rax
je     119b <find_ptyxx+0x5b>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe82(%rip),%rdi
mov    %eax,%esi
call   1050 <errorf@plt>
mov    0x4(%rsp),%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Couldn't openpty: %s\0A\00"
@errno = global i32 0
@.str.1 = [36 x i8] c"Couldn't put pty into raw mode: %s\0A\00"
define i32 @find_ptyxx(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @my_openpty(i32* %3, i32* %4, i8* %5)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load i32, i32* @errno
%10 = call i32 @strerror(i32 %9)
%11 = call i32 @errorf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %8, %1
%13 = load i32, i32* %4
%14 = call i64 @stty_raw(i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = load i32, i32* @errno
%18 = call i32 @strerror(i32 %17)
%19 = call i32 @errorf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %16, %12
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
@.str = [22 x i8] c"Couldn't openpty: %s\0A\00"
@errno = global i32 0
@.str.1 = [36 x i8] c"Couldn't put pty into raw mode: %s\0A\00"
define i32 @find_ptyxx(i8* %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = call i64 @my_openpty(i32* %2, i32* %3, i8* %0)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load i32, i32* @errno
%10 = call i32 @strerror(i32 %9)
%11 = call i32 @errorf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %8, %1
%13 = load i32, i32* %3
%14 = call i64 @stty_raw(i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = load i32, i32* @errno
%18 = call i32 @strerror(i32 %17)
%19 = call i32 @errorf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %16, %12
%21 = load i32, i32* %2
ret i32 %21
}