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

/* Variables and functions */
int EIO;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ printk(char *, int, int /*<<< orphan*/);
int write(int, char *, int);
int ping_watchdog(int fd) {
  int n;
  char c = '\n';
  n = write(fd, &c, sizeof(c));
  if (n != sizeof(c)) {
    printk("ping_watchdog - write failed, ret = %d, err = %d\n", n, errno);
    if (n < 0)
      return n;
    return -EIO;
  }
  return 1;
}


x86 assembly (clang, -O0):
<ping_watchdog>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movb   $0xa,-0xd(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rax
cmp    $0x1,%rax
je     1191 <ping_watchdog+0x71>
mov    -0xc(%rbp),%esi
mov    0x2e7d(%rip),%rax
mov    (%rax),%edx
lea    0xe9c(%rip),%rdi
call   1030 <printk@plt>
cmpl   $0x0,-0xc(%rbp)
jge    117e <ping_watchdog+0x5e>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1198 <ping_watchdog+0x78>
xor    %eax,%eax
mov    0x2e59(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1198 <ping_watchdog+0x78>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ping_watchdog>:
push   %rbp
push   %rbx
push   %rax
movb   $0xa,0x7(%rsp)
lea    0x7(%rsp),%rsi
mov    $0x1,%ebx
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0x1,%eax
je     116b <ping_watchdog+0x4b>
mov    %eax,%ebp
mov    0x2e8e(%rip),%rax
mov    (%rax),%edx
lea    0xead(%rip),%rdi
mov    %ebp,%esi
call   1030 <printk@plt>
mov    %ebp,%ebx
test   %ebp,%ebp
js     116b <ping_watchdog+0x4b>
mov    0x2e79(%rip),%rax
xor    %ebx,%ebx
sub    (%rax),%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [50 x i8] c"ping_watchdog - write failed, ret = %d, err = %d\0A\00"
@errno = global i32 0
@EIO = global i32 0
define i32 @ping_watchdog(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
store i32 %0, i32* %3
store i8 10, i8* %5
%6 = load i32, i32* %3
%7 = call i32 @write(i32 %6, i8* %5, i32 1)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = sext i32 %8 to i64
%10 = icmp ne i64 %9, 1
br i1 %10, label %11, label %22
11: ; preds = %1
%12 = load i32, i32* %4
%13 = load i32, i32* @errno
%14 = call i32 @printk(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %13)
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = load i32, i32* %4
store i32 %18, i32* %2
br label %23
19: ; preds = %11
%20 = load i32, i32* @EIO
%21 = sub nsw i32 0, %20
store i32 %21, i32* %2
br label %23
22: ; preds = %1
store i32 1, i32* %2
br label %23
23: ; preds = %22, %19, %17
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@.str = [50 x i8] c"ping_watchdog - write failed, ret = %d, err = %d\0A\00"
@errno = global i32 0
@EIO = global i32 0
define i32 @ping_watchdog(i32 %0) {
%2 = alloca i8
store i8 10, i8* %2
%3 = call i32 @write(i32 %0, i8* %2, i32 1)
%4 = icmp eq i32 %3, 1
br i1 %4, label %12, label %5
5: ; preds = %1
%6 = load i32, i32* @errno
%7 = tail call i32 @printk(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %6)
%8 = icmp slt i32 %3, 0
br i1 %8, label %12, label %9
9: ; preds = %5
%10 = load i32, i32* @EIO
%11 = sub nsw i32 0, %10
br label %12
12: ; preds = %1, %5, %9
%13 = phi i32 [ %11, %9 ], [ %3, %5 ], [ 1, %1 ]
ret i32 %13
}