#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ assert(int);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ tolower(int);
void chunk_readcallback(FILE *in, char *obuff, size_t size) {
  char *buff;
  int c;
  assert(in != NULL);
  assert(obuff != NULL);
  assert(size > 0);
  buff = obuff;
  *buff = '\0';
  while (size) {
    c = fgetc(in);
    if (c == EOF)
      return;
    if (c == '}') {
      c = fgetc(in);
      if (c == EOF)
        return;
      if (c == '%')
        return;
      *buff++ = '}';
    }
    *buff++ = tolower(c);
    *buff = '\0';
    size--;
  }
  assert((size_t)(buff - obuff) < size);
  return;
}


x86 assembly (clang, -O0):
<chunk_readcallback>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
cmpq   $0x0,-0x18(%rbp)
je     1238 <chunk_readcallback+0x108>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e3e(%rip),%rcx
cmp    (%rcx),%eax
jne    11b7 <chunk_readcallback+0x87>
jmp    1254 <chunk_readcallback+0x124>
cmpl   $0x7d,-0x24(%rbp)
jne    1205 <chunk_readcallback+0xd5>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e11(%rip),%rcx
cmp    (%rcx),%eax
jne    11e4 <chunk_readcallback+0xb4>
jmp    1254 <chunk_readcallback+0x124>
cmpl   $0x25,-0x24(%rbp)
jne    11f3 <chunk_readcallback+0xc3>
jmp    1254 <chunk_readcallback+0x124>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x7d,(%rax)
mov    -0x24(%rbp),%edi
call   1050 <tolower@plt>
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1189 <chunk_readcallback+0x59>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
cmp    -0x18(%rbp),%rax
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chunk_readcallback>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1040 <assert@plt>
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1040 <assert@plt>
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1040 <assert@plt>
movb   $0x0,(%rbx)
test   %r15,%r15
je     11c6 <chunk_readcallback+0x96>
mov    0x2e6e(%rip),%r12
jmp    1197 <chunk_readcallback+0x67>
nopl   0x0(%rax)
mov    %eax,%edi
call   1050 <tolower@plt>
mov    %al,(%rbx)
movb   $0x0,0x1(%rbx)
add    $0x1,%rbx
add    $0xffffffffffffffff,%r15
je     11c6 <chunk_readcallback+0x96>
mov    %r14,%rdi
call   1030 <fgetc@plt>
cmp    (%r12),%eax
je     11d8 <chunk_readcallback+0xa8>
cmp    $0x7d,%eax
jne    1180 <chunk_readcallback+0x50>
mov    %r14,%rdi
call   1030 <fgetc@plt>
cmp    $0x25,%eax
je     11d8 <chunk_readcallback+0xa8>
cmp    (%r12),%eax
je     11d8 <chunk_readcallback+0xa8>
movb   $0x7d,(%rbx)
add    $0x1,%rbx
jmp    1180 <chunk_readcallback+0x50>
xor    %edi,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <assert@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EOF = global i32 0
define void @chunk_readcallback(i32* %0, i8* %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%9 = load i32*, i32** %4
%10 = icmp ne i32* %9, null
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i64, i64* %6
%18 = icmp ugt i64 %17, 0
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i8*, i8** %5
store i8* %21, i8** %7
%22 = load i8*, i8** %7
store i8 0, i8* %22
br label %23
23: ; preds = %50, %3
%24 = load i64, i64* %6
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %59
26: ; preds = %23
%27 = load i32*, i32** %4
%28 = call i32 @fgetc(i32* %27)
store i32 %28, i32* %8
%29 = load i32, i32* %8
%30 = load i32, i32* @EOF
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %33
32: ; preds = %26
br label %69
33: ; preds = %26
%34 = load i32, i32* %8
%35 = icmp eq i32 %34, 125
br i1 %35, label %36, label %50
36: ; preds = %33
%37 = load i32*, i32** %4
%38 = call i32 @fgetc(i32* %37)
store i32 %38, i32* %8
%39 = load i32, i32* %8
%40 = load i32, i32* @EOF
%41 = icmp eq i32 %39, %40
br i1 %41, label %42, label %43
42: ; preds = %36
br label %69
43: ; preds = %36
%44 = load i32, i32* %8
%45 = icmp eq i32 %44, 37
br i1 %45, label %46, label %47
46: ; preds = %43
br label %69
47: ; preds = %43
%48 = load i8*, i8** %7
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %7
store i8 125, i8* %48
br label %50
50: ; preds = %47, %33
%51 = load i32, i32* %8
%52 = call i32 @tolower(i32 %51)
%53 = trunc i32 %52 to i8
%54 = load i8*, i8** %7
%55 = getelementptr inbounds i8, i8* %54, i32 1
store i8* %55, i8** %7
store i8 %53, i8* %54
%56 = load i8*, i8** %7
store i8 0, i8* %56
%57 = load i64, i64* %6
%58 = add i64 %57, -1
store i64 %58, i64* %6
br label %23
59: ; preds = %23
%60 = load i8*, i8** %7
%61 = load i8*, i8** %5
%62 = ptrtoint i8* %60 to i64
%63 = ptrtoint i8* %61 to i64
%64 = sub i64 %62, %63
%65 = load i64, i64* %6
%66 = icmp ult i64 %64, %65
%67 = zext i1 %66 to i32
%68 = call i32 @assert(i32 %67)
br label %69
69: ; preds = %59, %46, %42, %32
ret void
}

LLVM IR (-O2):
@EOF = global i32 0
define void @chunk_readcallback(i32* %0, i8* writeonly %1, i64 %2) {
%4 = icmp ne i32* %0, null
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = icmp ne i8* %1, null
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = icmp ne i64 %2, 0
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
store i8 0, i8* %1
%13 = icmp eq i64 %2, 0
br i1 %13, label %38, label %14
14: ; preds = %3, %30
%15 = phi i8* [ %35, %30 ], [ %1, %3 ]
%16 = phi i64 [ %36, %30 ], [ %2, %3 ]
%17 = tail call i32 @fgetc(i32* %0)
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %40, label %20
20: ; preds = %14
%21 = icmp eq i32 %17, 125
br i1 %21, label %22, label %30
22: ; preds = %20
%23 = tail call i32 @fgetc(i32* %0)
%24 = load i32, i32* @EOF
%25 = icmp eq i32 %23, %24
%26 = icmp eq i32 %23, 37
%27 = or i1 %26, %25
br i1 %27, label %40, label %28
28: ; preds = %22
%29 = getelementptr inbounds i8, i8* %15, i64 1
store i8 125, i8* %15
br label %30
30: ; preds = %28, %20
%31 = phi i8* [ %29, %28 ], [ %15, %20 ]
%32 = phi i32 [ %23, %28 ], [ %17, %20 ]
%33 = tail call i32 @tolower(i32 %32)
%34 = trunc i32 %33 to i8
%35 = getelementptr inbounds i8, i8* %31, i64 1
store i8 %34, i8* %31
store i8 0, i8* %35
%36 = add i64 %16, -1
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %14
38: ; preds = %30, %3
%39 = tail call i32 @assert(i32 0)
br label %40
40: ; preds = %22, %14, %38
ret void
}