#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*/ MS_BIND;
int do_tiocgptpeer(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int mount(char *, char *, int /*<<< orphan*/ *, int /*<<< orphan*/,
          int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int verify_ptmx_bind_mount(void) {
  int ret;
  ret = mount("/dev/pts/ptmx", "/dev/ptmx", NULL, MS_BIND, NULL);
  if (ret < 0) {
    fprintf(stderr, "Failed to bind mount \"/dev/pts/ptmx\" to "
                    "\"/dev/ptmx\" mount namespace\n");
    return -1;
  }
  ret = do_tiocgptpeer("/dev/ptmx", "/dev/pts/");
  if (ret < 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<verify_ptmx_bind_mount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ea9(%rip),%rax
mov    (%rax),%ecx
lea    0xeb8(%rip),%rdi
lea    0xebf(%rip),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
call   1030 <mount@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    118a <verify_ptmx_bind_mount+0x5a>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
lea    0xe9f(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bd <verify_ptmx_bind_mount+0x8d>
lea    0xe7d(%rip),%rdi
lea    0xec5(%rip),%rsi
call   1050 <do_tiocgptpeer@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11b6 <verify_ptmx_bind_mount+0x86>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bd <verify_ptmx_bind_mount+0x8d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verify_ptmx_bind_mount>:
push   %rax
mov    0x2eb0(%rip),%rax
mov    (%rax),%ecx
lea    0xebf(%rip),%rdi
lea    0xec6(%rip),%rsi
xor    %edx,%edx
xor    %r8d,%r8d
call   1030 <mount@plt>
test   %eax,%eax
js     116e <verify_ptmx_bind_mount+0x3e>
lea    0xeb1(%rip),%rdi
lea    0xef9(%rip),%rsi
call   1050 <do_tiocgptpeer@plt>
sar    $0x1f,%eax
pop    %rcx
ret
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
lea    0xe9a(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/dev/pts/ptmx\00"
@.str.1 = [10 x i8] c"/dev/ptmx\00"
@MS_BIND = global i32 0
@stderr = global i32 0
@.str.2 = [69 x i8] c"Failed to bind mount \22/dev/pts/ptmx\22 to \22/dev/ptmx\22 mount namespace\0A\00"
@.str.3 = [10 x i8] c"/dev/pts/\00"
define i32 @verify_ptmx_bind_mount() {
%1 = alloca i32
%2 = alloca i32
%3 = load i32, i32* @MS_BIND
%4 = call i32 @mount(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* null, i32 %3, i32* null)
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %16
10: ; preds = %0
%11 = call i32 @do_tiocgptpeer(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
store i32 %11, i32* %2
%12 = load i32, i32* %2
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %10
store i32 -1, i32* %1
br label %16
15: ; preds = %10
store i32 0, i32* %1
br label %16
16: ; preds = %15, %14, %7
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
@.str = [14 x i8] c"/dev/pts/ptmx\00"
@.str.1 = [10 x i8] c"/dev/ptmx\00"
@MS_BIND = global i32 0
@stderr = global i32 0
@.str.2 = [69 x i8] c"Failed to bind mount \22/dev/pts/ptmx\22 to \22/dev/ptmx\22 mount namespace\0A\00"
@.str.3 = [10 x i8] c"/dev/pts/\00"
define i32 @verify_ptmx_bind_mount() {
%1 = load i32, i32* @MS_BIND
%2 = tail call i32 @mount(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* null, i32 %1, i32* null)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.2, i64 0, i64 0))
br label %10
7: ; preds = %0
%8 = tail call i32 @do_tiocgptpeer(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%9 = ashr i32 %8, 31
br label %10
10: ; preds = %7, %4
%11 = phi i32 [ -1, %4 ], [ %9, %7 ]
ret i32 %11
}