#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*/ O_RDWR;
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
scalar_t__ grantpt(int);
int posix_openpt(int /*<<< orphan*/);
int /*<<< orphan*/ ptsname(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
scalar_t__ unlockpt(int);
int sys_init_CreateMaster(char fsn[]) {
  int fdm;
  if ((fdm = posix_openpt(O_RDWR)) < 0) {
    fprintf(stderr, "Error %d on posix_openpt()\n", errno);
    exit(1);
  }
  if (grantpt(fdm) != 0) {
    fprintf(stderr, "Error %d on grantpt()\n", errno);
    exit(1);
  }
  if (unlockpt(fdm) != 0) {
    fprintf(stderr, "Error %d on unlockpt()\n", errno);
    return 1;
  }
  strcpy(fsn, ptsname(fdm));
  return fdm;
}


x86 assembly (clang, -O0):
<sys_init_CreateMaster>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
call   1090 <posix_openpt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11be <sys_init_CreateMaster+0x4e>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
mov    0x2e2a(%rip),%rax
mov    (%rax),%edx
lea    0xe51(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
call   1070 <grantpt@plt>
cmp    $0x0,%rax
je     11f8 <sys_init_CreateMaster+0x88>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
mov    0x2df0(%rip),%rax
mov    (%rax),%edx
lea    0xe33(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
call   1050 <unlockpt@plt>
cmp    $0x0,%rax
je     1234 <sys_init_CreateMaster+0xc4>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
mov    0x2db6(%rip),%rax
mov    (%rax),%edx
lea    0xe10(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1255 <sys_init_CreateMaster+0xe5>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <ptsname@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%esi
call   1040 <strcpy@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sys_init_CreateMaster>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
call   1090 <posix_openpt@plt>
test   %eax,%eax
js     11e3 <sys_init_CreateMaster+0x73>
mov    %eax,%ebx
mov    %eax,%edi
call   1070 <grantpt@plt>
test   %rax,%rax
jne    11fe <sys_init_CreateMaster+0x8e>
mov    %ebx,%edi
call   1050 <unlockpt@plt>
test   %rax,%rax
je     11c8 <sys_init_CreateMaster+0x58>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
mov    0x2e1d(%rip),%rax
mov    (%rax),%edx
lea    0xe77(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%ebx
jmp    11d9 <sys_init_CreateMaster+0x69>
mov    %ebx,%edi
call   1030 <ptsname@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <strcpy@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
mov    0x2ddd(%rip),%rax
mov    (%rax),%edx
lea    0xe04(%rip),%rsi
jmp    1217 <sys_init_CreateMaster+0xa7>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
mov    0x2dc2(%rip),%rax
mov    (%rax),%edx
lea    0xe05(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@O_RDWR = global i32 0
@stderr = global i32 0
@.str = [28 x i8] c"Error %d on posix_openpt()\0A\00"
@errno = global i32 0
@.str.1 = [23 x i8] c"Error %d on grantpt()\0A\00"
@.str.2 = [24 x i8] c"Error %d on unlockpt()\0A\00"
define i32 @sys_init_CreateMaster(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i32, i32* @O_RDWR
%6 = call i32 @posix_openpt(i32 %5)
store i32 %6, i32* %4
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %1
%14 = load i32, i32* %4
%15 = call i64 @grantpt(i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %13
%23 = load i32, i32* %4
%24 = call i64 @unlockpt(i32 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = load i32, i32* @errno
%29 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %28)
store i32 1, i32* %2
br label %36
30: ; preds = %22
%31 = load i8*, i8** %3
%32 = load i32, i32* %4
%33 = call i32 @ptsname(i32 %32)
%34 = call i32 @strcpy(i8* %31, i32 %33)
%35 = load i32, i32* %4
store i32 %35, i32* %2
br label %36
36: ; preds = %30, %26
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@stderr = global i32 0
@.str = [28 x i8] c"Error %d on posix_openpt()\0A\00"
@errno = global i32 0
@.str.1 = [23 x i8] c"Error %d on grantpt()\0A\00"
@.str.2 = [24 x i8] c"Error %d on unlockpt()\0A\00"
define i32 @sys_init_CreateMaster(i8* %0) {
%2 = load i32, i32* @O_RDWR
%3 = tail call i32 @posix_openpt(i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %10
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = load i32, i32* @errno
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %1
%11 = tail call i64 @grantpt(i32 %3)
%12 = icmp eq i64 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %10
%19 = tail call i64 @unlockpt(i32 %3)
%20 = icmp eq i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = load i32, i32* @errno
%24 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %23)
br label %28
25: ; preds = %18
%26 = tail call i32 @ptsname(i32 %3)
%27 = tail call i32 @strcpy(i8* %0, i32 %26)
br label %28
28: ; preds = %25, %21
%29 = phi i32 [ 1, %21 ], [ %3, %25 ]
ret i32 %29
}