#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 N_HDLC;
int /*<<< orphan*/ TIOCSETD;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ get_master_slave(int *, int *);
scalar_t__ ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ stderr;
int main() {
  int master, slave;
  int disc = N_HDLC;
  if (get_master_slave(&master, &slave) < 0) {
    fprintf(stderr, "Can't get a master/slave pair\n");
    return -1;
  }
  if (ioctl(master, TIOCSETD, &disc) < 0) {
    return -1;
  }
  close(master);
  close(slave);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
lea    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1030 <get_master_slave@plt>
cmp    $0x0,%rax
jge    1193 <main+0x53>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d5 <main+0x95>
mov    -0x8(%rbp),%edi
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    11be <main+0x7e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d5 <main+0x95>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
mov    0x2e9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
lea    0xc(%rsp),%rdi
lea    0x14(%rsp),%rsi
call   1030 <get_master_slave@plt>
test   %rax,%rax
js     119a <main+0x5a>
mov    0xc(%rsp),%edi
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
call   1040 <ioctl@plt>
test   %rax,%rax
js     11af <main+0x6f>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
mov    0x14(%rsp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@N_HDLC = global i32 0
@stderr = global i32 0
@.str = [31 x i8] c"Can't get a master/slave pair\0A\00"
@TIOCSETD = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @N_HDLC
store i32 %5, i32* %4
%6 = call i64 @get_master_slave(i32* %2, i32* %3)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %22
11: ; preds = %0
%12 = load i32, i32* %2
%13 = load i32, i32* @TIOCSETD
%14 = call i64 @ioctl(i32 %12, i32 %13, i32* %4)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %11
store i32 -1, i32* %1
br label %22
17: ; preds = %11
%18 = load i32, i32* %2
%19 = call i32 @close(i32 %18)
%20 = load i32, i32* %3
%21 = call i32 @close(i32 %20)
store i32 0, i32* %1
br label %22
22: ; preds = %17, %16, %8
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@N_HDLC = global i32 0
@stderr = global i32 0
@.str = [31 x i8] c"Can't get a master/slave pair\0A\00"
@TIOCSETD = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = load i32, i32* @N_HDLC
store i32 %7, i32* %3
%8 = call i64 @get_master_slave(i32* %1, i32* %2)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %23
13: ; preds = %0
%14 = load i32, i32* %1
%15 = load i32, i32* @TIOCSETD
%16 = call i64 @ioctl(i32 %14, i32 %15, i32* %3)
%17 = icmp slt i64 %16, 0
br i1 %17, label %23, label %18
18: ; preds = %13
%19 = load i32, i32* %1
%20 = call i32 @close(i32 %19)
%21 = load i32, i32* %2
%22 = call i32 @close(i32 %21)
br label %23
23: ; preds = %13, %18, %10
%24 = phi i32 [ -1, %10 ], [ 0, %18 ], [ -1, %13 ]
ret i32 %24
}