#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*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ ioctl(int, int, int *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sleep(int);
int main(int argc, const char *argv[]) {
  int fd = open("/dev/watchdog", O_WRONLY);
  if (fd == 1) {
    perror("watchdog");
    exit(1);
  }
  int timeout = 4;
  ioctl(fd, 2, &timeout);
  while (1) {
    ioctl(fd, 1, 0);
    sleep(1);
  }
  close(fd);
}


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)
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
lea    0xe8a(%rip),%rdi
call   1040 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    119e <main+0x4e>
lea    0xe76(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movl   $0x4,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x2,%esi
lea    -0x18(%rbp),%rdx
call   1030 <ioctl@plt>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <ioctl@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
jmp    11b6 <main+0x66>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
lea    0xe9b(%rip),%rdi
call   1040 <open@plt>
cmp    $0x1,%eax
je     11aa <main+0x5a>
mov    %eax,%ebx
movl   $0x4,0xc(%rsp)
lea    0xc(%rsp),%rdx
mov    %eax,%edi
mov    $0x2,%esi
call   1030 <ioctl@plt>
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1030 <ioctl@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
jmp    1190 <main+0x40>
lea    0xe54(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"/dev/watchdog\00"
@O_WRONLY = global i32 0
@.str.1 = [9 x i8] c"watchdog\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @O_WRONLY
%9 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
store i32 4, i32* %7
%16 = load i32, i32* %6
%17 = call i32 @ioctl(i32 %16, i32 2, i32* %7)
br label %18
18: ; preds = %15, %18
%19 = load i32, i32* %6
%20 = call i32 @ioctl(i32 %19, i32 1, i32* null)
%21 = call i32 @sleep(i32 1)
br label %18
}

LLVM IR (-O2):
@.str = [14 x i8] c"/dev/watchdog\00"
@O_WRONLY = global i32 0
@.str.1 = [9 x i8] c"watchdog\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = load i32, i32* @O_WRONLY
%5 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = bitcast i32* %3 to i8*
store i32 4, i32* %3
%12 = call i32 @ioctl(i32 %5, i32 2, i32* %3)
br label %13
13: ; preds = %13, %10
%14 = call i32 @ioctl(i32 %5, i32 1, i32* null)
%15 = call i32 @sleep(i32 1)
br label %13
}