#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__ calloc(size_t, size_t);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ stderr;
scalar_t__ write(int, unsigned char *, int);
void write_next_comment(int fd, const char *comment, int len, int loc) {
  if (len > 0)
    do {
      if (((len) > 0) && (write(fd, (unsigned char *)comment, len) == 0))
        fprintf(stderr, "header write error");
    } while (0);
  len = loc - (len + 24);
  if (len > 0) {
    unsigned char *combuf;
    combuf = (unsigned char *)calloc((size_t)(len), (size_t)(sizeof(char)));
    do {
      if (((len) > 0) && (write(fd, combuf, len) == 0))
        fprintf(stderr, "header write error");
    } while (0);
    free(combuf);
  }
}


x86 assembly (clang, -O0):
<write_next_comment>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11a6 <write_next_comment+0x66>
jmp    1164 <write_next_comment+0x24>
cmpl   $0x0,-0x14(%rbp)
jle    119c <write_next_comment+0x5c>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <write@plt>
cmp    $0x0,%rax
jne    119c <write_next_comment+0x5c>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
call   1060 <fprintf@plt>
jmp    11a1 <write_next_comment+0x61>
jmp    11a6 <write_next_comment+0x66>
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    $0x18,%ecx
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1216 <write_next_comment+0xd6>
movslq -0x14(%rbp),%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1208 <write_next_comment+0xc8>
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <write@plt>
cmp    $0x0,%rax
jne    1208 <write_next_comment+0xc8>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
lea    0xdfd(%rip),%rsi
call   1060 <fprintf@plt>
jmp    120d <write_next_comment+0xcd>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_next_comment>:
push   %rbp
push   %r14
push   %rbx
mov    %ecx,%ebx
mov    %edx,%ebp
mov    %edi,%r14d
test   %edx,%edx
jle    1173 <write_next_comment+0x33>
mov    %r14d,%edi
mov    %ebp,%edx
call   1040 <write@plt>
test   %rax,%rax
jne    1173 <write_next_comment+0x33>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
lea    0xe92(%rip),%rsi
call   1060 <fprintf@plt>
sub    %ebp,%ebx
add    $0xffffffe8,%ebx
test   %ebx,%ebx
jle    11be <write_next_comment+0x7e>
mov    %ebx,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%rbp
mov    %r14d,%edi
mov    %rax,%rsi
mov    %ebx,%edx
call   1040 <write@plt>
test   %rax,%rax
jne    11b2 <write_next_comment+0x72>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
lea    0xe53(%rip),%rsi
call   1060 <fprintf@plt>
mov    %rbp,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <free@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [19 x i8] c"header write error\00"
define void @write_next_comment(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i32, i32* %7
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %27
12: ; preds = %4
br label %13
13: ; preds = %12
%14 = load i32, i32* %7
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %25
16: ; preds = %13
%17 = load i32, i32* %5
%18 = load i8*, i8** %6
%19 = load i32, i32* %7
%20 = call i64 @write(i32 %17, i8* %18, i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %22, %16, %13
br label %26
26: ; preds = %25
br label %27
27: ; preds = %26, %4
%28 = load i32, i32* %8
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 24
%31 = sub nsw i32 %28, %30
store i32 %31, i32* %7
%32 = load i32, i32* %7
%33 = icmp sgt i32 %32, 0
br i1 %33, label %34, label %55
34: ; preds = %27
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = call i64 @calloc(i64 %36, i64 1)
%38 = inttoptr i64 %37 to i8*
store i8* %38, i8** %9
br label %39
39: ; preds = %34
%40 = load i32, i32* %7
%41 = icmp sgt i32 %40, 0
br i1 %41, label %42, label %51
42: ; preds = %39
%43 = load i32, i32* %5
%44 = load i8*, i8** %9
%45 = load i32, i32* %7
%46 = call i64 @write(i32 %43, i8* %44, i32 %45)
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %42
%49 = load i32, i32* @stderr
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %51
51: ; preds = %48, %42, %39
br label %52
52: ; preds = %51
%53 = load i8*, i8** %9
%54 = call i32 @free(i8* %53)
br label %55
55: ; preds = %52, %27
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [19 x i8] c"header write error\00"
define void @write_next_comment(i32 %0, i8* nocapture %1, i32 %2, i32 %3) {
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %12
6: ; preds = %4
%7 = tail call i64 @write(i32 %0, i8* %1, i32 %2)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %9, %6, %4
%13 = sub i32 -24, %2
%14 = add i32 %13, %3
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %27
16: ; preds = %12
%17 = zext i32 %14 to i64
%18 = tail call i64 @calloc(i64 %17, i64 1)
%19 = inttoptr i64 %18 to i8*
%20 = tail call i64 @write(i32 %0, i8* %19, i32 %14)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = load i32, i32* @stderr
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %22, %16
%26 = tail call i32 @free(i8* %19)
br label %27
27: ; preds = %25, %12
ret void
}