#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_RDWR;
int /*<<< orphan*/ WDIOC_GETTIMELEFT;
int /*<<< orphan*/ WDIOC_KEEPALIVE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int ii = 10, j;
  int fd = open("/dev/watchdog", O_RDWR);
  if (fd == -1) {
    perror("watchdog");
    exit(EXIT_FAILURE);
  }
  printf("Open window watchdog ok\n");
  while (1) {
    do {
      ioctl(fd, WDIOC_GETTIMELEFT, &j);
    } while (j != 0);
    if (ii-- > 0) {
      printf("ii = %d\n", ii);
      ioctl(fd, WDIOC_KEEPALIVE, 0);
    }
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xa,-0x8(%rbp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
lea    0xe8a(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    11a2 <main+0x52>
lea    0xe76(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b5 <main+0x65>
mov    -0x10(%rbp),%edi
mov    0x2e09(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdx
call   1040 <ioctl@plt>
cmpl   $0x0,-0xc(%rbp)
jne    11b5 <main+0x65>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
jle    120e <main+0xbe>
mov    -0x8(%rbp),%esi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%edi
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <ioctl@plt>
jmp    11b0 <main+0x60>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
lea    0xe85(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11f3 <main+0x93>
mov    %eax,%ebx
lea    0xe89(%rip),%rdi
call   1030 <puts@plt>
mov    $0xa,%r15d
mov    0x2e28(%rip),%rbp
lea    0x4(%rsp),%r14
mov    0x2e34(%rip),%r13
nopl   0x0(%rax)
mov    0x0(%rbp),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1050 <ioctl@plt>
cmpl   $0x0,0x4(%rsp)
jne    11b0 <main+0x50>
lea    -0x1(%r15),%r12d
test   %r15d,%r15d
mov    %r12d,%r15d
jle    11b0 <main+0x50>
lea    0xe37(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1050 <ioctl@plt>
mov    %r12d,%r15d
jmp    11b0 <main+0x50>
lea    0xe0b(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"/dev/watchdog\00"
@O_RDWR = global i32 0
@.str.1 = [9 x i8] c"watchdog\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [25 x i8] c"Open window watchdog ok\0A\00"
@WDIOC_GETTIMELEFT = global i32 0
@.str.3 = [9 x i8] c"ii = %d\0A\00"
@WDIOC_KEEPALIVE = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 10, i32* %2
%5 = load i32, i32* @O_RDWR
%6 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %13, %33
br label %16
16: ; preds = %20, %15
%17 = load i32, i32* %4
%18 = load i32, i32* @WDIOC_GETTIMELEFT
%19 = call i32 @ioctl(i32 %17, i32 %18, i32* %3)
br label %20
20: ; preds = %16
%21 = load i32, i32* %3
%22 = icmp ne i32 %21, 0
br i1 %22, label %16, label %23
23: ; preds = %20
%24 = load i32, i32* %2
%25 = add nsw i32 %24, -1
store i32 %25, i32* %2
%26 = icmp sgt i32 %24, 0
br i1 %26, label %27, label %33
27: ; preds = %23
%28 = load i32, i32* %2
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %4
%31 = load i32, i32* @WDIOC_KEEPALIVE
%32 = call i32 @ioctl(i32 %30, i32 %31, i32* null)
br label %33
33: ; preds = %27, %23
br label %15
}

LLVM IR (-O2):
@.str = [14 x i8] c"/dev/watchdog\00"
@O_RDWR = global i32 0
@.str.1 = [9 x i8] c"watchdog\00"
@EXIT_FAILURE = global i32 0
@WDIOC_GETTIMELEFT = global i32 0
@.str.3 = [9 x i8] c"ii = %d\0A\00"
@WDIOC_KEEPALIVE = global i32 0
@str = [24 x i8] c"Open window watchdog ok\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %0
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %12
12: ; preds = %26, %10
%13 = phi i32 [ 10, %10 ], [ %20, %26 ]
br label %14
14: ; preds = %14, %12
%15 = load i32, i32* @WDIOC_GETTIMELEFT
%16 = call i32 @ioctl(i32 %4, i32 %15, i32* %1)
%17 = load i32, i32* %1
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %14
19: ; preds = %14
%20 = add nsw i32 %13, -1
%21 = icmp sgt i32 %13, 0
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %20)
%24 = load i32, i32* @WDIOC_KEEPALIVE
%25 = call i32 @ioctl(i32 %4, i32 %24, i32* null)
br label %26
26: ; preds = %22, %19
br label %12
}