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

/* Variables and functions */
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ fail(char *);
scalar_t__ fchmod(int /*<<< orphan*/, int);
scalar_t__ fchown(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
void chown_tty(uid_t owner, gid_t group, char with_fail) {
  if (fchown(STDIN_FILENO, owner, group) && with_fail)
    fail("fchown");
  if (fchmod(STDIN_FILENO, 0600) && with_fail)
    fail("fchmod");
}


x86 assembly (clang, -O0):
<chown_tty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dl,%al
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    0x2e96(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1050 <fchown@plt>
cmp    $0x0,%rax
je     117a <chown_tty+0x4a>
movsbl -0x9(%rbp),%eax
cmp    $0x0,%eax
je     117a <chown_tty+0x4a>
lea    0xe8b(%rip),%rdi
call   1030 <fail@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
mov    $0x180,%esi
call   1040 <fchmod@plt>
cmp    $0x0,%rax
je     11b0 <chown_tty+0x80>
movsbl -0x9(%rbp),%eax
cmp    $0x0,%eax
je     11b0 <chown_tty+0x80>
lea    0xe5c(%rip),%rdi
call   1030 <fail@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chown_tty>:
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%edx
mov    %edi,%esi
mov    0x2e9f(%rip),%r14
mov    (%r14),%edi
call   1050 <fchown@plt>
test   %bl,%bl
je     115e <chown_tty+0x2e>
test   %rax,%rax
je     115e <chown_tty+0x2e>
lea    0xea7(%rip),%rdi
call   1030 <fail@plt>
mov    (%r14),%edi
mov    $0x180,%esi
call   1040 <fchmod@plt>
test   %bl,%bl
je     1187 <chown_tty+0x57>
test   %rax,%rax
je     1187 <chown_tty+0x57>
lea    0xe8c(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fail@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@.str = [7 x i8] c"fchown\00"
@.str.1 = [7 x i8] c"fchmod\00"
define void @chown_tty(i32 %0, i32 %1, i8 signext %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8 %2, i8* %6
%7 = load i32, i32* @STDIN_FILENO
%8 = load i32, i32* %4
%9 = load i32, i32* %5
%10 = call i64 @fchown(i32 %7, i32 %8, i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %3
%13 = load i8, i8* %6
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 @fail(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %12, %3
%19 = load i32, i32* @STDIN_FILENO
%20 = call i64 @fchmod(i32 %19, i32 384)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %18
%23 = load i8, i8* %6
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 @fail(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %26, %22, %18
ret void
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@.str = [7 x i8] c"fchown\00"
@.str.1 = [7 x i8] c"fchmod\00"
define void @chown_tty(i32 %0, i32 %1, i8 signext %2) {
%4 = load i32, i32* @STDIN_FILENO
%5 = tail call i64 @fchown(i32 %4, i32 %0, i32 %1)
%6 = icmp ne i64 %5, 0
%7 = icmp ne i8 %2, 0
%8 = and i1 %7, %6
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = tail call i32 @fail(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %3
%12 = load i32, i32* @STDIN_FILENO
%13 = tail call i64 @fchmod(i32 %12, i32 384)
%14 = icmp ne i64 %13, 0
%15 = and i1 %7, %14
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = tail call i32 @fail(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %11
ret void
}