#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*/ AUDIO_CLEAR_BUFFER;
int /*<<< orphan*/ VIDEO_CLEAR_BUFFER;
int ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int deviceClear(int afd, int vfd) {
  int ans;
  if (vfd >= 0) {
    if ((ans = ioctl(vfd, VIDEO_CLEAR_BUFFER, 0)) < 0) {
      perror("VIDEO CLEAR BUFFER: ");
      return -1;
    }
  }
  if (afd >= 0) {
    if ((ans = ioctl(afd, AUDIO_CLEAR_BUFFER, 0)) < 0) {
      perror("AUDIO CLEAR BUFFER: ");
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<deviceClear>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     1174 <deviceClear+0x54>
mov    -0xc(%rbp),%edi
mov    0x2ea6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <ioctl@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jge    116f <deviceClear+0x4f>
lea    0xea2(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c1 <deviceClear+0xa1>
jmp    1174 <deviceClear+0x54>
cmpl   $0x0,-0x8(%rbp)
jl     11ba <deviceClear+0x9a>
mov    -0x8(%rbp),%edi
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <ioctl@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jge    11b5 <deviceClear+0x95>
lea    0xe71(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c1 <deviceClear+0xa1>
jmp    11ba <deviceClear+0x9a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<deviceClear>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
test   %esi,%esi
js     1141 <deviceClear+0x21>
mov    0x2eb8(%rip),%rax
mov    (%rax),%eax
mov    %esi,%edi
mov    %eax,%esi
xor    %edx,%edx
call   1030 <ioctl@plt>
test   %eax,%eax
js     1171 <deviceClear+0x51>
test   %ebx,%ebx
js     1166 <deviceClear+0x46>
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
xor    %ebp,%ebp
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <ioctl@plt>
test   %eax,%eax
jns    1168 <deviceClear+0x48>
lea    0xeb1(%rip),%rdi
jmp    1178 <deviceClear+0x58>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe88(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%ebp
jmp    1168 <deviceClear+0x48>

LLVM IR (-O0):
@VIDEO_CLEAR_BUFFER = global i32 0
@.str = [21 x i8] c"VIDEO CLEAR BUFFER: \00"
@AUDIO_CLEAR_BUFFER = global i32 0
@.str.1 = [21 x i8] c"AUDIO CLEAR BUFFER: \00"
define i32 @deviceClear(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = icmp sge i32 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %2
%10 = load i32, i32* %5
%11 = load i32, i32* @VIDEO_CLEAR_BUFFER
%12 = call i32 @ioctl(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %6
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %29
16: ; preds = %9
br label %17
17: ; preds = %16, %2
%18 = load i32, i32* %4
%19 = icmp sge i32 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %17
%21 = load i32, i32* %4
%22 = load i32, i32* @AUDIO_CLEAR_BUFFER
%23 = call i32 @ioctl(i32 %21, i32 %22, i32 0)
store i32 %23, i32* %6
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %29
27: ; preds = %20
br label %28
28: ; preds = %27, %17
store i32 0, i32* %3
br label %29
29: ; preds = %28, %25, %14
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@VIDEO_CLEAR_BUFFER = global i32 0
@.str = [21 x i8] c"VIDEO CLEAR BUFFER: \00"
@AUDIO_CLEAR_BUFFER = global i32 0
@.str.1 = [21 x i8] c"AUDIO CLEAR BUFFER: \00"
define i32 @deviceClear(i32 %0, i32 %1) {
%3 = icmp sgt i32 %1, -1
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @VIDEO_CLEAR_BUFFER
%6 = tail call i32 @ioctl(i32 %1, i32 %5, i32 0)
%7 = icmp slt i32 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %4, %2
%9 = icmp sgt i32 %0, -1
br i1 %9, label %10, label %17
10: ; preds = %8
%11 = load i32, i32* @AUDIO_CLEAR_BUFFER
%12 = tail call i32 @ioctl(i32 %0, i32 %11, i32 0)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %10, %4
%15 = phi i8* [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), %4 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), %10 ]
%16 = tail call i32 @perror(i8* %15)
br label %17
17: ; preds = %14, %8, %10
%18 = phi i32 [ 0, %10 ], [ 0, %8 ], [ -1, %14 ]
ret i32 %18
}