#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 /*<<< orphan*/ free(char *);
int iconv(scalar_t__, char **, size_t *, char **, size_t *);
int /*<<< orphan*/ iconv_close(scalar_t__);
scalar_t__ iconv_open(char const *, char const *);
scalar_t__ malloc(size_t);
int strlen(char *);
char *qstr_conv_encoding(const char *str, const char *fromcode,
                         const char *tocode, float mag) {
  if (str == NULL)
    return NULL;
  char *fromstr = (char *)str;
  size_t fromsize = strlen(fromstr) + 1;
  size_t tosize = sizeof(char) * ((mag * (fromsize - 1)) + 1);
  char *tostr = (char *)malloc(tosize);
  if (tostr == NULL)
    return NULL;
  char *tostr1 = tostr;
  iconv_t it = iconv_open(tocode, fromcode);
  if (it < 0) {
    ;
    return NULL;
  }
  int ret = iconv(it, &fromstr, &fromsize, &tostr, &tosize);
  iconv_close(it);
  if (ret < 0) {
    ;
    free(tostr1);
    return NULL;
  }
  return tostr1;
}


x86 assembly (clang, -O0):
<qstr_conv_encoding>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movss  %xmm0,-0x24(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1191 <qstr_conv_encoding+0x31>
movq   $0x0,-0x8(%rbp)
jmp    12dd <qstr_conv_encoding+0x17d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x38(%rbp)
movss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x68(%rbp)
mov    -0x38(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x64(%rbp)
test   %rax,%rax
movss  %xmm0,-0x60(%rbp)
js     11f6 <qstr_conv_encoding+0x96>
movss  -0x64(%rbp),%xmm0
movss  %xmm0,-0x60(%rbp)
movss  -0x68(%rbp),%xmm0
movss  -0x60(%rbp),%xmm1
mulss  %xmm1,%xmm0
movss  0xdf4(%rip),%xmm1
addss  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttss2si %xmm1,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
movss  0xddd(%rip),%xmm1
subss  %xmm1,%xmm0
cvttss2si %xmm0,%rcx
and    %rdx,%rcx
or     %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    125f <qstr_conv_encoding+0xff>
movq   $0x0,-0x8(%rbp)
jmp    12dd <qstr_conv_encoding+0x17d>
mov    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <iconv_open@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jge    1290 <qstr_conv_encoding+0x130>
movq   $0x0,-0x8(%rbp)
jmp    12dd <qstr_conv_encoding+0x17d>
mov    -0x58(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x48(%rbp),%rcx
lea    -0x40(%rbp),%r8
call   1040 <iconv@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x58(%rbp),%rdi
call   1070 <iconv_close@plt>
cmpl   $0x0,-0x5c(%rbp)
jge    12d5 <qstr_conv_encoding+0x175>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    12dd <qstr_conv_encoding+0x17d>
mov    -0x50(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qstr_conv_encoding>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
test   %rdi,%rdi
je     1240 <qstr_conv_encoding+0xe0>
mov    %rdx,%r14
mov    %rsi,%r15
movaps %xmm0,0x20(%rsp)
mov    %rdi,0x18(%rsp)
call   1050 <strlen@plt>
movslq %eax,%rcx
lea    0x1(%rcx),%rdx
mov    %rdx,0x10(%rsp)
test   %rcx,%rcx
js     11a2 <qstr_conv_encoding+0x42>
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
jmp    11b7 <qstr_conv_encoding+0x57>
shr    %rcx
and    $0x1,%eax
or     %rcx,%rax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
addss  %xmm0,%xmm0
movaps 0x20(%rsp),%xmm1
mulss  %xmm0,%xmm1
addss  0xe38(%rip),%xmm1
cvttss2si %xmm1,%rax
mov    %rax,%rcx
subss  0xe2c(%rip),%xmm1
cvttss2si %xmm1,%rdi
sar    $0x3f,%rcx
and    %rcx,%rdi
or     %rax,%rdi
mov    %rdi,0x8(%rsp)
call   1060 <malloc@plt>
mov    %rax,(%rsp)
test   %rax,%rax
je     1240 <qstr_conv_encoding+0xe0>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <iconv_open@plt>
test   %rax,%rax
js     1240 <qstr_conv_encoding+0xe0>
mov    %rax,%r14
lea    0x18(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %rsp,%rcx
lea    0x8(%rsp),%r8
mov    %rax,%rdi
call   1040 <iconv@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1070 <iconv_close@plt>
test   %ebp,%ebp
jns    1242 <qstr_conv_encoding+0xe2>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @qstr_conv_encoding(i8* %0, i8* %1, i8* %2, float %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca float
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i64
%16 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store float %3, float* %9
%17 = load i8*, i8** %6
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %20
19: ; preds = %4
store i8* null, i8** %5
br label %59
20: ; preds = %4
%21 = load i8*, i8** %6
store i8* %21, i8** %10
%22 = load i8*, i8** %10
%23 = call i32 @strlen(i8* %22)
%24 = add nsw i32 %23, 1
%25 = sext i32 %24 to i64
store i64 %25, i64* %11
%26 = load float, float* %9
%27 = load i64, i64* %11
%28 = sub i64 %27, 1
%29 = uitofp i64 %28 to float
%30 = call float @llvm.fmuladd.f32(float %26, float %29, float 1.000000e+00)
%31 = fmul float 1.000000e+00, %30
%32 = fptoui float %31 to i64
store i64 %32, i64* %12
%33 = load i64, i64* %12
%34 = call i64 @malloc(i64 %33)
%35 = inttoptr i64 %34 to i8*
store i8* %35, i8** %13
%36 = load i8*, i8** %13
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %39
38: ; preds = %20
store i8* null, i8** %5
br label %59
39: ; preds = %20
%40 = load i8*, i8** %13
store i8* %40, i8** %14
%41 = load i8*, i8** %8
%42 = load i8*, i8** %7
%43 = call i64 @iconv_open(i8* %41, i8* %42)
store i64 %43, i64* %15
%44 = load i64, i64* %15
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %39
store i8* null, i8** %5
br label %59
47: ; preds = %39
%48 = load i64, i64* %15
%49 = call i32 @iconv(i64 %48, i8** %10, i64* %11, i8** %13, i64* %12)
store i32 %49, i32* %16
%50 = load i64, i64* %15
%51 = call i32 @iconv_close(i64 %50)
%52 = load i32, i32* %16
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %47
%55 = load i8*, i8** %14
%56 = call i32 @free(i8* %55)
store i8* null, i8** %5
br label %59
57: ; preds = %47
%58 = load i8*, i8** %14
store i8* %58, i8** %5
br label %59
59: ; preds = %57, %54, %46, %38, %19
%60 = load i8*, i8** %5
ret i8* %60
}

LLVM IR (-O2):
define i8* @qstr_conv_encoding(i8* %0, i8* %1, i8* %2, float %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
%9 = icmp eq i8* %0, null
br i1 %9, label %36, label %10
10: ; preds = %4
%11 = bitcast i8** %5 to i8*
store i8* %0, i8** %5
%12 = bitcast i64* %6 to i8*
%13 = tail call i32 @strlen(i8* %0)
%14 = add nsw i32 %13, 1
%15 = sext i32 %14 to i64
store i64 %15, i64* %6
%16 = bitcast i64* %7 to i8*
%17 = add nsw i64 %15, -1
%18 = uitofp i64 %17 to float
%19 = tail call float @llvm.fmuladd.f32(float %3, float %18, float 1.000000e+00)
%20 = fptoui float %19 to i64
store i64 %20, i64* %7
%21 = bitcast i8** %8 to i8*
%22 = tail call i64 @malloc(i64 %20)
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %8
%24 = icmp eq i64 %22, 0
br i1 %24, label %34, label %25
25: ; preds = %10
%26 = tail call i64 @iconv_open(i8* %2, i8* %1)
%27 = icmp slt i64 %26, 0
br i1 %27, label %34, label %28
28: ; preds = %25
%29 = call i32 @iconv(i64 %26, i8** %5, i64* %6, i8** %8, i64* %7)
%30 = call i32 @iconv_close(i64 %26)
%31 = icmp slt i32 %29, 0
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = call i32 @free(i8* %23)
br label %34
34: ; preds = %25, %28, %32, %10
%35 = phi i8* [ null, %10 ], [ null, %25 ], [ null, %32 ], [ %23, %28 ]
br label %36
36: ; preds = %4, %34
%37 = phi i8* [ %35, %34 ], [ null, %4 ]
ret i8* %37
}