#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*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ _IOR(char, int, int /*<<< orphan*/);
int /*<<< orphan*/ __u32;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int fd;
  int result;
  uint32_t state;
  fd = open("/dev/"
            "niwatchdog",
            0);
  if (fd < 0) {
    fprintf(stderr, "Could not open watchdog device.\n");
    return -1;
  }
  result = ioctl(fd, _IOR('W', 6, __u32), &state);
  return result;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rdi
xor    %esi,%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1192 <main+0x52>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
lea    0xe8f(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c7 <main+0x87>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
mov    $0x57,%edi
mov    $0x6,%esi
call   1050 <_IOR@plt>
mov    -0x20(%rbp),%edi
mov    %eax,%esi
lea    -0x1c(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xeb4(%rip),%rdi
xor    %esi,%esi
call   1060 <open@plt>
test   %eax,%eax
js     1181 <main+0x41>
mov    %eax,%ebx
mov    0x2e78(%rip),%rax
mov    (%rax),%edx
mov    $0x57,%edi
mov    $0x6,%esi
call   1050 <_IOR@plt>
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
mov    %eax,%esi
call   1030 <ioctl@plt>
jmp    119b <main+0x5b>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
lea    0xe7f(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"/dev/niwatchdog\00"
@stderr = global i32 0
@.str.1 = [33 x i8] c"Could not open watchdog device.\0A\00"
@__u32 = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 0)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %21
15: ; preds = %2
%16 = load i32, i32* %6
%17 = load i32, i32* @__u32
%18 = call i32 @_IOR(i8 signext 87, i32 6, i32 %17)
%19 = call i32 @ioctl(i32 %16, i32 %18, i32* %8)
store i32 %19, i32* %7
%20 = load i32, i32* %7
store i32 %20, i32* %3
br label %21
21: ; preds = %15, %12
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
@.str = [16 x i8] c"/dev/niwatchdog\00"
@stderr = global i32 0
@.str.1 = [33 x i8] c"Could not open watchdog device.\0A\00"
@__u32 = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 0)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %14
10: ; preds = %2
%11 = load i32, i32* @__u32
%12 = tail call i32 @_IOR(i8 signext 87, i32 6, i32 %11)
%13 = call i32 @ioctl(i32 %5, i32 %12, i32* %3)
br label %14
14: ; preds = %10, %7
%15 = phi i32 [ -1, %7 ], [ %13, %10 ]
ret i32 %15
}