#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__, char **, size_t *, char **, size_t *);
int /*<<< orphan*/ iconv_close(scalar_t__);
scalar_t__ iconv_open(char const *, char const *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ printf(char *, char *, int);
int code_convert(const char *from_charset, const char *to_charset, char *inbuf,
                 size_t inlen, char *outbuf, size_t outlen) {
  iconv_t cd;
  char **pin = &inbuf;
  char **pout = &outbuf;
  cd = iconv_open(to_charset, from_charset);
  if ((iconv_t)-1 == cd) {
    printf("file:%s,line:%d,iconv_open error!\n",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/Onyx47/chan_extra/refs/heads/master/src/"
           "libgsmat/gsm_sms.c",
           609);
    return -1;
  }
  memset(outbuf, 0, outlen);
  if (iconv(cd, pin, &inlen, pout, &outlen) == -1) {
    printf("file:%s,line:%d,iconv error!\n",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/Onyx47/chan_extra/refs/heads/master/src/"
           "libgsmat/gsm_sms.c",
           616);
    return -1;
  }
  iconv_close(cd);
  return outlen;
}


x86 assembly (clang, -O0):
<code_convert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <iconv_open@plt>
mov    %rax,-0x40(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    -0x40(%rbp),%rax
jne    11c6 <code_convert+0x76>
lea    0xe57(%rip),%rdi
lea    0xe73(%rip),%rsi
mov    $0x261,%edx
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122b <code_convert+0xdb>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rdx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x50(%rbp),%rcx
lea    -0x28(%rbp),%rdx
lea    -0x38(%rbp),%r8
call   1030 <iconv@plt>
cmp    $0xffffffff,%eax
jne    121b <code_convert+0xcb>
lea    0xeba(%rip),%rdi
lea    0xe1e(%rip),%rsi
mov    $0x268,%edx
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122b <code_convert+0xdb>
mov    -0x40(%rbp),%rdi
call   1060 <iconv_close@plt>
mov    -0x38(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<code_convert>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %r9,%r14
mov    %r8,%rbx
mov    %rdi,%rax
mov    %rdx,0x18(%rsp)
mov    %rcx,0x10(%rsp)
mov    %r8,0x8(%rsp)
mov    %r9,(%rsp)
mov    %rsi,%rdi
mov    %rax,%rsi
call   1070 <iconv_open@plt>
cmp    $0xffffffffffffffff,%rax
je     11c2 <code_convert+0x72>
mov    %rax,%r15
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1050 <memset@plt>
lea    0x18(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rsp,%r8
mov    %r15,%rdi
call   1030 <iconv@plt>
cmp    $0xffffffff,%eax
je     11d7 <code_convert+0x87>
mov    %r15,%rdi
call   1060 <iconv_close@plt>
mov    (%rsp),%eax
jmp    11f4 <code_convert+0xa4>
lea    0xe37(%rip),%rdi
lea    0xe53(%rip),%rsi
mov    $0x261,%edx
jmp    11ea <code_convert+0x9a>
lea    0xeda(%rip),%rdi
lea    0xe3e(%rip),%rsi
mov    $0x268,%edx
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [35 x i8] c"file:%s,line:%d,iconv_open error!\0A\00"
@.str.1 = [149 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Onyx47/chan_extra/refs/heads/master/src/libgsmat/gsm_sms.c\00"
@.str.2 = [30 x i8] c"file:%s,line:%d,iconv error!\0A\00"
define i32 @code_convert(i8* %0, i8* %1, i8* %2, i64 %3, i8* %4, i64 %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i64
%15 = alloca i8**
%16 = alloca i8**
store i8* %0, i8** %8
store i8* %1, i8** %9
store i8* %2, i8** %10
store i64 %3, i64* %11
store i8* %4, i8** %12
store i64 %5, i64* %13
store i8** %10, i8*** %15
store i8** %12, i8*** %16
%17 = load i8*, i8** %9
%18 = load i8*, i8** %8
%19 = call i64 @iconv_open(i8* %17, i8* %18)
store i64 %19, i64* %14
%20 = load i64, i64* %14
%21 = icmp eq i64 -1, %20
br i1 %21, label %22, label %24
22: ; preds = %6
%23 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.1, i64 0, i64 0), i32 609)
store i32 -1, i32* %7
br label %40
24: ; preds = %6
%25 = load i8*, i8** %12
%26 = load i64, i64* %13
%27 = call i32 @memset(i8* %25, i32 0, i64 %26)
%28 = load i64, i64* %14
%29 = load i8**, i8*** %15
%30 = load i8**, i8*** %16
%31 = call i32 @iconv(i64 %28, i8** %29, i64* %11, i8** %30, i64* %13)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %35
33: ; preds = %24
%34 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.1, i64 0, i64 0), i32 616)
store i32 -1, i32* %7
br label %40
35: ; preds = %24
%36 = load i64, i64* %14
%37 = call i32 @iconv_close(i64 %36)
%38 = load i64, i64* %13
%39 = trunc i64 %38 to i32
store i32 %39, i32* %7
br label %40
40: ; preds = %35, %33, %22
%41 = load i32, i32* %7
ret i32 %41
}

LLVM IR (-O2):
@.str = [35 x i8] c"file:%s,line:%d,iconv_open error!\0A\00"
@.str.1 = [149 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Onyx47/chan_extra/refs/heads/master/src/libgsmat/gsm_sms.c\00"
@.str.2 = [30 x i8] c"file:%s,line:%d,iconv error!\0A\00"
define i32 @code_convert(i8* %0, i8* %1, i8* %2, i64 %3, i8* %4, i64 %5) {
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
store i8* %2, i8** %7
store i64 %3, i64* %8
store i8* %4, i8** %9
store i64 %5, i64* %10
%11 = tail call i64 @iconv_open(i8* %1, i8* %0)
%12 = icmp eq i64 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %6
%14 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.1, i64 0, i64 0), i32 609)
br label %25
15: ; preds = %6
%16 = tail call i32 @memset(i8* %4, i32 0, i64 %5)
%17 = call i32 @iconv(i64 %11, i8** %7, i64* %8, i8** %9, i64* %10)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.1, i64 0, i64 0), i32 616)
br label %25
21: ; preds = %15
%22 = call i32 @iconv_close(i64 %11)
%23 = load i64, i64* %10
%24 = trunc i64 %23 to i32
br label %25
25: ; preds = %21, %19, %13
%26 = phi i32 [ -1, %13 ], [ -1, %19 ], [ %24, %21 ]
ret i32 %26
}