#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_thread_exit(int const, 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_thread_exit(fd, errno,
                       "["
                       "/scratch/repos/new/home/jordi_armengol_estape/"
                       "c-scraper/outputs/2022-01-22/02-19-57/repos/"
                       "zh1149277309/fms/refs/heads/master/server/common.c"
                       ",%d] "
                       "write",
                       36);
    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    1195 <writen+0x75>
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    1175 <writen+0x55>
mov    -0x4(%rbp),%edi
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
lea    0xe95(%rip),%rdx
mov    $0x24,%ecx
call   1040 <_err_thread_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     1186 <writen+0x66>
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     1186 <writen+0x66>
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),%esi
mov    %r14d,%edi
mov    %r15,%rdx
mov    $0x24,%ecx
call   1040 <_err_thread_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/server/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 = %22, %3
%9 = load i32, i32* %6
%10 = icmp ugt i32 %9, 0
br i1 %10, label %11, label %30
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 %22
18: ; preds = %11
%19 = load i32, i32* %4
%20 = load i32, i32* @errno
%21 = call i32 @_err_thread_exit(i32 %19, i32 %20, i8* getelementptr inbounds ([152 x i8], [152 x i8]* @.str, i64 0, i64 0), i32 36)
br label %22
22: ; preds = %18, %11
%23 = load i32, i32* %7
%24 = load i32, i32* %6
%25 = sub i32 %24, %23
store i32 %25, i32* %6
%26 = load i32, i32* %7
%27 = load i8*, i8** %5
%28 = zext i32 %26 to i64
%29 = getelementptr i8, i8* %27, i64 %28
store i8* %29, i8** %5
br label %8
30: ; 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/server/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_thread_exit(i32 %0, i32 %11, i8* getelementptr inbounds ([152 x i8], [152 x i8]* @.str, i64 0, i64 0), i32 36)
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
}