#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 */
scalar_t__ EINTR;
int /*<<< orphan*/ _exit(int);
scalar_t__ errno;
int write(int, char *, int);
void s_write(int fd, char *s, int n) {
  int w;
  while (n) {
    w = write(fd, s, n);
    if (w == 0)
      _exit(1);
    if (w == -1) {
      if (errno == EINTR)
        continue;
      _exit(1);
    }
    s += w;
    n -= w;
  }
}


x86 assembly (clang, -O0):
<s_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11b6 <s_write+0x96>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1162 <s_write+0x42>
mov    $0x1,%edi
call   1030 <_exit@plt>
cmpl   $0xffffffff,-0x18(%rbp)
jne    1195 <s_write+0x75>
mov    0x2e6d(%rip),%rax
mov    (%rax),%rax
mov    0x2e5b(%rip),%rcx
cmp    (%rcx),%rax
jne    118b <s_write+0x6b>
jmp    1132 <s_write+0x12>
mov    $0x1,%edi
call   1030 <_exit@plt>
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    1132 <s_write+0x12>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<s_write>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edx,%edx
je     1179 <s_write+0x59>
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %edi,%r14d
mov    0x2ea5(%rip),%r15
mov    0x2e96(%rip),%r12
jmp    1159 <s_write+0x39>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r15),%rax
cmp    (%r12),%rax
jne    1182 <s_write+0x62>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     1150 <s_write+0x30>
test   %eax,%eax
je     1182 <s_write+0x62>
movslq %eax,%rcx
add    %rcx,%rbx
sub    %eax,%ebp
jne    1159 <s_write+0x39>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
define void @s_write(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
br label %8
8: ; preds = %30, %27, %3
%9 = load i32, i32* %6
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %38
11: ; preds = %8
%12 = load i32, i32* %4
%13 = load i8*, i8** %5
%14 = load i32, i32* %6
%15 = call i32 @write(i32 %12, i8* %13, i32 %14)
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %11
%19 = call i32 @_exit(i32 1)
unreachable
20: ; preds = %11
%21 = load i32, i32* %7
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %30
23: ; preds = %20
%24 = load i64, i64* @errno
%25 = load i64, i64* @EINTR
%26 = icmp eq i64 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %23
br label %8
28: ; preds = %23
%29 = call i32 @_exit(i32 1)
unreachable
30: ; preds = %20
%31 = load i32, i32* %7
%32 = load i8*, i8** %5
%33 = sext i32 %31 to i64
%34 = getelementptr inbounds i8, i8* %32, i64 %33
store i8* %34, i8** %5
%35 = load i32, i32* %7
%36 = load i32, i32* %6
%37 = sub nsw i32 %36, %35
store i32 %37, i32* %6
br label %8
38: ; preds = %8
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
define void @s_write(i32 %0, i8* nocapture %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %23, label %5
5: ; preds = %3, %18
%6 = phi i8* [ %20, %18 ], [ %1, %3 ]
%7 = phi i32 [ %21, %18 ], [ %2, %3 ]
br label %8
8: ; preds = %5, %12
%9 = tail call i32 @write(i32 %0, i8* %6, i32 %7)
switch i32 %9, label %18 [
i32 0, label %10
i32 -1, label %12
]
10: ; preds = %8
%11 = tail call i32 @_exit(i32 1)
unreachable
12: ; preds = %8
%13 = load i64, i64* @errno
%14 = load i64, i64* @EINTR
%15 = icmp eq i64 %13, %14
br i1 %15, label %8, label %16
16: ; preds = %12
%17 = tail call i32 @_exit(i32 1)
unreachable
18: ; preds = %8
%19 = sext i32 %9 to i64
%20 = getelementptr inbounds i8, i8* %6, i64 %19
%21 = sub nsw i32 %7, %9
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %5
23: ; preds = %18, %3
ret void
}