#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 */
typedef int /*<<< orphan*/ dev_t;

/* Variables and functions */
int ENOMEM;
int O_CLOEXEC;
int O_NOCTTY;
int O_NONBLOCK;
int O_RDONLY;
scalar_t__ asprintf(char **, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ free(char *);
int get_ctty_devnr(int /*<<< orphan*/ *);
int /*<<< orphan*/ major(int /*<<< orphan*/);
int /*<<< orphan*/ minor(int /*<<< orphan*/);
int /*<<< orphan*/ mkdir_parents(char *, int);
int /*<<< orphan*/ mkfifo(char *, int);
int open(char *, int);
int wall_tty_block(void) {
  char *p;
  int fd, r;
  dev_t devnr;
  if ((r = get_ctty_devnr(&devnr)) < 0)
    return -r;
  if (asprintf(&p, "/run/systemd/ask-password-block/%u:%u", major(devnr),
               minor(devnr)) < 0)
    return -ENOMEM;
  mkdir_parents(p, 0700);
  mkfifo(p, 0600);
  fd = open(p, O_RDONLY | O_CLOEXEC | O_NONBLOCK | O_NOCTTY);
  free(p);
  if (fd < 0)
    return -errno;
  return fd;
}


x86 assembly (clang, -O0):
<wall_tty_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x1c(%rbp),%rdi
call   1050 <get_ctty_devnr@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    11aa <wall_tty_block+0x2a>
xor    %eax,%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1267 <wall_tty_block+0xe7>
mov    -0x1c(%rbp),%edi
call   1070 <major@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <minor@plt>
mov    -0x20(%rbp),%edx
mov    %eax,%ecx
lea    -0x10(%rbp),%rdi
lea    0xe33(%rip),%rsi
call   1090 <asprintf@plt>
cmp    $0x0,%rax
jge    11ef <wall_tty_block+0x6f>
xor    %eax,%eax
mov    0x2deb(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1267 <wall_tty_block+0xe7>
mov    -0x10(%rbp),%rdi
mov    $0x1c0,%esi
call   1030 <mkdir_parents@plt>
mov    -0x10(%rbp),%rdi
mov    $0x180,%esi
call   1080 <mkfifo@plt>
mov    -0x10(%rbp),%rdi
mov    0x2dca(%rip),%rax
mov    (%rax),%esi
mov    0x2d91(%rip),%rax
or     (%rax),%esi
mov    0x2dc0(%rip),%rax
or     (%rax),%esi
mov    0x2d97(%rip),%rax
or     (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <free@plt>
cmpl   $0x0,-0x14(%rbp)
jge    1261 <wall_tty_block+0xe1>
xor    %eax,%eax
mov    0x2d69(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1267 <wall_tty_block+0xe7>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wall_tty_block>:
push   %rbx
sub    $0x10,%rsp
lea    0x4(%rsp),%rdi
call   1050 <get_ctty_devnr@plt>
test   %eax,%eax
js     122a <wall_tty_block+0xaa>
mov    0x4(%rsp),%edi
call   1070 <major@plt>
mov    %eax,%ebx
mov    0x4(%rsp),%edi
call   1060 <minor@plt>
lea    0xe4e(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %ebx,%edx
mov    %eax,%ecx
call   1090 <asprintf@plt>
test   %rax,%rax
js     1230 <wall_tty_block+0xb0>
mov    0x8(%rsp),%rdi
mov    $0x1c0,%esi
call   1030 <mkdir_parents@plt>
mov    0x8(%rsp),%rdi
mov    $0x180,%esi
call   1080 <mkfifo@plt>
mov    0x2df6(%rip),%rax
mov    0x2dbf(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2dec(%rip),%rax
or     (%rax),%esi
mov    0x8(%rsp),%rdi
mov    0x2dbe(%rip),%rax
or     (%rax),%esi
call   10a0 <open@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rdi
call   1040 <free@plt>
test   %ebx,%ebx
jns    123b <wall_tty_block+0xbb>
mov    0x2d98(%rip),%rax
jmp    1237 <wall_tty_block+0xb7>
mov    %eax,%ebx
neg    %ebx
jmp    123b <wall_tty_block+0xbb>
mov    0x2d99(%rip),%rax
xor    %ebx,%ebx
sub    (%rax),%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [38 x i8] c"/run/systemd/ask-password-block/%u:%u\00"
@ENOMEM = global i32 0
@O_RDONLY = global i32 0
@O_CLOEXEC = global i32 0
@O_NONBLOCK = global i32 0
@O_NOCTTY = global i32 0
@errno = global i32 0
define i32 @wall_tty_block() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = call i32 @get_ctty_devnr(i32* %5)
store i32 %6, i32* %4
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = load i32, i32* %4
%10 = sub nsw i32 0, %9
store i32 %10, i32* %1
br label %44
11: ; preds = %0
%12 = load i32, i32* %5
%13 = call i32 @major(i32 %12)
%14 = load i32, i32* %5
%15 = call i32 @minor(i32 %14)
%16 = call i64 @asprintf(i8** %2, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %15)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = load i32, i32* @ENOMEM
%20 = sub nsw i32 0, %19
store i32 %20, i32* %1
br label %44
21: ; preds = %11
%22 = load i8*, i8** %2
%23 = call i32 @mkdir_parents(i8* %22, i32 448)
%24 = load i8*, i8** %2
%25 = call i32 @mkfifo(i8* %24, i32 384)
%26 = load i8*, i8** %2
%27 = load i32, i32* @O_RDONLY
%28 = load i32, i32* @O_CLOEXEC
%29 = or i32 %27, %28
%30 = load i32, i32* @O_NONBLOCK
%31 = or i32 %29, %30
%32 = load i32, i32* @O_NOCTTY
%33 = or i32 %31, %32
%34 = call i32 @open(i8* %26, i32 %33)
store i32 %34, i32* %3
%35 = load i8*, i8** %2
%36 = call i32 @free(i8* %35)
%37 = load i32, i32* %3
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %21
%40 = load i32, i32* @errno
%41 = sub nsw i32 0, %40
store i32 %41, i32* %1
br label %44
42: ; preds = %21
%43 = load i32, i32* %3
store i32 %43, i32* %1
br label %44
44: ; preds = %42, %39, %18, %8
%45 = load i32, i32* %1
ret i32 %45
}

LLVM IR (-O2):
@.str = [38 x i8] c"/run/systemd/ask-password-block/%u:%u\00"
@ENOMEM = global i32 0
@O_RDONLY = global i32 0
@O_CLOEXEC = global i32 0
@O_NONBLOCK = global i32 0
@O_NOCTTY = global i32 0
@errno = global i32 0
define i32 @wall_tty_block() {
%1 = alloca i8*
%2 = alloca i32
%3 = bitcast i8** %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 @get_ctty_devnr(i32* %2)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = sub nsw i32 0, %5
br label %39
9: ; preds = %0
%10 = load i32, i32* %2
%11 = call i32 @major(i32 %10)
%12 = load i32, i32* %2
%13 = call i32 @minor(i32 %12)
%14 = call i64 @asprintf(i8** %1, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %9
%17 = load i32, i32* @ENOMEM
%18 = sub nsw i32 0, %17
br label %39
19: ; preds = %9
%20 = load i8*, i8** %1
%21 = call i32 @mkdir_parents(i8* %20, i32 448)
%22 = load i8*, i8** %1
%23 = call i32 @mkfifo(i8* %22, i32 384)
%24 = load i8*, i8** %1
%25 = load i32, i32* @O_RDONLY
%26 = load i32, i32* @O_CLOEXEC
%27 = or i32 %26, %25
%28 = load i32, i32* @O_NONBLOCK
%29 = or i32 %27, %28
%30 = load i32, i32* @O_NOCTTY
%31 = or i32 %29, %30
%32 = call i32 @open(i8* %24, i32 %31)
%33 = load i8*, i8** %1
%34 = call i32 @free(i8* %33)
%35 = icmp slt i32 %32, 0
br i1 %35, label %36, label %39
36: ; preds = %19
%37 = load i32, i32* @errno
%38 = sub nsw i32 0, %37
br label %39
39: ; preds = %19, %36, %16, %7
%40 = phi i32 [ %8, %7 ], [ %18, %16 ], [ %38, %36 ], [ %32, %19 ]
ret i32 %40
}