#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 scalar_t__ iconv_t;

/* Variables and functions */
scalar_t__ E2BIG;
char *alloca(size_t);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
int iconv(scalar_t__, char **, size_t *, char **, size_t *);
int /*<<< orphan*/ iconv_close(scalar_t__);
scalar_t__ iconv_open(char *, char const *);
int /*<<< orphan*/ stderr;
void test(const char *encoding, char *inbuf, size_t inbufsize,
          size_t outbufsize) {
  char *outbuf = alloca(outbufsize);
  iconv_t cd;
  char *inptr;
  size_t inlen;
  char *outptr;
  size_t outlen;
  int result;
  bool empty_input;
  bool empty_output;
  cd = iconv_open("UTF-8", encoding);
  if (cd == (iconv_t)-1) {
    fprintf(stderr, "cannot convert from %s\n", encoding);
    exit(1);
  }
  inptr = inbuf;
  inlen = inbufsize;
  outptr = outbuf;
  outlen = outbufsize;
  result = iconv(cd, &inptr, &inlen, &outptr, &outlen);
  if (!(result == -1 && errno == E2BIG)) {
    fprintf(stderr, "%s: wrong iconv result: %d/%d (%m)\n", encoding, result,
            errno);
    exit(1);
  }
  empty_input = (inptr == inbuf && inlen == inbufsize);
  empty_output = (outptr == outbuf && outlen == outbufsize);
  if (!empty_input && empty_output) {
    fprintf(stderr, "%s: ate %td input bytes\n", encoding, inptr - inbuf);
    exit(1);
  }
  if (empty_input && !empty_output) {
    fprintf(stderr, "%s: produced %td output bytes\n", encoding,
            outptr - outbuf);
    exit(1);
  }
  iconv_close(cd);
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <alloca@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe70(%rip),%rdi
call   1080 <iconv_open@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0xffffffffffffffff,-0x30(%rbp)
jne    11c9 <test+0x69>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe4e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
lea    -0x40(%rbp),%rdx
lea    -0x48(%rbp),%rcx
lea    -0x50(%rbp),%r8
call   1030 <iconv@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0xffffffff,-0x54(%rbp)
jne    1229 <test+0xc9>
mov    0x2dba(%rip),%rax
mov    (%rax),%rax
mov    0x2dc8(%rip),%rcx
cmp    (%rcx),%rax
je     125b <test+0xfb>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x54(%rbp),%ecx
mov    0x2d90(%rip),%rax
mov    (%rax),%r8
lea    0xdd4(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x38(%rbp),%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x5d(%rbp)
jne    127c <test+0x11c>
mov    -0x40(%rbp),%rax
cmp    -0x18(%rbp),%rax
sete   %al
mov    %al,-0x5d(%rbp)
mov    -0x5d(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x58(%rbp)
mov    -0x48(%rbp),%rcx
xor    %eax,%eax
cmp    -0x28(%rbp),%rcx
mov    %al,-0x5e(%rbp)
jne    12a8 <test+0x148>
mov    -0x50(%rbp),%rax
cmp    -0x20(%rbp),%rax
sete   %al
mov    %al,-0x5e(%rbp)
mov    -0x5e(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x58(%rbp)
jne    12f7 <test+0x197>
cmpl   $0x0,-0x5c(%rbp)
je     12f7 <test+0x197>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x10(%rbp),%rax
sub    %rax,%rcx
lea    0xd5c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpl   $0x0,-0x58(%rbp)
je     133b <test+0x1db>
cmpl   $0x0,-0x5c(%rbp)
jne    133b <test+0x1db>
mov    0x2cc6(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    -0x28(%rbp),%rax
sub    %rax,%rcx
lea    0xd31(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x30(%rbp),%rdi
call   1060 <iconv_close@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%rbp
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rcx,%rdi
call   1050 <alloca@plt>
mov    %rax,%r12
lea    0xe74(%rip),%rdi
mov    %r14,%rsi
call   1080 <iconv_open@plt>
cmp    $0xffffffffffffffff,%rax
je     1239 <test+0xd9>
mov    %rax,%r13
mov    %r15,0x20(%rsp)
mov    %rbx,0x18(%rsp)
mov    %r12,0x10(%rsp)
mov    %rbp,0x8(%rsp)
lea    0x20(%rsp),%rsi
lea    0x18(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0x8(%rsp),%r8
mov    %rax,%rdi
call   1030 <iconv@plt>
mov    0x2df8(%rip),%rcx
mov    (%rcx),%r8
cmp    $0xffffffff,%eax
jne    125d <test+0xfd>
mov    0x2e01(%rip),%rcx
cmp    (%rcx),%r8
jne    125d <test+0xfd>
mov    0x20(%rsp),%rax
mov    %rax,%rsi
xor    %r15,%rsi
xor    0x18(%rsp),%rbx
mov    0x10(%rsp),%rcx
mov    %rcx,%rdx
xor    %r12,%rdx
xor    0x8(%rsp),%rbp
or     %rdx,%rbp
sete   %dl
or     %rsi,%rbx
setne  %bl
je     121e <test+0xbe>
test   %dl,%dl
jne    1283 <test+0x123>
or     %dl,%bl
je     129e <test+0x13e>
mov    %r13,%rdi
call   1060 <iconv_close@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
lea    0xdbd(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2d74(%rip),%rcx
mov    (%rcx),%edi
lea    0xdb1(%rip),%rsi
mov    %r14,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2d4e(%rip),%rcx
mov    (%rcx),%edi
sub    %r15,%rax
lea    0xdac(%rip),%rsi
mov    %r14,%rdx
mov    %rax,%rcx
jmp    12b4 <test+0x154>
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
sub    %r12,%rcx
lea    0xdaa(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"UTF-8\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"cannot convert from %s\0A\00"
@errno = global i64 0
@E2BIG = global i64 0
@.str.2 = [36 x i8] c"%s: wrong iconv result: %d/%d (%m)\0A\00"
@.str.3 = [25 x i8] c"%s: ate %td input bytes\0A\00"
@.str.4 = [31 x i8] c"%s: produced %td output bytes\0A\00"
define void @test(i8* %0, i8* %1, i64 %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i64 %3, i64* %8
%18 = load i64, i64* %8
%19 = call i8* @alloca(i64 %18)
store i8* %19, i8** %9
%20 = load i8*, i8** %5
%21 = call i64 @iconv_open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %20)
store i64 %21, i64* %10
%22 = load i64, i64* %10
%23 = icmp eq i64 %22, -1
br i1 %23, label %24, label %29
24: ; preds = %4
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %5
%27 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %4
%30 = load i8*, i8** %6
store i8* %30, i8** %11
%31 = load i64, i64* %7
store i64 %31, i64* %12
%32 = load i8*, i8** %9
store i8* %32, i8** %13
%33 = load i64, i64* %8
store i64 %33, i64* %14
%34 = load i64, i64* %10
%35 = call i32 @iconv(i64 %34, i8** %11, i64* %12, i8** %13, i64* %14)
store i32 %35, i32* %15
%36 = load i32, i32* %15
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %42
38: ; preds = %29
%39 = load i64, i64* @errno
%40 = load i64, i64* @E2BIG
%41 = icmp eq i64 %39, %40
br i1 %41, label %49, label %42
42: ; preds = %38, %29
%43 = load i32, i32* @stderr
%44 = load i8*, i8** %5
%45 = load i32, i32* %15
%46 = load i64, i64* @errno
%47 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %44, i32 %45, i64 %46)
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %38
%50 = load i8*, i8** %11
%51 = load i8*, i8** %6
%52 = icmp eq i8* %50, %51
br i1 %52, label %53, label %57
53: ; preds = %49
%54 = load i64, i64* %12
%55 = load i64, i64* %7
%56 = icmp eq i64 %54, %55
br label %57
57: ; preds = %53, %49
%58 = phi i1 [ false, %49 ], [ %56, %53 ]
%59 = zext i1 %58 to i32
store i32 %59, i32* %16
%60 = load i8*, i8** %13
%61 = load i8*, i8** %9
%62 = icmp eq i8* %60, %61
br i1 %62, label %63, label %67
63: ; preds = %57
%64 = load i64, i64* %14
%65 = load i64, i64* %8
%66 = icmp eq i64 %64, %65
br label %67
67: ; preds = %63, %57
%68 = phi i1 [ false, %57 ], [ %66, %63 ]
%69 = zext i1 %68 to i32
store i32 %69, i32* %17
%70 = load i32, i32* %16
%71 = icmp ne i32 %70, 0
br i1 %71, label %85, label %72
72: ; preds = %67
%73 = load i32, i32* %17
%74 = icmp ne i32 %73, 0
br i1 %74, label %75, label %85
75: ; preds = %72
%76 = load i32, i32* @stderr
%77 = load i8*, i8** %5
%78 = load i8*, i8** %11
%79 = load i8*, i8** %6
%80 = ptrtoint i8* %78 to i64
%81 = ptrtoint i8* %79 to i64
%82 = sub i64 %80, %81
%83 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %77, i64 %82)
%84 = call i32 @exit(i32 1)
unreachable
85: ; preds = %72, %67
%86 = load i32, i32* %16
%87 = icmp ne i32 %86, 0
br i1 %87, label %88, label %101
88: ; preds = %85
%89 = load i32, i32* %17
%90 = icmp ne i32 %89, 0
br i1 %90, label %101, label %91
91: ; preds = %88
%92 = load i32, i32* @stderr
%93 = load i8*, i8** %5
%94 = load i8*, i8** %13
%95 = load i8*, i8** %9
%96 = ptrtoint i8* %94 to i64
%97 = ptrtoint i8* %95 to i64
%98 = sub i64 %96, %97
%99 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %92, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %93, i64 %98)
%100 = call i32 @exit(i32 1)
unreachable
101: ; preds = %88, %85
%102 = load i64, i64* %10
%103 = call i32 @iconv_close(i64 %102)
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"UTF-8\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"cannot convert from %s\0A\00"
@errno = global i64 0
@E2BIG = global i64 0
@.str.2 = [36 x i8] c"%s: wrong iconv result: %d/%d (%m)\0A\00"
@.str.3 = [25 x i8] c"%s: ate %td input bytes\0A\00"
@.str.4 = [31 x i8] c"%s: produced %td output bytes\0A\00"
define void @test(i8* %0, i8* %1, i64 %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = tail call i8* @alloca(i64 %3)
%10 = bitcast i8** %5 to i8*
%11 = bitcast i64* %6 to i8*
%12 = bitcast i8** %7 to i8*
%13 = bitcast i64* %8 to i8*
%14 = tail call i64 @iconv_open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0)
%15 = icmp eq i64 %14, -1
br i1 %15, label %16, label %20
16: ; preds = %4
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i8* %9, i8** %7
store i64 %3, i64* %8
%21 = call i32 @iconv(i64 %14, i8** %5, i64* %6, i8** %7, i64* %8)
%22 = icmp eq i32 %21, -1
%23 = load i64, i64* @errno
%24 = load i64, i64* @E2BIG
%25 = icmp eq i64 %23, %24
%26 = select i1 %22, i1 %25, i1 false
br i1 %26, label %31, label %27
27: ; preds = %20
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %21, i64 %23)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %20
%32 = load i8*, i8** %5
%33 = icmp ne i8* %32, %1
%34 = load i64, i64* %6
%35 = icmp ne i64 %34, %2
%36 = select i1 %33, i1 true, i1 %35
%37 = load i8*, i8** %7
%38 = icmp eq i8* %37, %9
%39 = load i64, i64* %8
%40 = icmp eq i64 %39, %3
%41 = select i1 %38, i1 %40, i1 false
%42 = select i1 %36, i1 %41, i1 false
br i1 %42, label %43, label %50
43: ; preds = %31
%44 = load i32, i32* @stderr
%45 = ptrtoint i8* %32 to i64
%46 = ptrtoint i8* %1 to i64
%47 = sub i64 %45, %46
%48 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %0, i64 %47)
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %31
%51 = select i1 %36, i1 true, i1 %41
br i1 %51, label %59, label %52
52: ; preds = %50
%53 = load i32, i32* @stderr
%54 = ptrtoint i8* %37 to i64
%55 = ptrtoint i8* %9 to i64
%56 = sub i64 %54, %55
%57 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %0, i64 %56)
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %50
%60 = call i32 @iconv_close(i64 %14)
ret void
}