#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);
char *strchr(char *, char);
char *strdup(char *);
size_t strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
char *hc_real_part(char *num) {
  if (!num)
    return NULL;
  char *ipos = strchr(num, 'i');
  char *ret;
  if (ipos) {
    ret = malloc(strlen(num) - strlen(ipos) + 1);
    strncpy(ret, num, strlen(num) - strlen(ipos));
    ret[strlen(num) - strlen(ipos)] = '\0';
  } else {
    ret = strdup(num);
  }
  return ret;
}


x86 assembly (clang, -O0):
<hc_real_part>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1174 <hc_real_part+0x24>
movq   $0x0,-0x8(%rbp)
jmp    1244 <hc_real_part+0xf4>
mov    -0x10(%rbp),%rdi
mov    $0x69,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     122f <hc_real_part+0xdf>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rdx
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
sub    %rax,%rdx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rcx
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    123c <hc_real_part+0xec>
mov    -0x10(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hc_real_part>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     11c0 <hc_real_part+0x70>
mov    %rdi,%rbx
mov    $0x69,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11d2 <hc_real_part+0x82>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rax,%r12
mov    %r14,%rdi
call   1040 <strlen@plt>
sub    %rax,%r12
lea    0x1(%r12),%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
sub    %rax,%rbx
movb   $0x0,(%r15,%rbx,1)
jmp    11c3 <hc_real_part+0x73>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1070 <strdup@plt>

LLVM IR (-O0):
define i8* @hc_real_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 %43
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 %38
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = call i64 @strlen(i8* %15)
%17 = load i8*, i8** %4
%18 = call i64 @strlen(i8* %17)
%19 = sub i64 %16, %18
%20 = add i64 %19, 1
%21 = trunc i64 %20 to i32
%22 = call i8* @malloc(i32 %21)
store i8* %22, i8** %5
%23 = load i8*, i8** %5
%24 = load i8*, i8** %3
%25 = load i8*, i8** %3
%26 = call i64 @strlen(i8* %25)
%27 = load i8*, i8** %4
%28 = call i64 @strlen(i8* %27)
%29 = sub i64 %26, %28
%30 = call i32 @strncpy(i8* %23, i8* %24, i64 %29)
%31 = load i8*, i8** %5
%32 = load i8*, i8** %3
%33 = call i64 @strlen(i8* %32)
%34 = load i8*, i8** %4
%35 = call i64 @strlen(i8* %34)
%36 = sub i64 %33, %35
%37 = getelementptr inbounds i8, i8* %31, i64 %36
store i8 0, i8* %37
br label %41
38: ; preds = %9
%39 = load i8*, i8** %3
%40 = call i8* @strdup(i8* %39)
store i8* %40, i8** %5
br label %41
41: ; preds = %38, %14
%42 = load i8*, i8** %5
store i8* %42, i8** %2
br label %43
43: ; preds = %41, %8
%44 = load i8*, i8** %2
ret i8* %44
}

LLVM IR (-O2):
define i8* @hc_real_part(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %20, 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 %18, label %6
6: ; preds = %3
%7 = tail call i64 @strlen(i8* %0)
%8 = tail call i64 @strlen(i8* %4)
%9 = sub i64 %7, %8
%10 = trunc i64 %9 to i32
%11 = add i32 %10, 1
%12 = tail call i8* @malloc(i32 %11)
%13 = tail call i32 @strncpy(i8* %12, i8* %0, i64 %9)
%14 = tail call i64 @strlen(i8* %0)
%15 = tail call i64 @strlen(i8* %4)
%16 = sub i64 %14, %15
%17 = getelementptr inbounds i8, i8* %12, i64 %16
store i8 0, i8* %17
br label %20
18: ; preds = %3
%19 = tail call i8* @strdup(i8* %0)
br label %20
20: ; preds = %6, %18, %1
%21 = phi i8* [ null, %1 ], [ %12, %6 ], [ %19, %18 ]
ret i8* %21
}