#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 */

/* Variables and functions */
char *malloc(int /*<<< orphan*/);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
char *hc_imag_part(char *num) {
  if (!num)
    return NULL;
  char *ipos = strchr(num, 'i');
  if (ipos) {
    char *ret = malloc(strlen(ipos));
    strcpy(ret, (char *)(ipos + sizeof(char)));
    return ret;
  } else {
    return NULL;
  }
}


x86 assembly (clang, -O0):
<hc_imag_part>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1164 <hc_imag_part+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11bb <hc_imag_part+0x7b>
mov    -0x10(%rbp),%rdi
mov    $0x69,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11b3 <hc_imag_part+0x73>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11bb <hc_imag_part+0x7b>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hc_imag_part>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     117e <hc_imag_part+0x3e>
mov    $0x69,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     117e <hc_imag_part+0x3e>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
add    $0x1,%rbx
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
jmp    1181 <hc_imag_part+0x41>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @hc_imag_part(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %1
store i8* null, i8** %2
br label %24
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i8* @strchr(i8* %10, i8 signext 105)
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %23
14: ; preds = %9
%15 = load i8*, i8** %4
%16 = call i32 @strlen(i8* %15)
%17 = call i8* @malloc(i32 %16)
store i8* %17, i8** %5
%18 = load i8*, i8** %5
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = call i32 @strcpy(i8* %18, i8* %20)
%22 = load i8*, i8** %5
store i8* %22, i8** %2
br label %24
23: ; preds = %9
store i8* null, i8** %2
br label %24
24: ; preds = %23, %14, %8
%25 = load i8*, i8** %2
ret i8* %25
}

LLVM IR (-O2):
define i8* @hc_imag_part(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %11, label %3
3: ; preds = %1
%4 = tail call i8* @strchr(i8* %0, i8 signext 105)
%5 = icmp eq i8* %4, null
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = tail call i32 @strlen(i8* %4)
%8 = tail call i8* @malloc(i32 %7)
%9 = getelementptr inbounds i8, i8* %4, i64 1
%10 = tail call i32 @strcpy(i8* %8, i8* %9)
br label %11
11: ; preds = %6, %3, %1
%12 = phi i8* [ null, %1 ], [ %8, %6 ], [ null, %3 ]
ret i8* %12
}