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

/* Variables and functions */
int E2BIG;
#define EBADF 130
#define EILSEQ 129
#define EINVAL 128
char *_(char *);
int errno;
int /*<<< orphan*/ error(int /*<<< orphan*/, int /*<<< orphan*/, char *, ...);
scalar_t__ ferror(int /*<<< orphan*/ *);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
size_t iconv(int /*<<< orphan*/, char const **, size_t *, char **, size_t *);
int process_block(iconv_t cd, const char *addr, size_t len, FILE *output) {
  const char *start = addr;
  char outbuf[32768];
  char *outptr;
  size_t outlen;
  size_t n;
  while (len > 0) {
    outptr = outbuf;
    outlen = 32768;
    n = iconv(cd, &addr, &len, &outptr, &outlen);
    if (outptr != outbuf) {
      if (fwrite(outbuf, 1, outptr - outbuf, output) < outptr - outbuf ||
          ferror(output)) {
        error(0, 0,
              _("conversion stopped due to problem in writing the output"));
        return -1;
      }
    }
    if (n != (size_t)-1)
      break;
    if (errno != E2BIG) {
      switch (errno) {
      case EILSEQ:
        error(0, 0, _("illegal input sequence at position %ld"), addr - start);
        addr++;
        len--;
        goto cont;
        break;
      case EINVAL:
        error(0, 0,
              _("incomplete character or shift sequence at end of buffer"));
        break;
      case EBADF:
        error(0, 0, _("internal error (illegal descriptor)"));
        break;
      default:
        error(0, 0, _("unknown iconv() error %d"), errno);
        break;
      }
      return -1;
    }
  cont:;
  }
  return 0;
}


x86 assembly (clang, -O0):
<process_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8050,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    1383 <process_block+0x233>
lea    -0x8030(%rbp),%rax
mov    %rax,-0x8038(%rbp)
movq   $0x8000,-0x8040(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x8038(%rbp),%rcx
lea    -0x8040(%rbp),%r8
call   1030 <iconv@plt>
mov    %rax,-0x8048(%rbp)
mov    -0x8038(%rbp),%rax
lea    -0x8030(%rbp),%rcx
cmp    %rcx,%rax
je     1254 <process_block+0x104>
lea    -0x8030(%rbp),%rdi
mov    -0x8038(%rbp),%rax
lea    -0x8030(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
cltq
mov    -0x8038(%rbp),%rcx
lea    -0x8030(%rbp),%rdx
sub    %rdx,%rcx
cmp    %rcx,%rax
jl     1229 <process_block+0xd9>
mov    -0x20(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     124f <process_block+0xff>
lea    0xdd0(%rip),%rdi
call   1050 <_@plt>
mov    %rax,%rdx
xor    %esi,%esi
mov    %esi,%edi
mov    $0x0,%al
call   1060 <error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    138a <process_block+0x23a>
jmp    1254 <process_block+0x104>
cmpq   $0xffffffffffffffff,-0x8048(%rbp)
ff
je     1267 <process_block+0x117>
jmp    1383 <process_block+0x233>
mov    0x2d6a(%rip),%rax
mov    (%rax),%eax
mov    0x2d71(%rip),%rcx
cmp    (%rcx),%eax
je     1379 <process_block+0x229>
mov    0x2d52(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x804c(%rbp)
sub    $0x80,%eax
je     130c <process_block+0x1bc>
jmp    129e <process_block+0x14e>
mov    -0x804c(%rbp),%eax
sub    $0x81,%eax
je     12ca <process_block+0x17a>
jmp    12b4 <process_block+0x164>
mov    -0x804c(%rbp),%eax
sub    $0x82,%eax
je     132b <process_block+0x1db>
jmp    134a <process_block+0x1fa>
lea    0xd67(%rip),%rdi
call   1050 <_@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rcx
mov    -0x28(%rbp),%rax
sub    %rax,%rcx
xor    %esi,%esi
mov    %esi,%edi
mov    $0x0,%al
call   1060 <error@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    137e <process_block+0x22e>
lea    0xd4c(%rip),%rdi
call   1050 <_@plt>
mov    %rax,%rdx
xor    %esi,%esi
mov    %esi,%edi
mov    $0x0,%al
call   1060 <error@plt>
jmp    136d <process_block+0x21d>
lea    0xd65(%rip),%rdi
call   1050 <_@plt>
mov    %rax,%rdx
xor    %esi,%esi
mov    %esi,%edi
mov    $0x0,%al
call   1060 <error@plt>
jmp    136d <process_block+0x21d>
lea    0xd6a(%rip),%rdi
call   1050 <_@plt>
mov    %rax,%rdx
mov    0x2c78(%rip),%rax
mov    (%rax),%ecx
xor    %esi,%esi
mov    %esi,%edi
mov    $0x0,%al
call   1060 <error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    138a <process_block+0x23a>
jmp    137e <process_block+0x22e>
jmp    1172 <process_block+0x22>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x8050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_block>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x8028,%rsp
mov    %rsi,0x10(%rsp)
mov    %rdx,(%rsp)
test   %rdx,%rdx
je     1270 <process_block+0x120>
mov    %rcx,%rbx
mov    %rsi,%r14
mov    %edi,%r15d
lea    0x20(%rsp),%rbp
xor    %r12d,%r12d
jmp    119d <process_block+0x4d>
cs nopw 0x0(%rax,%rax,1)
mov    (%rsp),%rax
test   %rax,%rax
je     12b5 <process_block+0x165>
mov    %rbp,0x8(%rsp)
movq   $0x8000,0x18(%rsp)
mov    %r15d,%edi
lea    0x10(%rsp),%rsi
mov    %rsp,%rdx
lea    0x8(%rsp),%rcx
lea    0x18(%rsp),%r8
call   1030 <iconv@plt>
mov    %rax,%r13
mov    0x8(%rsp),%rdx
cmp    %rbp,%rdx
je     1208 <process_block+0xb8>
sub    %ebp,%edx
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %rbx,%rcx
call   1070 <fwrite@plt>
cltq
mov    0x8(%rsp),%rcx
sub    %rbp,%rcx
cmp    %rax,%rcx
jg     128c <process_block+0x13c>
mov    %rbx,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
jne    128c <process_block+0x13c>
cmp    $0xffffffffffffffff,%r13
jne    12b5 <process_block+0x165>
mov    0x2dbf(%rip),%rax
mov    (%rax),%eax
mov    0x2dc6(%rip),%rcx
cmp    (%rcx),%eax
je     1190 <process_block+0x40>
cmp    $0x81,%eax
jne    1275 <process_block+0x125>
lea    0xe00(%rip),%rdi
call   1050 <_@plt>
mov    0x10(%rsp),%rcx
sub    %r14,%rcx
xor    %edi,%edi
xor    %esi,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <error@plt>
addq   $0x1,0x10(%rsp)
mov    (%rsp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,(%rsp)
test   %rax,%rax
jne    119d <process_block+0x4d>
jmp    12b5 <process_block+0x165>
xor    %r12d,%r12d
jmp    12b5 <process_block+0x165>
cmp    $0x80,%eax
je     1295 <process_block+0x145>
cmp    $0x82,%eax
jne    12ca <process_block+0x17a>
lea    0xe0d(%rip),%rdi
jmp    129c <process_block+0x14c>
lea    0xd6d(%rip),%rdi
jmp    129c <process_block+0x14c>
lea    0xdc3(%rip),%rdi
call   1050 <_@plt>
xor    %edi,%edi
xor    %esi,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <error@plt>
mov    $0xffffffff,%r12d
mov    %r12d,%eax
add    $0x8028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdea(%rip),%rdi
call   1050 <_@plt>
mov    0x2cfb(%rip),%rcx
mov    (%rcx),%ecx
xor    %edi,%edi
xor    %esi,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <error@plt>
jmp    12af <process_block+0x15f>

LLVM IR (-O0):
@.str = [56 x i8] c"conversion stopped due to problem in writing the output\00"
@errno = global i32 0
@E2BIG = global i32 0
@.str.1 = [39 x i8] c"illegal input sequence at position %ld\00"
@.str.2 = [56 x i8] c"incomplete character or shift sequence at end of buffer\00"
@.str.3 = [36 x i8] c"internal error (illegal descriptor)\00"
@.str.4 = [25 x i8] c"unknown iconv() error %d\00"
define i32 @process_block(i32 %0, i8* %1, i64 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca [32768 x i8]
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i64
store i32 %0, i32* %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i32* %3, i32** %9
%15 = load i8*, i8** %7
store i8* %15, i8** %10
br label %16
16: ; preds = %85, %4
%17 = load i64, i64* %8
%18 = icmp ugt i64 %17, 0
br i1 %18, label %19, label %86
19: ; preds = %16
%20 = getelementptr inbounds [32768 x i8], [32768 x i8]* %11, i64 0, i64 0
store i8* %20, i8** %12
store i64 32768, i64* %13
%21 = load i32, i32* %6
%22 = call i64 @iconv(i32 %21, i8** %7, i64* %8, i8** %12, i64* %13)
store i64 %22, i64* %14
%23 = load i8*, i8** %12
%24 = getelementptr inbounds [32768 x i8], [32768 x i8]* %11, i64 0, i64 0
%25 = icmp ne i8* %23, %24
br i1 %25, label %26, label %51
26: ; preds = %19
%27 = getelementptr inbounds [32768 x i8], [32768 x i8]* %11, i64 0, i64 0
%28 = load i8*, i8** %12
%29 = getelementptr inbounds [32768 x i8], [32768 x i8]* %11, i64 0, i64 0
%30 = ptrtoint i8* %28 to i64
%31 = ptrtoint i8* %29 to i64
%32 = sub i64 %30, %31
%33 = trunc i64 %32 to i32
%34 = load i32*, i32** %9
%35 = call i32 @fwrite(i8* %27, i32 1, i32 %33, i32* %34)
%36 = sext i32 %35 to i64
%37 = load i8*, i8** %12
%38 = getelementptr inbounds [32768 x i8], [32768 x i8]* %11, i64 0, i64 0
%39 = ptrtoint i8* %37 to i64
%40 = ptrtoint i8* %38 to i64
%41 = sub i64 %39, %40
%42 = icmp slt i64 %36, %41
br i1 %42, label %47, label %43
43: ; preds = %26
%44 = load i32*, i32** %9
%45 = call i64 @ferror(i32* %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %43, %26
%48 = call i8* @_(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0))
%49 = call i32 (i32, i32, i8*, ...) @error(i32 0, i32 0, i8* %48)
store i32 -1, i32* %5
br label %87
50: ; preds = %43
br label %51
51: ; preds = %50, %19
%52 = load i64, i64* %14
%53 = icmp ne i64 %52, -1
br i1 %53, label %54, label %55
54: ; preds = %51
br label %86
55: ; preds = %51
%56 = load i32, i32* @errno
%57 = load i32, i32* @E2BIG
%58 = icmp ne i32 %56, %57
br i1 %58, label %59, label %84
59: ; preds = %55
%60 = load i32, i32* @errno
switch i32 %60, label %79 [
i32 129, label %61
i32 128, label %73
i32 130, label %76
]
61: ; preds = %59
%62 = call i8* @_(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%63 = load i8*, i8** %7
%64 = load i8*, i8** %10
%65 = ptrtoint i8* %63 to i64
%66 = ptrtoint i8* %64 to i64
%67 = sub i64 %65, %66
%68 = call i32 (i32, i32, i8*, ...) @error(i32 0, i32 0, i8* %62, i64 %67)
%69 = load i8*, i8** %7
%70 = getelementptr inbounds i8, i8* %69, i32 1
store i8* %70, i8** %7
%71 = load i64, i64* %8
%72 = add i64 %71, -1
store i64 %72, i64* %8
br label %85
73: ; preds = %59
%74 = call i8* @_(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0))
%75 = call i32 (i32, i32, i8*, ...) @error(i32 0, i32 0, i8* %74)
br label %83
76: ; preds = %59
%77 = call i8* @_(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%78 = call i32 (i32, i32, i8*, ...) @error(i32 0, i32 0, i8* %77)
br label %83
79: ; preds = %59
%80 = call i8* @_(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%81 = load i32, i32* @errno
%82 = call i32 (i32, i32, i8*, ...) @error(i32 0, i32 0, i8* %80, i32 %81)
br label %83
83: ; preds = %79, %76, %73
store i32 -1, i32* %5
br label %87
84: ; preds = %55
br label %85
85: ; preds = %84, %61
br label %16
86: ; preds = %54, %16
store i32 0, i32* %5
br label %87
87: ; preds = %86, %83, %47
%88 = load i32, i32* %5
ret i32 %88
}

LLVM IR (-O2):
@.str = [56 x i8] c"conversion stopped due to problem in writing the output\00"
@errno = global i32 0
@E2BIG = global i32 0
@.str.1 = [39 x i8] c"illegal input sequence at position %ld\00"
@.str.2 = [56 x i8] c"incomplete character or shift sequence at end of buffer\00"
@.str.3 = [36 x i8] c"internal error (illegal descriptor)\00"
@.str.4 = [25 x i8] c"unknown iconv() error %d\00"
define i32 @process_block(i32 %0, i8* %1, i64 %2, i32* nocapture %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca [32768 x i8]
%8 = alloca i8*
%9 = alloca i64
store i8* %1, i8** %5
store i64 %2, i64* %6
%10 = getelementptr inbounds [32768 x i8], [32768 x i8]* %7, i64 0, i64 0
%11 = bitcast i8** %8 to i8*
%12 = bitcast i64* %9 to i8*
%13 = icmp eq i64 %2, 0
br i1 %13, label %69, label %14
14: ; preds = %4
%15 = ptrtoint [32768 x i8]* %7 to i64
%16 = ptrtoint i8* %1 to i64
br label %17
17: ; preds = %14, %66
store i8* %10, i8** %8
store i64 32768, i64* %9
%18 = call i64 @iconv(i32 %0, i8** %5, i64* %6, i8** %8, i64* %9)
%19 = load i8*, i8** %8
%20 = icmp eq i8* %19, %10
br i1 %20, label %37, label %21
21: ; preds = %17
%22 = ptrtoint i8* %19 to i64
%23 = sub i64 %22, %15
%24 = trunc i64 %23 to i32
%25 = call i32 @fwrite(i8* %10, i32 1, i32 %24, i32* %3)
%26 = sext i32 %25 to i64
%27 = load i8*, i8** %8
%28 = ptrtoint i8* %27 to i64
%29 = sub i64 %28, %15
%30 = icmp sgt i64 %29, %26
br i1 %30, label %34, label %31
31: ; preds = %21
%32 = call i64 @ferror(i32* %3)
%33 = icmp eq i64 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %31, %21
%35 = call i8* @_(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0))
%36 = call i32 (i32, i32, i8*, ...) @error(i32 0, i32 0, i8* %35)
br label %69
37: ; preds = %31, %17
%38 = icmp eq i64 %18, -1
br i1 %38, label %39, label %69
39: ; preds = %37
%40 = load i32, i32* @errno
%41 = load i32, i32* @E2BIG
%42 = icmp eq i32 %40, %41
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = load i64, i64* %6
br label %66
45: ; preds = %39
switch i32 %40, label %62 [
i32 129, label %46
i32 128, label %56
i32 130, label %59
]
46: ; preds = %45
%47 = call i8* @_(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%48 = load i8*, i8** %5
%49 = ptrtoint i8* %48 to i64
%50 = sub i64 %49, %16
%51 = call i32 (i32, i32, i8*, ...) @error(i32 0, i32 0, i8* %47, i64 %50)
%52 = load i8*, i8** %5
%53 = getelementptr inbounds i8, i8* %52, i64 1
store i8* %53, i8** %5
%54 = load i64, i64* %6
%55 = add i64 %54, -1
store i64 %55, i64* %6
br label %66
56: ; preds = %45
%57 = call i8* @_(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0))
%58 = call i32 (i32, i32, i8*, ...) @error(i32 0, i32 0, i8* %57)
br label %69
59: ; preds = %45
%60 = call i8* @_(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%61 = call i32 (i32, i32, i8*, ...) @error(i32 0, i32 0, i8* %60)
br label %69
62: ; preds = %45
%63 = call i8* @_(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%64 = load i32, i32* @errno
%65 = call i32 (i32, i32, i8*, ...) @error(i32 0, i32 0, i8* %63, i32 %64)
br label %69
66: ; preds = %43, %46
%67 = phi i64 [ %44, %43 ], [ %55, %46 ]
%68 = icmp eq i64 %67, 0
br i1 %68, label %69, label %17
69: ; preds = %37, %66, %4, %56, %59, %62, %34
%70 = phi i32 [ -1, %34 ], [ -1, %62 ], [ -1, %59 ], [ -1, %56 ], [ 0, %4 ], [ 0, %66 ], [ 0, %37 ]
ret i32 %70
}