#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 /*<<< orphan*/ EAGAIN;
int /*<<< orphan*/ EINTR;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ hwp_client_close();
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int write(int, char *, int);
void put_hwp_rsp_char(int fd, char c) {
  if (-1 == fd) {
    fprintf(
        stderr,
        "Warning: Attempt to write '%c' to unopened HWP RSP client: Ignored\n",
        c);
    return;
  }
  while (1) {
    switch (write(fd, &c, sizeof(c))) {
    case -1:
      if ((EAGAIN != errno) && (EINTR != errno)) {
        fprintf(stderr,
                "Warning: Failed to write to HWP RSP client: Closing client "
                "connection: %s\n",
                strerror(errno));
        hwp_client_close();
        return;
      }
      break;
    case 0:
      break;
    default:
      return;
    }
  }
}


x86 assembly (clang, -O0):
<put_hwp_rsp_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
mov    $0xffffffff,%eax
cmp    -0x4(%rbp),%eax
jne    117f <put_hwp_rsp_char+0x3f>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
movsbl -0x5(%rbp),%edx
lea    0xe8d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1236 <put_hwp_rsp_char+0xf6>
jmp    1184 <put_hwp_rsp_char+0x44>
mov    -0x4(%rbp),%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
sub    $0xffffffff,%eax
je     11b8 <put_hwp_rsp_char+0x78>
jmp    11a8 <put_hwp_rsp_char+0x68>
mov    -0xc(%rbp),%eax
test   %eax,%eax
je     1227 <put_hwp_rsp_char+0xe7>
jmp    122c <put_hwp_rsp_char+0xec>
mov    0x2e01(%rip),%rax
mov    (%rax),%eax
mov    0x2e10(%rip),%rcx
cmp    (%rcx),%eax
je     1222 <put_hwp_rsp_char+0xe2>
mov    0x2df9(%rip),%rax
mov    (%rax),%eax
mov    0x2df8(%rip),%rcx
cmp    (%rcx),%eax
je     1222 <put_hwp_rsp_char+0xe2>
mov    0x2df1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x10(%rbp),%edi
mov    %rax,%rdx
lea    0xe35(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1040 <hwp_client_close@plt>
jmp    1236 <put_hwp_rsp_char+0xf6>
jmp    1231 <put_hwp_rsp_char+0xf1>
jmp    1231 <put_hwp_rsp_char+0xf1>
jmp    1236 <put_hwp_rsp_char+0xf6>
jmp    1184 <put_hwp_rsp_char+0x44>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<put_hwp_rsp_char>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %sil,0xf(%rsp)
cmp    $0xffffffff,%edi
je     11dc <put_hwp_rsp_char+0x9c>
mov    %edi,%ebx
lea    0xf(%rsp),%r14
mov    0x2e57(%rip),%r15
mov    0x2e68(%rip),%r12
mov    0x2e59(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
test   %eax,%eax
je     1180 <put_hwp_rsp_char+0x40>
cmp    $0xffffffff,%eax
jne    1204 <put_hwp_rsp_char+0xc4>
mov    (%r12),%edi
cmp    %edi,(%r15)
je     1180 <put_hwp_rsp_char+0x40>
cmp    %edi,0x0(%r13)
je     1180 <put_hwp_rsp_char+0x40>
mov    0x2e32(%rip),%rax
mov    (%rax),%ebx
call   1060 <strerror@plt>
lea    0xe88(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <hwp_client_close@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
movsbl %sil,%edx
lea    0xe10(%rip),%rsi
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1050 <fprintf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [68 x i8] c"Warning: Attempt to write '%c' to unopened HWP RSP client: Ignored\0A\00"
@EAGAIN = global i32 0
@errno = global i32 0
@EINTR = global i32 0
@.str.1 = [75 x i8] c"Warning: Failed to write to HWP RSP client: Closing client connection: %s\0A\00"
define void @put_hwp_rsp_char(i32 %0, i8 signext %1) {
%3 = alloca i32
%4 = alloca i8
store i32 %0, i32* %3
store i8 %1, i8* %4
%5 = load i32, i32* %3
%6 = icmp eq i32 -1, %5
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i8, i8* %4
%10 = sext i8 %9 to i32
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %34
12: ; preds = %2
br label %13
13: ; preds = %12, %33
%14 = load i32, i32* %3
%15 = call i32 @write(i32 %14, i8* %4, i32 1)
switch i32 %15, label %32 [
i32 -1, label %16
i32 0, label %31
]
16: ; preds = %13
%17 = load i32, i32* @EAGAIN
%18 = load i32, i32* @errno
%19 = icmp ne i32 %17, %18
br i1 %19, label %20, label %30
20: ; preds = %16
%21 = load i32, i32* @EINTR
%22 = load i32, i32* @errno
%23 = icmp ne i32 %21, %22
br i1 %23, label %24, label %30
24: ; preds = %20
%25 = load i32, i32* @stderr
%26 = load i32, i32* @errno
%27 = call i8* @strerror(i32 %26)
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = call i32 (...) @hwp_client_close()
br label %34
30: ; preds = %20, %16
br label %33
31: ; preds = %13
br label %33
32: ; preds = %13
br label %34
33: ; preds = %31, %30
br label %13
34: ; preds = %32, %24, %7
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [68 x i8] c"Warning: Attempt to write '%c' to unopened HWP RSP client: Ignored\0A\00"
@EAGAIN = global i32 0
@errno = global i32 0
@EINTR = global i32 0
@.str.1 = [75 x i8] c"Warning: Failed to write to HWP RSP client: Closing client connection: %s\0A\00"
define void @put_hwp_rsp_char(i32 %0, i8 signext %1) {
%3 = alloca i8
store i8 %1, i8* %3
%4 = icmp eq i32 %0, -1
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = sext i8 %1 to i32
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %24
9: ; preds = %2, %18
%10 = call i32 @write(i32 %0, i8* %3, i32 1)
switch i32 %10, label %24 [
i32 -1, label %11
i32 0, label %18
]
11: ; preds = %9
%12 = load i32, i32* @EAGAIN
%13 = load i32, i32* @errno
%14 = icmp eq i32 %12, %13
%15 = load i32, i32* @EINTR
%16 = icmp eq i32 %15, %13
%17 = select i1 %14, i1 true, i1 %16
br i1 %17, label %18, label %19
18: ; preds = %11, %9
br label %9
19: ; preds = %11
%20 = load i32, i32* @stderr
%21 = tail call i8* @strerror(i32 %13)
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = tail call i32 (...) @hwp_client_close()
br label %24
24: ; preds = %9, %19, %5
ret void
}