#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*/ TIOCCBRK;
int /*<<< orphan*/ TIOCMGET;
int TIOCM_CAR;
int /*<<< orphan*/ TIOCSBRK;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
void powerkill(int fd) {
  int flags;
  ioctl(fd, TIOCSBRK, 10 * 5);
  sleep(5);
  ioctl(fd, TIOCCBRK, 10 * 5);
  ioctl(fd, TIOCMGET, &flags);
  if (!(flags & TIOCM_CAR)) {
    fprintf(stderr, "kill failed - power is ok\n");
  } else {
    fprintf(stderr, "kill failed - ups did not respond, bad cable?\n");
  }
}


x86 assembly (clang, -O0):
<powerkill>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
mov    $0x32,%edx
mov    $0x0,%al
call   1030 <ioctl@plt>
mov    $0x5,%edi
call   1050 <sleep@plt>
mov    -0x4(%rbp),%edi
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
mov    $0x32,%edx
mov    $0x0,%al
call   1030 <ioctl@plt>
mov    -0x4(%rbp),%edi
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
mov    $0x0,%al
call   1030 <ioctl@plt>
mov    -0x8(%rbp),%eax
mov    0x2e4a(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    11bb <powerkill+0x8b>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe4f(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11d0 <powerkill+0xa0>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
call   1040 <fprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<powerkill>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
mov    $0x32,%edx
xor    %eax,%eax
call   1030 <ioctl@plt>
mov    $0x5,%edi
call   1050 <sleep@plt>
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    $0x32,%edx
xor    %eax,%eax
call   1030 <ioctl@plt>
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <ioctl@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%eax
and    0xc(%rsp),%eax
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
lea    0xe5f(%rip),%rax
lea    0xe73(%rip),%rsi
cmove  %rax,%rsi
call   1040 <fprintf@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@TIOCSBRK = global i32 0
@TIOCCBRK = global i32 0
@TIOCMGET = global i32 0
@TIOCM_CAR = global i32 0
@stderr = global i32 0
@.str = [27 x i8] c"kill failed - power is ok\0A\00"
@.str.1 = [47 x i8] c"kill failed - ups did not respond, bad cable?\0A\00"
define void @powerkill(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = load i32, i32* @TIOCSBRK
%6 = call i32 (i32, i32, ...) @ioctl(i32 %4, i32 %5, i32 50)
%7 = call i32 @sleep(i32 5)
%8 = load i32, i32* %2
%9 = load i32, i32* @TIOCCBRK
%10 = call i32 (i32, i32, ...) @ioctl(i32 %8, i32 %9, i32 50)
%11 = load i32, i32* %2
%12 = load i32, i32* @TIOCMGET
%13 = call i32 (i32, i32, ...) @ioctl(i32 %11, i32 %12, i32* %3)
%14 = load i32, i32* %3
%15 = load i32, i32* @TIOCM_CAR
%16 = and i32 %14, %15
%17 = icmp ne i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %1
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %24
21: ; preds = %1
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %21, %18
ret void
}

LLVM IR (-O2):
@TIOCSBRK = global i32 0
@TIOCCBRK = global i32 0
@TIOCMGET = global i32 0
@TIOCM_CAR = global i32 0
@stderr = global i32 0
@.str = [27 x i8] c"kill failed - power is ok\0A\00"
@.str.1 = [47 x i8] c"kill failed - ups did not respond, bad cable?\0A\00"
define void @powerkill(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = load i32, i32* @TIOCSBRK
%5 = tail call i32 (i32, i32, ...) @ioctl(i32 %0, i32 %4, i32 50)
%6 = tail call i32 @sleep(i32 5)
%7 = load i32, i32* @TIOCCBRK
%8 = tail call i32 (i32, i32, ...) @ioctl(i32 %0, i32 %7, i32 50)
%9 = load i32, i32* @TIOCMGET
%10 = call i32 (i32, i32, ...) @ioctl(i32 %0, i32 %9, i32* %2)
%11 = load i32, i32* %2
%12 = load i32, i32* @TIOCM_CAR
%13 = and i32 %12, %11
%14 = icmp eq i32 %13, 0
%15 = load i32, i32* @stderr
%16 = select i1 %14, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0)
%17 = call i32 @fprintf(i32 %15, i8* %16)
ret void
}