#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 scalar_t__ ssize_t;

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
scalar_t__ write(int, char const *, size_t);
ssize_t Writen(int sockfd, const void *buf, size_t nbytes) {
  size_t nleft;
  ssize_t nwritten;
  const char *ptr;
  ptr = buf;
  nleft = nbytes;
  while (nleft > 0) {
    if ((nwritten = write(sockfd, ptr, nbytes)) <= 0) {
      if (nwritten < 0 && errno == EINTR)
        nwritten = 0;
      else {
        fprintf(stderr, "%s:%d: Writen(): %s\n",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/Ricky-Gong/LegoCar/refs/"
                "heads/master/CarServer/self/nano_spec/wrap.c",
                21, strerror(errno));
        exit(1);
      }
    }
    nleft -= nwritten;
    ptr += nwritten;
  }
  return nbytes;
}


x86 assembly (clang, -O0):
<Writen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jbe    1226 <Writen+0xe6>
mov    -0x4(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <write@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jg     1206 <Writen+0xc6>
cmpq   $0x0,-0x28(%rbp)
jge    11be <Writen+0x7e>
mov    0x2e3a(%rip),%rax
mov    (%rax),%rax
mov    0x2e28(%rip),%rcx
cmp    (%rcx),%rax
jne    11be <Writen+0x7e>
movq   $0x0,-0x28(%rbp)
jmp    1201 <Writen+0xc1>
mov    0x2e1b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2e07(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%r8
lea    0xe1a(%rip),%rsi
lea    0xe28(%rip),%rdx
mov    $0x15,%ecx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    1206 <Writen+0xc6>
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1163 <Writen+0x23>
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Writen>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
test   %rdx,%rdx
je     119a <Writen+0x5a>
mov    %rsi,%rbx
mov    %edi,%r13d
mov    0x2e78(%rip),%r15
mov    0x2e69(%rip),%r12
mov    %r14,%rbp
jmp    1178 <Writen+0x38>
nopl   0x0(%rax)
add    %rax,%rbx
sub    %rax,%rbp
je     119a <Writen+0x5a>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <write@plt>
test   %rax,%rax
jg     1170 <Writen+0x30>
mov    (%r15),%rdi
je     11ac <Writen+0x6c>
cmp    (%r12),%rdi
jne    11ac <Writen+0x6c>
xor    %eax,%eax
jmp    1170 <Writen+0x30>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e2d(%rip),%rax
mov    (%rax),%ebx
call   1060 <strerror@plt>
lea    0xe3f(%rip),%rsi
lea    0xe4d(%rip),%rdx
mov    %ebx,%edi
mov    $0x15,%ecx
mov    %rax,%r8
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
@stderr = global i32 0
@.str = [21 x i8] c"%s:%d: Writen(): %s\0A\00"
@.str.1 = [159 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Ricky-Gong/LegoCar/refs/heads/master/CarServer/self/nano_spec/wrap.c\00"
define i64 @Writen(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%10 = load i8*, i8** %5
store i8* %10, i8** %9
%11 = load i64, i64* %6
store i64 %11, i64* %7
br label %12
12: ; preds = %36, %3
%13 = load i64, i64* %7
%14 = icmp ugt i64 %13, 0
br i1 %14, label %15, label %43
15: ; preds = %12
%16 = load i32, i32* %4
%17 = load i8*, i8** %9
%18 = load i64, i64* %6
%19 = call i64 @write(i32 %16, i8* %17, i64 %18)
store i64 %19, i64* %8
%20 = icmp sle i64 %19, 0
br i1 %20, label %21, label %36
21: ; preds = %15
%22 = load i64, i64* %8
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = load i64, i64* @errno
%26 = load i64, i64* @EINTR
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %24
store i64 0, i64* %8
br label %35
29: ; preds = %24, %21
%30 = load i32, i32* @stderr
%31 = load i64, i64* @errno
%32 = call i8* @strerror(i64 %31)
%33 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([159 x i8], [159 x i8]* @.str.1, i64 0, i64 0), i32 21, i8* %32)
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %28
br label %36
36: ; preds = %35, %15
%37 = load i64, i64* %8
%38 = load i64, i64* %7
%39 = sub i64 %38, %37
store i64 %39, i64* %7
%40 = load i64, i64* %8
%41 = load i8*, i8** %9
%42 = getelementptr inbounds i8, i8* %41, i64 %40
store i8* %42, i8** %9
br label %12
43: ; preds = %12
%44 = load i64, i64* %6
ret i64 %44
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
@stderr = global i32 0
@.str = [21 x i8] c"%s:%d: Writen(): %s\0A\00"
@.str.1 = [159 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Ricky-Gong/LegoCar/refs/heads/master/CarServer/self/nano_spec/wrap.c\00"
define i64 @Writen(i32 %0, i8* nocapture %1, i64 returned %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %26, label %5
5: ; preds = %3, %21
%6 = phi i8* [ %24, %21 ], [ %1, %3 ]
%7 = phi i64 [ %23, %21 ], [ %2, %3 ]
%8 = tail call i64 @write(i32 %0, i8* %6, i64 %2)
%9 = icmp slt i64 %8, 1
br i1 %9, label %10, label %21
10: ; preds = %5
%11 = icmp ne i64 %8, 0
%12 = load i64, i64* @errno
%13 = load i64, i64* @EINTR
%14 = icmp eq i64 %12, %13
%15 = select i1 %11, i1 %14, i1 false
br i1 %15, label %21, label %16
16: ; preds = %10
%17 = load i32, i32* @stderr
%18 = tail call i8* @strerror(i64 %12)
%19 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([159 x i8], [159 x i8]* @.str.1, i64 0, i64 0), i32 21, i8* %18)
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %10, %5
%22 = phi i64 [ %8, %5 ], [ 0, %10 ]
%23 = sub i64 %7, %22
%24 = getelementptr inbounds i8, i8* %6, i64 %22
%25 = icmp eq i64 %23, 0
br i1 %25, label %26, label %5
26: ; preds = %21, %3
ret i64 %2
}