#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*/ EXIT_FAILURE;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sleep(int);
int write(int, char *, int);
int main(void) {
  int fd = open("/dev/watchdog", O_WRONLY);
  int ret = 0;
  if (fd == -1) {
    perror("watchdog");
    exit(EXIT_FAILURE);
  }
  while (1) {
    ret = write(fd, "\0", 1);
    if (ret != 1) {
      ret = -1;
      break;
    }
    sleep(10);
  }
  close(fd);
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11b2 <main+0x52>
lea    0xe66(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    11b7 <main+0x57>
mov    -0x8(%rbp),%edi
lea    0xe4d(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
je     11e4 <main+0x84>
movl   $0xffffffff,-0xc(%rbp)
jmp    11f3 <main+0x93>
mov    $0xa,%edi
call   1080 <sleep@plt>
jmp    11b7 <main+0x57>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
lea    0xe8c(%rip),%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     11d2 <main+0x72>
mov    %eax,%ebx
lea    0xe87(%rip),%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
jne    11be <main+0x5e>
lea    0xe6f(%rip),%r14
nop
mov    $0xa,%edi
call   1080 <sleep@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
je     11a0 <main+0x40>
mov    %ebx,%edi
call   1040 <close@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe2c(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
call   1070 <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"
@EXIT_FAILURE = global i32 0
@.str.2 = [2 x i8] zeroinitializer
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @O_WRONLY
%5 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %2
store i32 0, i32* %3
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %0
br label %13
13: ; preds = %12, %19
%14 = load i32, i32* %2
%15 = call i32 @write(i32 %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = icmp ne i32 %16, 1
br i1 %17, label %18, label %19
18: ; preds = %13
store i32 -1, i32* %3
br label %21
19: ; preds = %13
%20 = call i32 @sleep(i32 10)
br label %13
21: ; preds = %18
%22 = load i32, i32* %2
%23 = call i32 @close(i32 %22)
%24 = load i32, i32* %3
ret i32 %24
}

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