#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 O_NONBLOCK;
int O_RDWR;
int /*<<< orphan*/ WDIOC_SETTIMEOUT;
unsigned int atoi(char *);
int /*<<< orphan*/ close(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, unsigned int *);
int open(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(unsigned int);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd;
  unsigned int timeout = 90;
  unsigned int sleeptime = 10;
  int ret = 0;
  if (argc == 2)
    timeout = atoi(argv[1]);
  fd = open("/dev/watchdog", O_RDWR | O_NONBLOCK);
  if (fd == -1) {
    printf("ERROR: Aero watchdog daemon: Open watchdog device node failed\n");
    return -1;
  }
  if (ioctl(fd, WDIOC_SETTIMEOUT, &timeout)) {
    printf("ERROR: Aero watchdog daemon: Set time out failed\n");
    return -1;
  }
  while (1) {
    ret = write(fd, "\0", 1);
    if (ret != 1) {
      printf("ERROR: Keep Alive write to watchdog device file failed!\n");
      ret = -1;
      break;
    }
    sleep(sleeptime);
  }
  close(fd);
  return ret;
}


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)
movl   $0x5a,-0x18(%rbp)
movl   $0xa,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11b5 <main+0x45>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
mov    0x2e1b(%rip),%rax
or     (%rax),%esi
lea    0xe32(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11f8 <main+0x88>
lea    0xe27(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1288 <main+0x118>
mov    -0x14(%rbp),%edi
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
je     122f <main+0xbf>
lea    0xe2f(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1288 <main+0x118>
jmp    1234 <main+0xc4>
mov    -0x14(%rbp),%edi
lea    0xe7a(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
je     126d <main+0xfd>
lea    0xe23(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x20(%rbp)
jmp    127a <main+0x10a>
mov    -0x1c(%rbp),%edi
call   1090 <sleep@plt>
jmp    1234 <main+0xc4>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
movl   $0x5a,0x4(%rsp)
cmp    $0x2,%edi
jne    118e <main+0x1e>
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,0x4(%rsp)
mov    0x2e53(%rip),%rax
mov    0x2e44(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe59(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11d6 <main+0x66>
mov    %eax,%ebx
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
call   1050 <ioctl@plt>
test   %rax,%rax
je     11e4 <main+0x74>
lea    0xe72(%rip),%rdi
jmp    11dd <main+0x6d>
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
jmp    1241 <main+0xd1>
lea    0xeca(%rip),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0x1,%eax
jne    122e <main+0xbe>
lea    0xeb2(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0xa,%edi
call   1090 <sleep@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0x1,%eax
je     1210 <main+0xa0>
lea    0xdd9(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/dev/watchdog\00"
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [63 x i8] c"ERROR: Aero watchdog daemon: Open watchdog device node failed\0A\00"
@WDIOC_SETTIMEOUT = global i32 0
@.str.2 = [50 x i8] c"ERROR: Aero watchdog daemon: Set time out failed\0A\00"
@.str.3 = [2 x i8] zeroinitializer
@.str.4 = [57 x i8] c"ERROR: Keep Alive write to watchdog device file failed!\0A\00"
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
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 90, i32* %7
store i32 10, i32* %8
store i32 0, i32* %9
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 2
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %7
br label %17
17: ; preds = %12, %2
%18 = load i32, i32* @O_RDWR
%19 = load i32, i32* @O_NONBLOCK
%20 = or i32 %18, %19
%21 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %17
%25 = call i32 @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %48
26: ; preds = %17
%27 = load i32, i32* %6
%28 = load i32, i32* @WDIOC_SETTIMEOUT
%29 = call i64 @ioctl(i32 %27, i32 %28, i32* %7)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %48
33: ; preds = %26
br label %34
34: ; preds = %33, %41
%35 = load i32, i32* %6
%36 = call i32 @write(i32 %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
store i32 %36, i32* %9
%37 = load i32, i32* %9
%38 = icmp ne i32 %37, 1
br i1 %38, label %39, label %41
39: ; preds = %34
%40 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %9
br label %44
41: ; preds = %34
%42 = load i32, i32* %8
%43 = call i32 @sleep(i32 %42)
br label %34
44: ; preds = %39
%45 = load i32, i32* %6
%46 = call i32 @close(i32 %45)
%47 = load i32, i32* %9
store i32 %47, i32* %3
br label %48
48: ; preds = %44, %31, %24
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@.str = [14 x i8] c"/dev/watchdog\00"
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@WDIOC_SETTIMEOUT = global i32 0
@.str.3 = [2 x i8] zeroinitializer
@str = [56 x i8] c"ERROR: Keep Alive write to watchdog device file failed!\00"
@str.5 = [49 x i8] c"ERROR: Aero watchdog daemon: Set time out failed\00"
@str.6 = [62 x i8] c"ERROR: Aero watchdog daemon: Open watchdog device node failed\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 90, i32* %3
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
store i32 %9, i32* %3
br label %10
10: ; preds = %6, %2
%11 = load i32, i32* @O_RDWR
%12 = load i32, i32* @O_NONBLOCK
%13 = or i32 %12, %11
%14 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @str.6, i64 0, i64 0))
br label %34
18: ; preds = %10
%19 = load i32, i32* @WDIOC_SETTIMEOUT
%20 = call i64 @ioctl(i32 %14, i32 %19, i32* %3)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = call i32 @write(i32 %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
%24 = icmp eq i32 %23, 1
br i1 %24, label %30, label %27
25: ; preds = %18
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str.5, i64 0, i64 0))
br label %34
27: ; preds = %30, %22
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str, i64 0, i64 0))
%29 = call i32 @close(i32 %14)
br label %34
30: ; preds = %22, %30
%31 = call i32 @sleep(i32 10)
%32 = call i32 @write(i32 %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
%33 = icmp eq i32 %32, 1
br i1 %33, label %30, label %27
34: ; preds = %27, %25, %16
ret i32 -1
}