#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 */
int iconv(scalar_t__, void *, size_t *, char **, size_t *);
scalar_t__ memcpy(char *, char *, int);
void utfError(char *, int, char *);
int iconvConvert(iconv_t ic, char *bytes, int len, char *output,
                 int outputMaxLen) {
  int outputLen = 0;
  ((bytes) == 0
       ? utfError("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/34benma/openjdk/refs/"
                  "heads/jaklin-master/jdk/src/java.instrument/unix/native/"
                  "libinstrument/EncodingSupport_md.c",
                  122,
                  "ASSERT ERROR "
                  "bytes")
       : (void)0);
  ((len >= 0) == 0
       ? utfError("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/34benma/openjdk/refs/"
                  "heads/jaklin-master/jdk/src/java.instrument/unix/native/"
                  "libinstrument/EncodingSupport_md.c",
                  123,
                  "ASSERT ERROR "
                  "len>=0")
       : (void)0);
  ((output) == 0
       ? utfError("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/34benma/openjdk/refs/"
                  "heads/jaklin-master/jdk/src/java.instrument/unix/native/"
                  "libinstrument/EncodingSupport_md.c",
                  124,
                  "ASSERT ERROR "
                  "output")
       : (void)0);
  ((outputMaxLen > len) == 0
       ? utfError("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/34benma/openjdk/refs/"
                  "heads/jaklin-master/jdk/src/java.instrument/unix/native/"
                  "libinstrument/EncodingSupport_md.c",
                  125,
                  "ASSERT ERROR "
                  "outputMaxLen>len")
       : (void)0);
  output[0] = 0;
  outputLen = 0;
  if (ic != (iconv_t)-1) {
    int returnValue;
    size_t inLeft;
    size_t outLeft;
    char *inbuf;
    char *outbuf;
    inbuf = bytes;
    outbuf = output;
    inLeft = len;
    outLeft = outputMaxLen;
    returnValue = iconv(ic, (void *)&inbuf, &inLeft, &outbuf, &outLeft);
    if (returnValue >= 0 && inLeft == 0) {
      outputLen = outputMaxLen - outLeft;
      output[outputLen] = 0;
      return outputLen;
    }
    return -1;
  }
  outputLen = len;
  (void)memcpy(output, bytes, len);
  output[len] = 0;
  return outputLen;
}


x86 assembly (clang, -O0):
<iconvConvert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117a <iconvConvert+0x4a>
lea    0xe9c(%rip),%rdi
mov    $0x7a,%esi
lea    0xf5a(%rip),%rdx
call   1040 <utfError@plt>
jmp    117f <iconvConvert+0x4f>
jmp    117f <iconvConvert+0x4f>
cmpl   $0x0,-0x1c(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%eax
cmp    $0x0,%eax
jne    11b1 <iconvConvert+0x81>
lea    0xe65(%rip),%rdi
mov    $0x7b,%esi
lea    0xf36(%rip),%rdx
call   1040 <utfError@plt>
jmp    11b6 <iconvConvert+0x86>
jmp    11b6 <iconvConvert+0x86>
cmpq   $0x0,-0x28(%rbp)
jne    11de <iconvConvert+0xae>
lea    0xe38(%rip),%rdi
mov    $0x7c,%esi
lea    0xf1d(%rip),%rdx
call   1040 <utfError@plt>
jmp    11e3 <iconvConvert+0xb3>
jmp    11e3 <iconvConvert+0xb3>
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
setg   %al
and    $0x1,%al
movzbl %al,%eax
cmp    $0x0,%eax
jne    1217 <iconvConvert+0xe7>
lea    0xdff(%rip),%rdi
mov    $0x7d,%esi
lea    0xef8(%rip),%rdx
call   1040 <utfError@plt>
jmp    121c <iconvConvert+0xec>
jmp    121c <iconvConvert+0xec>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x30(%rbp)
cmpq   $0xffffffffffffffff,-0x10(%rbp)
je     12b4 <iconvConvert+0x184>
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
movslq -0x1c(%rbp),%rax
mov    %rax,-0x40(%rbp)
movslq -0x2c(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x50(%rbp),%rsi
lea    -0x40(%rbp),%rdx
lea    -0x58(%rbp),%rcx
lea    -0x48(%rbp),%r8
call   1030 <iconv@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jl     12a8 <iconvConvert+0x178>
cmpq   $0x0,-0x40(%rbp)
jne    12a8 <iconvConvert+0x178>
movslq -0x2c(%rbp),%rax
sub    -0x48(%rbp),%rax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12dc <iconvConvert+0x1ac>
movl   $0xffffffff,-0x4(%rbp)
jmp    12dc <iconvConvert+0x1ac>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iconvConvert>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %r8d,%r14d
mov    %rcx,%rbx
mov    %edx,%ebp
mov    %rsi,%r12
mov    %rdi,%r15
test   %rsi,%rsi
je     11ea <iconvConvert+0xba>
test   %ebp,%ebp
js     120a <iconvConvert+0xda>
test   %rbx,%rbx
je     122b <iconvConvert+0xfb>
cmp    %ebp,%r14d
jg     1181 <iconvConvert+0x51>
lea    0xe90(%rip),%rdi
lea    0xf8e(%rip),%rdx
mov    $0x7d,%esi
call   1040 <utfError@plt>
movb   $0x0,(%rbx)
cmp    $0xffffffffffffffff,%r15
je     1251 <iconvConvert+0x121>
mov    %r12,0x18(%rsp)
mov    %rbx,0x10(%rsp)
movslq %ebp,%rax
mov    %rax,0x8(%rsp)
movslq %r14d,%rax
mov    %rax,(%rsp)
lea    0x18(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    %rsp,%r8
mov    %r15,%rdi
call   1030 <iconv@plt>
mov    $0xffffffff,%ebp
test   %eax,%eax
js     1265 <iconvConvert+0x135>
cmpq   $0x0,0x8(%rsp)
jne    1265 <iconvConvert+0x135>
sub    (%rsp),%r14d
movslq %r14d,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %r14d,%ebp
jmp    1265 <iconvConvert+0x135>
lea    0xe0f(%rip),%rdi
lea    0xed2(%rip),%rdx
mov    $0x7a,%esi
call   1040 <utfError@plt>
test   %ebp,%ebp
jns    115b <iconvConvert+0x2b>
lea    0xdef(%rip),%rdi
lea    0xec5(%rip),%rdx
mov    $0x7b,%esi
call   1040 <utfError@plt>
test   %rbx,%rbx
jne    1164 <iconvConvert+0x34>
lea    0xdce(%rip),%rdi
lea    0xeb8(%rip),%rdx
mov    $0x7c,%esi
call   1040 <utfError@plt>
cmp    %ebp,%r14d
jle    1169 <iconvConvert+0x39>
jmp    1181 <iconvConvert+0x51>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1050 <memcpy@plt>
movslq %ebp,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [202 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/34benma/openjdk/refs/heads/jaklin-master/jdk/src/java.instrument/unix/native/libinstrument/EncodingSupport_md.c\00"
@.str.1 = [19 x i8] c"ASSERT ERROR bytes\00"
@.str.2 = [20 x i8] c"ASSERT ERROR len>=0\00"
@.str.3 = [20 x i8] c"ASSERT ERROR output\00"
@.str.4 = [30 x i8] c"ASSERT ERROR outputMaxLen>len\00"
define i32 @iconvConvert(i64 %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i64
%15 = alloca i64
%16 = alloca i8*
%17 = alloca i8*
store i64 %0, i64* %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32 %4, i32* %11
store i32 0, i32* %12
%18 = load i8*, i8** %8
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %21
20: ; preds = %5
br label %22
21: ; preds = %5
br label %22
22: ; preds = %21, %20
%23 = load i32, i32* %9
%24 = icmp sge i32 %23, 0
%25 = zext i1 %24 to i32
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %22
br label %29
28: ; preds = %22
br label %29
29: ; preds = %28, %27
%30 = load i8*, i8** %10
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %33
32: ; preds = %29
br label %34
33: ; preds = %29
br label %34
34: ; preds = %33, %32
%35 = load i32, i32* %11
%36 = load i32, i32* %9
%37 = icmp sgt i32 %35, %36
%38 = zext i1 %37 to i32
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %34
br label %42
41: ; preds = %34
br label %42
42: ; preds = %41, %40
%43 = load i8*, i8** %10
%44 = getelementptr inbounds i8, i8* %43, i64 0
store i8 0, i8* %44
store i32 0, i32* %12
%45 = load i64, i64* %7
%46 = icmp ne i64 %45, -1
br i1 %46, label %47, label %74
47: ; preds = %42
%48 = load i8*, i8** %8
store i8* %48, i8** %16
%49 = load i8*, i8** %10
store i8* %49, i8** %17
%50 = load i32, i32* %9
%51 = sext i32 %50 to i64
store i64 %51, i64* %14
%52 = load i32, i32* %11
%53 = sext i32 %52 to i64
store i64 %53, i64* %15
%54 = load i64, i64* %7
%55 = bitcast i8** %16 to i8*
%56 = call i32 @iconv(i64 %54, i8* %55, i64* %14, i8** %17, i64* %15)
store i32 %56, i32* %13
%57 = load i32, i32* %13
%58 = icmp sge i32 %57, 0
br i1 %58, label %59, label %73
59: ; preds = %47
%60 = load i64, i64* %14
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %73
62: ; preds = %59
%63 = load i32, i32* %11
%64 = sext i32 %63 to i64
%65 = load i64, i64* %15
%66 = sub i64 %64, %65
%67 = trunc i64 %66 to i32
store i32 %67, i32* %12
%68 = load i8*, i8** %10
%69 = load i32, i32* %12
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %68, i64 %70
store i8 0, i8* %71
%72 = load i32, i32* %12
store i32 %72, i32* %6
br label %85
73: ; preds = %59, %47
store i32 -1, i32* %6
br label %85
74: ; preds = %42
%75 = load i32, i32* %9
store i32 %75, i32* %12
%76 = load i8*, i8** %10
%77 = load i8*, i8** %8
%78 = load i32, i32* %9
%79 = call i64 @memcpy(i8* %76, i8* %77, i32 %78)
%80 = load i8*, i8** %10
%81 = load i32, i32* %9
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8, i8* %80, i64 %82
store i8 0, i8* %83
%84 = load i32, i32* %12
store i32 %84, i32* %6
br label %85
85: ; preds = %74, %73, %62
%86 = load i32, i32* %6
ret i32 %86
}

LLVM IR (-O2):
@.str = [202 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/34benma/openjdk/refs/heads/jaklin-master/jdk/src/java.instrument/unix/native/libinstrument/EncodingSupport_md.c\00"
@.str.1 = [19 x i8] c"ASSERT ERROR bytes\00"
@.str.2 = [20 x i8] c"ASSERT ERROR len>=0\00"
@.str.3 = [20 x i8] c"ASSERT ERROR output\00"
@.str.4 = [30 x i8] c"ASSERT ERROR outputMaxLen>len\00"
define i32 @iconvConvert(i64 %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = icmp eq i8* %1, null
br i1 %10, label %11, label %12
11: ; preds = %5
tail call void @utfError(i8* getelementptr inbounds ([202 x i8], [202 x i8]* @.str, i64 0, i64 0), i32 122, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %5, %11
%13 = icmp slt i32 %2, 0
br i1 %13, label %14, label %15
14: ; preds = %12
tail call void @utfError(i8* getelementptr inbounds ([202 x i8], [202 x i8]* @.str, i64 0, i64 0), i32 123, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %12, %14
%16 = icmp eq i8* %3, null
br i1 %16, label %17, label %18
17: ; preds = %15
tail call void @utfError(i8* getelementptr inbounds ([202 x i8], [202 x i8]* @.str, i64 0, i64 0), i32 124, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %18
18: ; preds = %15, %17
%19 = icmp sgt i32 %4, %2
br i1 %19, label %21, label %20
20: ; preds = %18
tail call void @utfError(i8* getelementptr inbounds ([202 x i8], [202 x i8]* @.str, i64 0, i64 0), i32 125, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
br label %21
21: ; preds = %18, %20
store i8 0, i8* %3
%22 = icmp eq i64 %0, -1
br i1 %22, label %43, label %23
23: ; preds = %21
%24 = bitcast i64* %6 to i8*
%25 = bitcast i64* %7 to i8*
%26 = bitcast i8** %8 to i8*
%27 = bitcast i8** %9 to i8*
store i8* %1, i8** %8
store i8* %3, i8** %9
%28 = sext i32 %2 to i64
store i64 %28, i64* %6
%29 = sext i32 %4 to i64
store i64 %29, i64* %7
%30 = call i32 @iconv(i64 %0, i8* %26, i64* %6, i8** %9, i64* %7)
%31 = icmp sgt i32 %30, -1
%32 = load i64, i64* %6
%33 = icmp eq i64 %32, 0
%34 = select i1 %31, i1 %33, i1 false
br i1 %34, label %35, label %41
35: ; preds = %23
%36 = load i64, i64* %7
%37 = trunc i64 %36 to i32
%38 = sub i32 %4, %37
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %3, i64 %39
store i8 0, i8* %40
br label %41
41: ; preds = %23, %35
%42 = phi i32 [ %38, %35 ], [ -1, %23 ]
br label %47
43: ; preds = %21
%44 = tail call i64 @memcpy(i8* %3, i8* %1, i32 %2)
%45 = sext i32 %2 to i64
%46 = getelementptr inbounds i8, i8* %3, i64 %45
store i8 0, i8* %46
br label %47
47: ; preds = %43, %41
%48 = phi i32 [ %42, %41 ], [ %2, %43 ]
ret i32 %48
}