#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 */
int /*<<< orphan*/ _err_exit(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ errno;
unsigned int write(int const, void const *, unsigned int);
void writen(const int fd, const void *buf, unsigned int len) {
  unsigned int n;
  while (len > 0) {
    n = write(fd, buf, len);
    if (n == -1)
      _err_exit(errno,
                "["
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/zh1149277309/fms/refs/heads/"
                "master/client/common.c"
                ",%d] "
                "write",
                35);
    len -= n;
    buf += n;
  }
}


x86 assembly (clang, -O0):
<writen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jbe    1192 <writen+0x72>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1172 <writen+0x52>
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
lea    0xe98(%rip),%rsi
mov    $0x23,%edx
call   1040 <_err_exit@plt>
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,%ecx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    1132 <writen+0x12>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writen>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
je     1183 <writen+0x63>
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %edi,%r14d
mov    0x2ea2(%rip),%r13
lea    0xebb(%rip),%r15
jmp    115b <writen+0x3b>
nopw   0x0(%rax,%rax,1)
mov    %r12d,%eax
add    %rax,%rbx
sub    %r12d,%ebp
je     1183 <writen+0x63>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
mov    %eax,%r12d
cmp    $0xffffffff,%eax
jne    1150 <writen+0x30>
mov    0x0(%r13),%edi
mov    %r15,%rsi
mov    $0x23,%edx
call   1040 <_err_exit@plt>
jmp    1150 <writen+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
@.str = [152 x i8] c"[/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/zh1149277309/fms/refs/heads/master/client/common.c,%d] write\00"
define void @writen(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 = %21, %3
%9 = load i32, i32* %6
%10 = icmp ugt i32 %9, 0
br i1 %10, label %11, label %29
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, -1
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = load i32, i32* @errno
%20 = call i32 @_err_exit(i32 %19, i8* getelementptr inbounds ([152 x i8], [152 x i8]* @.str, i64 0, i64 0), i32 35)
br label %21
21: ; preds = %18, %11
%22 = load i32, i32* %7
%23 = load i32, i32* %6
%24 = sub i32 %23, %22
store i32 %24, i32* %6
%25 = load i32, i32* %7
%26 = load i8*, i8** %5
%27 = zext i32 %25 to i64
%28 = getelementptr i8, i8* %26, i64 %27
store i8* %28, i8** %5
br label %8
29: ; preds = %8
ret void
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [152 x i8] c"[/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/zh1149277309/fms/refs/heads/master/client/common.c,%d] write\00"
define void @writen(i32 %0, i8* nocapture %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %18, label %5
5: ; preds = %3, %13
%6 = phi i8* [ %16, %13 ], [ %1, %3 ]
%7 = phi i32 [ %14, %13 ], [ %2, %3 ]
%8 = tail call i32 @write(i32 %0, i8* %6, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = load i32, i32* @errno
%12 = tail call i32 @_err_exit(i32 %11, i8* getelementptr inbounds ([152 x i8], [152 x i8]* @.str, i64 0, i64 0), i32 35)
br label %13
13: ; preds = %10, %5
%14 = sub i32 %7, %8
%15 = zext i32 %8 to i64
%16 = getelementptr i8, i8* %6, i64 %15
%17 = icmp eq i32 %14, 0
br i1 %17, label %18, label %5
18: ; preds = %13, %3
ret void
}