#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 */
struct timespec {
  int tv_sec;
  int tv_nsec;
};

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
int /*<<< orphan*/ lwwire_reset();
scalar_t__ nanosleep(struct timespec *, struct timespec *);
void lwwire_protoerror(void) {
  struct timespec sltime;
  struct timespec rtime;
  sltime.tv_sec = 1;
  sltime.tv_nsec = 100000000;
  while (nanosleep(&sltime, &rtime) < 0) {
    if (errno != EINTR)
      break;
    sltime = rtime;
  }
  lwwire_reset();
}


x86 assembly (clang, -O0):
<lwwire_protoerror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x1,-0x8(%rbp)
movl   $0x5f5e100,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <nanosleep@plt>
cmp    $0x0,%rax
jge    1179 <lwwire_protoerror+0x59>
mov    0x2e8c(%rip),%rax
mov    (%rax),%rax
mov    0x2e7a(%rip),%rcx
cmp    (%rcx),%rax
je     116c <lwwire_protoerror+0x4c>
jmp    1179 <lwwire_protoerror+0x59>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1136 <lwwire_protoerror+0x16>
mov    $0x0,%al
call   1030 <lwwire_reset@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lwwire_protoerror>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movabs $0x5f5e10000000001,%rax
e1 f5 05
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1040 <nanosleep@plt>
test   %rax,%rax
jns    1193 <lwwire_protoerror+0x73>
mov    0x2e8b(%rip),%r15
mov    0x2e7c(%rip),%r12
lea    0x8(%rsp),%r14
lea    0x10(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    (%r15),%rax
cmp    (%r12),%rax
jne    1193 <lwwire_protoerror+0x73>
mov    0x10(%rsp),%rax
mov    %rax,0x8(%rsp)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <nanosleep@plt>
test   %rax,%rax
js     1170 <lwwire_protoerror+0x50>
xor    %eax,%eax
call   1030 <lwwire_reset@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@errno = global i64 0
@EINTR = global i64 0
define void @lwwire_protoerror() {
%1 = alloca %struct.timespec
%2 = alloca %struct.timespec
%3 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 0
store i32 1, i32* %3
%4 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 1
store i32 100000000, i32* %4
br label %5
5: ; preds = %13, %0
%6 = call i64 @nanosleep(%struct.timespec* %1, %struct.timespec* %2)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %5
%9 = load i64, i64* @errno
%10 = load i64, i64* @EINTR
%11 = icmp ne i64 %9, %10
br i1 %11, label %12, label %13
12: ; preds = %8
br label %16
13: ; preds = %8
%14 = bitcast %struct.timespec* %1 to i8*
%15 = bitcast %struct.timespec* %2 to i8*
br label %5
16: ; preds = %12, %5
%17 = call i32 (...) @lwwire_reset()
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@errno = global i64 0
@EINTR = global i64 0
define void @lwwire_protoerror() {
%1 = alloca i64
%2 = bitcast i64* %1 to %struct.timespec*
%3 = alloca i64
%4 = bitcast i64* %3 to %struct.timespec*
%5 = bitcast i64* %1 to i8*
%6 = bitcast i64* %3 to i8*
%7 = bitcast i64* %1 to i32*
store i32 1, i32* %7
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
store i32 100000000, i32* %8
%9 = call i64 @nanosleep(%struct.timespec* %2, %struct.timespec* %4)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %0, %15
%12 = load i64, i64* @errno
%13 = load i64, i64* @EINTR
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = load i64, i64* %3
store i64 %16, i64* %1
%17 = call i64 @nanosleep(%struct.timespec* %2, %struct.timespec* %4)
%18 = icmp slt i64 %17, 0
br i1 %18, label %11, label %19
19: ; preds = %15, %11, %0
%20 = call i32 (...) @lwwire_reset()
ret void
}