#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 *strchr(char *, char);
scalar_t__ strcmp(char *, char *);
char *strdup(char *);
size_t strlen(char *);
char *get_lpart(char *str) {
  if (!str || strcmp(str, "None") == 0)
    return str;
  char *new = strdup(str);
  char *tmp = strchr(str, ':');
  if (!tmp)
    return str;
  new[strlen(new) - strlen(tmp)] = 0;
  return new;
}


x86 assembly (clang, -O0):
<get_lpart>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1171 <get_lpart+0x31>
mov    -0x10(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    117e <get_lpart+0x3e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ed <get_lpart+0xad>
mov    -0x10(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b5 <get_lpart+0x75>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ed <get_lpart+0xad>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rcx
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_lpart>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     119e <get_lpart+0x5e>
mov    %rdi,%rbx
lea    0xeac(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11a0 <get_lpart+0x60>
mov    %rbx,%rdi
call   1060 <strdup@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11a0 <get_lpart+0x60>
mov    %rax,%r15
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
sub    %rax,%rbx
movb   $0x0,(%r14,%rbx,1)
mov    %r14,%rbx
jmp    11a0 <get_lpart+0x60>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"None\00"
define i8* @get_lpart(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 %8, label %12
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8, %1
%13 = load i8*, i8** %3
store i8* %13, i8** %2
br label %32
14: ; preds = %8
%15 = load i8*, i8** %3
%16 = call i8* @strdup(i8* %15)
store i8* %16, i8** %4
%17 = load i8*, i8** %3
%18 = call i8* @strchr(i8* %17, i8 signext 58)
store i8* %18, i8** %5
%19 = load i8*, i8** %5
%20 = icmp ne i8* %19, null
br i1 %20, label %23, label %21
21: ; preds = %14
%22 = load i8*, i8** %3
store i8* %22, i8** %2
br label %32
23: ; preds = %14
%24 = load i8*, i8** %4
%25 = load i8*, i8** %4
%26 = call i64 @strlen(i8* %25)
%27 = load i8*, i8** %5
%28 = call i64 @strlen(i8* %27)
%29 = sub i64 %26, %28
%30 = getelementptr inbounds i8, i8* %24, i64 %29
store i8 0, i8* %30
%31 = load i8*, i8** %4
store i8* %31, i8** %2
br label %32
32: ; preds = %23, %21, %12
%33 = load i8*, i8** %2
ret i8* %33
}

LLVM IR (-O2):
@.str = [5 x i8] c"None\00"
define i8* @get_lpart(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %15, label %3
3: ; preds = %1
%4 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %15, label %6
6: ; preds = %3
%7 = tail call i8* @strdup(i8* %0)
%8 = tail call i8* @strchr(i8* %0, i8 signext 58)
%9 = icmp eq i8* %8, null
br i1 %9, label %15, label %10
10: ; preds = %6
%11 = tail call i64 @strlen(i8* dereferenceable(1) %7)
%12 = tail call i64 @strlen(i8* %8)
%13 = sub i64 %11, %12
%14 = getelementptr inbounds i8, i8* %7, i64 %13
store i8 0, i8* %14
br label %15
15: ; preds = %10, %6, %1, %3
%16 = phi i8* [ %0, %3 ], [ null, %1 ], [ %7, %10 ], [ %0, %6 ]
ret i8* %16
}