#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*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int ab_manage(int /*<<< orphan*/);
int /*<<< orphan*/ do_echo(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
void *thread_console(void *arg) {
  if (ab_manage(STDIN_FILENO) == -1 || ab_manage(STDOUT_FILENO) == -1)
    return (void *)(intptr_t)errno;
  do_echo(STDIN_FILENO, STDOUT_FILENO);
  exit(0);
}


x86 assembly (clang, -O0):
<thread_console>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
call   1040 <ab_manage@plt>
cmp    $0xffffffff,%eax
je     116a <thread_console+0x3a>
mov    0x2e96(%rip),%rax
mov    (%rax),%edi
call   1040 <ab_manage@plt>
cmp    $0xffffffff,%eax
jne    117a <thread_console+0x4a>
mov    0x2e67(%rip),%rax
mov    (%rax),%rax
add    $0x10,%rsp
pop    %rbp
ret
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
call   1030 <do_echo@plt>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<thread_console>:
push   %r14
push   %rbx
push   %rax
mov    0x2e95(%rip),%rbx
mov    (%rbx),%edi
call   1040 <ab_manage@plt>
cmp    $0xffffffff,%eax
je     115b <thread_console+0x2b>
mov    0x2ea2(%rip),%r14
mov    (%r14),%edi
call   1040 <ab_manage@plt>
cmp    $0xffffffff,%eax
jne    116d <thread_console+0x3d>
mov    0x2e76(%rip),%rax
mov    (%rax),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    (%rbx),%edi
mov    (%r14),%esi
call   1030 <do_echo@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@errno = global i64 0
define i8* @thread_console(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = load i32, i32* @STDIN_FILENO
%4 = call i32 @ab_manage(i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %10, label %6
6: ; preds = %1
%7 = load i32, i32* @STDOUT_FILENO
%8 = call i32 @ab_manage(i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %6, %1
%11 = load i64, i64* @errno
%12 = inttoptr i64 %11 to i8*
ret i8* %12
13: ; preds = %6
%14 = load i32, i32* @STDIN_FILENO
%15 = load i32, i32* @STDOUT_FILENO
%16 = call i32 @do_echo(i32 %14, i32 %15)
%17 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@errno = global i64 0
define i8* @thread_console(i8* nocapture readnone %0) {
%2 = load i32, i32* @STDIN_FILENO
%3 = tail call i32 @ab_manage(i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %9, label %5
5: ; preds = %1
%6 = load i32, i32* @STDOUT_FILENO
%7 = tail call i32 @ab_manage(i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %5, %1
%10 = load i64, i64* @errno
%11 = inttoptr i64 %10 to i8*
ret i8* %11
12: ; preds = %5
%13 = load i32, i32* @STDIN_FILENO
%14 = load i32, i32* @STDOUT_FILENO
%15 = tail call i32 @do_echo(i32 %13, i32 %14)
%16 = tail call i32 @exit(i32 0)
unreachable
}