#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*/ Close(int);
int Write(int, char *, unsigned int);
int /*<<< orphan*/ assert(int);
int data_producer(int argl, void *args) {
  assert(argl == sizeof(int));
  int nbytes = *(int *)args;
  int i = 0;
  Close(0);
  char buffer[32768];
  while (nbytes > 0) {
    unsigned int n = (nbytes < 32768) ? nbytes : 32768;
    int rc = Write(1, buffer, n);
    assert(rc > 0);
    nbytes -= rc;
    i++;
  }
  Close(1);
  return 0;
}


x86 assembly (clang, -O0):
<data_producer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8030,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movslq -0x4(%rbp),%rax
cmp    $0x4,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
xor    %edi,%edi
call   1050 <Close@plt>
cmpl   $0x0,-0x14(%rbp)
jle    11fc <data_producer+0xcc>
cmpl   $0x8000,-0x14(%rbp)
jge    1193 <data_producer+0x63>
mov    -0x14(%rbp),%eax
mov    %eax,-0x802c(%rbp)
jmp    11a3 <data_producer+0x73>
mov    $0x8000,%eax
mov    %eax,-0x802c(%rbp)
jmp    11a3 <data_producer+0x73>
mov    -0x802c(%rbp),%eax
mov    %eax,-0x8024(%rbp)
lea    -0x8020(%rbp),%rsi
mov    -0x8024(%rbp),%edx
mov    $0x1,%edi
call   1030 <Write@plt>
mov    %eax,-0x8028(%rbp)
cmpl   $0x0,-0x8028(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8028(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    116e <data_producer+0x3e>
mov    $0x1,%edi
call   1050 <Close@plt>
xor    %eax,%eax
add    $0x8030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<data_producer>:
push   %rbp
push   %r14
push   %rbx
sub    $0x8000,%rsp
mov    %rsi,%rbx
xor    %eax,%eax
cmp    $0x4,%edi
sete   %al
mov    %eax,%edi
call   1040 <assert@plt>
mov    (%rbx),%ebx
xor    %edi,%edi
call   1050 <Close@plt>
test   %ebx,%ebx
jle    118e <data_producer+0x5e>
mov    %rsp,%r14
nopl   (%rax)
cmp    $0x8000,%ebx
mov    $0x8000,%edx
cmovb  %ebx,%edx
mov    $0x1,%edi
mov    %r14,%rsi
call   1030 <Write@plt>
mov    %eax,%ebp
xor    %edi,%edi
test   %eax,%eax
setg   %dil
call   1040 <assert@plt>
sub    %ebp,%ebx
jg     1160 <data_producer+0x30>
mov    $0x1,%edi
call   1050 <Close@plt>
xor    %eax,%eax
add    $0x8000,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @data_producer(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [32768 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = icmp eq i64 %11, 4
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i8*, i8** %4
%16 = bitcast i8* %15 to i32*
%17 = load i32, i32* %16
store i32 %17, i32* %5
store i32 0, i32* %6
%18 = call i32 @Close(i32 0)
br label %19
19: ; preds = %28, %2
%20 = load i32, i32* %5
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %42
22: ; preds = %19
%23 = load i32, i32* %5
%24 = icmp slt i32 %23, 32768
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = load i32, i32* %5
br label %28
27: ; preds = %22
br label %28
28: ; preds = %27, %25
%29 = phi i32 [ %26, %25 ], [ 32768, %27 ]
store i32 %29, i32* %8
%30 = getelementptr inbounds [32768 x i8], [32768 x i8]* %7, i64 0, i64 0
%31 = load i32, i32* %8
%32 = call i32 @Write(i32 1, i8* %30, i32 %31)
store i32 %32, i32* %9
%33 = load i32, i32* %9
%34 = icmp sgt i32 %33, 0
%35 = zext i1 %34 to i32
%36 = call i32 @assert(i32 %35)
%37 = load i32, i32* %9
%38 = load i32, i32* %5
%39 = sub nsw i32 %38, %37
store i32 %39, i32* %5
%40 = load i32, i32* %6
%41 = add nsw i32 %40, 1
store i32 %41, i32* %6
br label %19
42: ; preds = %19
%43 = call i32 @Close(i32 1)
ret i32 0
}

LLVM IR (-O2):
define i32 @data_producer(i32 %0, i8* nocapture %1) {
%3 = alloca [32768 x i8]
%4 = icmp eq i32 %0, 4
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = bitcast i8* %1 to i32*
%8 = load i32, i32* %7
%9 = tail call i32 @Close(i32 0)
%10 = getelementptr inbounds [32768 x i8], [32768 x i8]* %3, i64 0, i64 0
%11 = icmp sgt i32 %8, 0
br i1 %11, label %12, label %22
12: ; preds = %2, %12
%13 = phi i32 [ %20, %12 ], [ %8, %2 ]
%14 = icmp ult i32 %13, 32768
%15 = select i1 %14, i32 %13, i32 32768
%16 = call i32 @Write(i32 1, i8* %10, i32 %15)
%17 = icmp sgt i32 %16, 0
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = sub nsw i32 %13, %16
%21 = icmp sgt i32 %20, 0
br i1 %21, label %12, label %22
22: ; preds = %12, %2
%23 = call i32 @Close(i32 1)
ret i32 0
}