#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 */
scalar_t__ asprintf(char **, char *, char const *);
int /*<<< orphan*/ free(char *);
char *oneline(char *);
__attribute__((__malloc__)) char *actattr(const char *tty) {
  char *ret = (char *)0;
  char *path;
  if (!tty || *tty == '\0')
    goto err;
  if (asprintf(&path, "/sys/class/tty/%s/active", tty) < 0)
    goto err;
  if ((ret = oneline(path)) == (char *)0)
    goto out;
out:
  free(path);
err:
  return ret;
}


x86 assembly (clang, -O0):
<actattr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     115f <actattr+0x2f>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1164 <actattr+0x34>
jmp    11b1 <actattr+0x81>
mov    -0x8(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1050 <asprintf@plt>
cmp    $0x0,%rax
jge    1187 <actattr+0x57>
jmp    11b1 <actattr+0x81>
mov    -0x18(%rbp),%rdi
call   1040 <oneline@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11a3 <actattr+0x73>
jmp    11a8 <actattr+0x78>
jmp    11a8 <actattr+0x78>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<actattr>:
push   %rbx
sub    $0x10,%rsp
test   %rdi,%rdi
je     1171 <actattr+0x41>
mov    %rdi,%rdx
cmpb   $0x0,(%rdi)
je     1171 <actattr+0x41>
lea    0xeb7(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1050 <asprintf@plt>
test   %rax,%rax
js     1171 <actattr+0x41>
mov    0x8(%rsp),%rdi
call   1040 <oneline@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
jmp    1173 <actattr+0x43>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [25 x i8] c"/sys/class/tty/%s/active\00"
define noalias i8* @actattr(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
store i8* null, i8** %3
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %12
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %7, %1
br label %27
13: ; preds = %7
%14 = load i8*, i8** %2
%15 = call i64 @asprintf(i8** %4, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
br label %27
18: ; preds = %13
%19 = load i8*, i8** %4
%20 = call i8* @oneline(i8* %19)
store i8* %20, i8** %3
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %23
22: ; preds = %18
br label %24
23: ; preds = %18
br label %24
24: ; preds = %23, %22
%25 = load i8*, i8** %4
%26 = call i32 @free(i8* %25)
br label %27
27: ; preds = %24, %17, %12
%28 = load i8*, i8** %3
ret i8* %28
}

LLVM IR (-O2):
@.str = [25 x i8] c"/sys/class/tty/%s/active\00"
define noalias i8* @actattr(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %16, label %5
5: ; preds = %1
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %16, label %8
8: ; preds = %5
%9 = call i64 @asprintf(i8** %2, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %0)
%10 = icmp slt i64 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %8
%12 = load i8*, i8** %2
%13 = call i8* @oneline(i8* %12)
%14 = load i8*, i8** %2
%15 = call i32 @free(i8* %14)
br label %16
16: ; preds = %8, %1, %5, %11
%17 = phi i8* [ null, %5 ], [ null, %8 ], [ %13, %11 ], [ null, %1 ]
ret i8* %17
}