#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*/ outbuf;
typedef scalar_t__ iconv_t;

/* Variables and functions */
int errno;
size_t iconv(scalar_t__, char **, size_t *, char **, size_t *);
int /*<<< orphan*/ iconv_close(scalar_t__);
scalar_t__ iconv_open(char const *, char const *);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ puts(char *);
char *strerror(int);
int run_conversion(const char *from, const char *to, char *inbuf,
                   size_t inbuflen, int exp_errno, int line) {
  char outbuf[16];
  iconv_t cd;
  char *inptr;
  size_t inlen;
  char *outptr;
  size_t outlen;
  size_t n;
  int e;
  int fails = 0;
  cd = iconv_open(to, from);
  if (cd == (iconv_t)-1) {
    printf("line %d: cannot convert from %s to %s: %m\n", line, from, to);
    return 1;
  }
  inptr = (char *)inbuf;
  inlen = inbuflen;
  outptr = outbuf;
  outlen = sizeof(outbuf);
  errno = 0;
  n = iconv(cd, &inptr, &inlen, &outptr, &outlen);
  e = errno;
  if (exp_errno == 0) {
    if (n == (size_t)-1) {
      puts("n should be >= 0, but n == -1");
      fails++;
    }
    if (e != 0) {
      printf("errno should be 0: 'Success', but errno == %d: '%s'\n", e,
             strerror(e));
      fails++;
    }
  } else {
    if (n != (size_t)-1) {
      printf("n should be -1, but n == %zd\n", n);
      fails++;
    }
    if (e != exp_errno) {
      printf("errno should be %d: '%s', but errno == %d: '%s'\n", exp_errno,
             strerror(exp_errno), e, strerror(e));
      fails++;
    }
  }
  iconv_close(cd);
  if (fails > 0) {
    printf("Errors in line %d while converting %s to %s.\n\n", line, from, to);
  }
  return fails;
}


x86 assembly (clang, -O0):
<run_conversion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    %r9d,-0x30(%rbp)
movl   $0x0,-0x78(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <iconv_open@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0xffffffffffffffff,-0x48(%rbp)
jne    11cb <run_conversion+0x6b>
mov    -0x30(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1340 <run_conversion+0x1e0>
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x60(%rbp)
movq   $0x10,-0x68(%rbp)
mov    0x2dee(%rip),%rax
movl   $0x0,(%rax)
mov    -0x48(%rbp),%rdi
lea    -0x50(%rbp),%rsi
lea    -0x58(%rbp),%rdx
lea    -0x60(%rbp),%rcx
lea    -0x68(%rbp),%r8
call   1030 <iconv@plt>
mov    %rax,-0x70(%rbp)
mov    0x2dc4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    1285 <run_conversion+0x125>
cmpq   $0xffffffffffffffff,-0x70(%rbp)
jne    124b <run_conversion+0xeb>
lea    0xdee(%rip),%rdi
call   1040 <puts@plt>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
cmpl   $0x0,-0x74(%rbp)
je     1280 <run_conversion+0x120>
mov    -0x74(%rbp),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x74(%rbp),%edi
call   1070 <strerror@plt>
mov    -0x7c(%rbp),%esi
mov    %rax,%rdx
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    130e <run_conversion+0x1ae>
cmpq   $0xffffffffffffffff,-0x70(%rbp)
je     12ad <run_conversion+0x14d>
mov    -0x70(%rbp),%rax
mov    %eax,%esi
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
mov    -0x74(%rbp),%eax
cmp    -0x2c(%rbp),%eax
je     1309 <run_conversion+0x1a9>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x2c(%rbp),%edi
call   1070 <strerror@plt>
mov    %rax,-0x88(%rbp)
mov    -0x74(%rbp),%eax
mov    %eax,-0x80(%rbp)
mov    -0x74(%rbp),%edi
call   1070 <strerror@plt>
mov    -0x8c(%rbp),%esi
mov    -0x88(%rbp),%rdx
mov    -0x80(%rbp),%ecx
mov    %rax,%r8
lea    0xda3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    130e <run_conversion+0x1ae>
mov    -0x48(%rbp),%rdi
call   1060 <iconv_close@plt>
cmpl   $0x0,-0x78(%rbp)
jle    133a <run_conversion+0x1da>
mov    -0x30(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xd9a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x78(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_conversion>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r9d,%ebp
mov    %r8d,%r15d
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
mov    %r14,%rsi
call   1080 <iconv_open@plt>
cmp    $0xffffffffffffffff,%rax
je     1215 <run_conversion+0xb5>
mov    %r14,(%rsp)
mov    %rbx,0x8(%rsp)
mov    %r13,0x28(%rsp)
mov    %r12,0x20(%rsp)
lea    0x30(%rsp),%rcx
mov    %rcx,0x18(%rsp)
movq   $0x10,0x10(%rsp)
mov    0x2e1e(%rip),%rbx
movl   $0x0,(%rbx)
lea    0x28(%rsp),%rsi
lea    0x20(%rsp),%rdx
lea    0x18(%rsp),%rcx
lea    0x10(%rsp),%r8
mov    %rax,%r14
mov    %rax,%rdi
call   1030 <iconv@plt>
mov    (%rbx),%r13d
test   %r15d,%r15d
je     1235 <run_conversion+0xd5>
cmp    $0xffffffffffffffff,%rax
je     1248 <run_conversion+0xe8>
lea    0xe82(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%r12d
cmp    %r15d,%r13d
jne    1250 <run_conversion+0xf0>
jmp    12cf <run_conversion+0x16f>
lea    0xde4(%rip),%rdi
mov    %ebp,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%ebx
jmp    1304 <run_conversion+0x1a4>
xor    %r12d,%r12d
cmp    $0xffffffffffffffff,%rax
je     127f <run_conversion+0x11f>
test   %r13d,%r13d
jne    1296 <run_conversion+0x136>
jmp    12cf <run_conversion+0x16f>
xor    %r12d,%r12d
cmp    %r15d,%r13d
je     12cf <run_conversion+0x16f>
mov    %r15d,%edi
call   1070 <strerror@plt>
mov    %rax,%rbx
mov    %r13d,%edi
call   1070 <strerror@plt>
lea    0xe32(%rip),%rdi
mov    %r15d,%esi
mov    %rbx,%rdx
mov    %r13d,%ecx
mov    %rax,%r8
xor    %eax,%eax
call   1050 <printf@plt>
jmp    12b2 <run_conversion+0x152>
lea    0xda5(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r12d
test   %r13d,%r13d
je     12cf <run_conversion+0x16f>
mov    %r13d,%edi
call   1070 <strerror@plt>
lea    0xda4(%rip),%rdi
mov    %r13d,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%r15
mov    %ebp,%r13d
mov    (%rsp),%rbp
mov    %r14,%rdi
add    $0x1,%r12d
call   1060 <iconv_close@plt>
mov    %r12d,%ebx
jmp    12ed <run_conversion+0x18d>
mov    0x8(%rsp),%r15
mov    %ebp,%r13d
mov    (%rsp),%rbp
mov    %r14,%rdi
call   1060 <iconv_close@plt>
mov    $0x1,%ebx
test   %r12d,%r12d
je     1315 <run_conversion+0x1b5>
lea    0xdd9(%rip),%rdi
mov    %r13d,%esi
mov    %rbp,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebx,%ebx
jmp    1304 <run_conversion+0x1a4>

LLVM IR (-O0):
@.str = [43 x i8] c"line %d: cannot convert from %s to %s: %m\0A\00"
@errno = global i32 0
@.str.1 = [30 x i8] c"n should be >= 0, but n == -1\00"
@.str.2 = [53 x i8] c"errno should be 0: 'Success', but errno == %d: '%s'\0A\00"
@.str.3 = [30 x i8] c"n should be -1, but n == %zd\0A\00"
@.str.4 = [49 x i8] c"errno should be %d: '%s', but errno == %d: '%s'\0A\00"
@.str.5 = [47 x i8] c"Errors in line %d while converting %s to %s.\0A\0A\00"
define i32 @run_conversion(i8* %0, i8* %1, i8* %2, i64 %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32
%14 = alloca [16 x i8]
%15 = alloca i64
%16 = alloca i8*
%17 = alloca i64
%18 = alloca i8*
%19 = alloca i64
%20 = alloca i64
%21 = alloca i32
%22 = alloca i32
store i8* %0, i8** %8
store i8* %1, i8** %9
store i8* %2, i8** %10
store i64 %3, i64* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
store i32 0, i32* %22
%23 = load i8*, i8** %9
%24 = load i8*, i8** %8
%25 = call i64 @iconv_open(i8* %23, i8* %24)
store i64 %25, i64* %15
%26 = load i64, i64* %15
%27 = icmp eq i64 %26, -1
br i1 %27, label %28, label %33
28: ; preds = %6
%29 = load i32, i32* %13
%30 = load i8*, i8** %8
%31 = load i8*, i8** %9
%32 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %29, i8* %30, i8* %31)
store i32 1, i32* %7
br label %96
33: ; preds = %6
%34 = load i8*, i8** %10
store i8* %34, i8** %16
%35 = load i64, i64* %11
store i64 %35, i64* %17
%36 = getelementptr inbounds [16 x i8], [16 x i8]* %14, i64 0, i64 0
store i8* %36, i8** %18
store i64 16, i64* %19
store i32 0, i32* @errno
%37 = load i64, i64* %15
%38 = call i64 @iconv(i64 %37, i8** %16, i64* %17, i8** %18, i64* %19)
store i64 %38, i64* %20
%39 = load i32, i32* @errno
store i32 %39, i32* %21
%40 = load i32, i32* %12
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %60
42: ; preds = %33
%43 = load i64, i64* %20
%44 = icmp eq i64 %43, -1
br i1 %44, label %45, label %49
45: ; preds = %42
%46 = call i32 @puts(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%47 = load i32, i32* %22
%48 = add nsw i32 %47, 1
store i32 %48, i32* %22
br label %49
49: ; preds = %45, %42
%50 = load i32, i32* %21
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %59
52: ; preds = %49
%53 = load i32, i32* %21
%54 = load i32, i32* %21
%55 = call i8* @strerror(i32 %54)
%56 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i32 %53, i8* %55)
%57 = load i32, i32* %22
%58 = add nsw i32 %57, 1
store i32 %58, i32* %22
br label %59
59: ; preds = %52, %49
br label %84
60: ; preds = %33
%61 = load i64, i64* %20
%62 = icmp ne i64 %61, -1
br i1 %62, label %63, label %69
63: ; preds = %60
%64 = load i64, i64* %20
%65 = trunc i64 %64 to i32
%66 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %65)
%67 = load i32, i32* %22
%68 = add nsw i32 %67, 1
store i32 %68, i32* %22
br label %69
69: ; preds = %63, %60
%70 = load i32, i32* %21
%71 = load i32, i32* %12
%72 = icmp ne i32 %70, %71
br i1 %72, label %73, label %83
73: ; preds = %69
%74 = load i32, i32* %12
%75 = load i32, i32* %12
%76 = call i8* @strerror(i32 %75)
%77 = load i32, i32* %21
%78 = load i32, i32* %21
%79 = call i8* @strerror(i32 %78)
%80 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0), i32 %74, i8* %76, i32 %77, i8* %79)
%81 = load i32, i32* %22
%82 = add nsw i32 %81, 1
store i32 %82, i32* %22
br label %83
83: ; preds = %73, %69
br label %84
84: ; preds = %83, %59
%85 = load i64, i64* %15
%86 = call i32 @iconv_close(i64 %85)
%87 = load i32, i32* %22
%88 = icmp sgt i32 %87, 0
br i1 %88, label %89, label %94
89: ; preds = %84
%90 = load i32, i32* %13
%91 = load i8*, i8** %8
%92 = load i8*, i8** %9
%93 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0), i32 %90, i8* %91, i8* %92)
br label %94
94: ; preds = %89, %84
%95 = load i32, i32* %22
store i32 %95, i32* %7
br label %96
96: ; preds = %94, %28
%97 = load i32, i32* %7
ret i32 %97
}

LLVM IR (-O2):
@.str = [43 x i8] c"line %d: cannot convert from %s to %s: %m\0A\00"
@errno = global i32 0
@.str.1 = [30 x i8] c"n should be >= 0, but n == -1\00"
@.str.2 = [53 x i8] c"errno should be 0: 'Success', but errno == %d: '%s'\0A\00"
@.str.3 = [30 x i8] c"n should be -1, but n == %zd\0A\00"
@.str.4 = [49 x i8] c"errno should be %d: '%s', but errno == %d: '%s'\0A\00"
@.str.5 = [47 x i8] c"Errors in line %d while converting %s to %s.\0A\0A\00"
define i32 @run_conversion(i8* %0, i8* %1, i8* %2, i64 %3, i32 %4, i32 %5) {
%7 = alloca [16 x i8]
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i64
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%13 = bitcast i8** %8 to i8*
%14 = bitcast i64* %9 to i8*
%15 = bitcast i8** %10 to i8*
%16 = bitcast i64* %11 to i8*
%17 = tail call i64 @iconv_open(i8* %1, i8* %0)
%18 = icmp eq i64 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %6
%20 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %5, i8* %0, i8* %1)
br label %57
21: ; preds = %6
store i8* %2, i8** %8
store i64 %3, i64* %9
store i8* %12, i8** %10
store i64 16, i64* %11
store i32 0, i32* @errno
%22 = call i64 @iconv(i64 %17, i8** %8, i64* %9, i8** %10, i64* %11)
%23 = load i32, i32* @errno
%24 = icmp eq i32 %4, 0
%25 = icmp eq i64 %22, -1
br i1 %24, label %26, label %35
26: ; preds = %21
br i1 %25, label %27, label %29
27: ; preds = %26
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %27, %26
%30 = phi i32 [ 1, %27 ], [ 0, %26 ]
%31 = icmp eq i32 %23, 0
br i1 %31, label %50, label %32
32: ; preds = %29
%33 = call i8* @strerror(i32 %23)
%34 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i32 %23, i8* %33)
br label %46
35: ; preds = %21
br i1 %25, label %39, label %36
36: ; preds = %35
%37 = trunc i64 %22 to i32
%38 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %36, %35
%40 = phi i32 [ 1, %36 ], [ 0, %35 ]
%41 = icmp eq i32 %23, %4
br i1 %41, label %50, label %42
42: ; preds = %39
%43 = call i8* @strerror(i32 %4)
%44 = call i8* @strerror(i32 %23)
%45 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0), i32 %4, i8* %43, i32 %23, i8* %44)
br label %46
46: ; preds = %32, %42
%47 = phi i32 [ %40, %42 ], [ %30, %32 ]
%48 = add nuw nsw i32 %47, 1
%49 = call i32 @iconv_close(i64 %17)
br label %54
50: ; preds = %39, %29
%51 = phi i32 [ %30, %29 ], [ %40, %39 ]
%52 = call i32 @iconv_close(i64 %17)
%53 = icmp eq i32 %51, 0
br i1 %53, label %57, label %54
54: ; preds = %46, %50
%55 = phi i32 [ %48, %46 ], [ 1, %50 ]
%56 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0), i32 %5, i8* %0, i8* %1)
br label %57
57: ; preds = %50, %54, %19
%58 = phi i32 [ 1, %19 ], [ %55, %54 ], [ 0, %50 ]
ret i32 %58
}