#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 */
int MIN(int, int);
char *strchr(char const *, char);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *extract_ifname(const char *name) {
  char *cp;
  int len;
  static char ifname[64];
  if ((cp = strchr(name, ':')) != NULL)
    len = cp - name;
  else
    len = strlen(name);
  len = MIN(len, 63);
  strncpy(ifname, name, len);
  ifname[len] = '\0';
  return (ifname);
}


x86 assembly (clang, -O0):
<extract_ifname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     117b <extract_ifname+0x3b>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x14(%rbp)
jmp    1187 <extract_ifname+0x47>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x3f,%esi
call   1040 <MIN@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0x2eab(%rip),%rdi
call   1030 <strncpy@plt>
movslq -0x14(%rbp),%rcx
lea    0x2e9b(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e90(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_ifname>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    $0x3a,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     115a <extract_ifname+0x1a>
sub    %ebx,%eax
jmp    1162 <extract_ifname+0x22>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
mov    $0x3f,%esi
call   1040 <MIN@plt>
mov    %eax,%ebp
lea    0x2ed9(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
movslq %ebp,%rax
movb   $0x0,(%rax,%r14,1)
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@extract_ifname.ifname = internal global [64 x i8] zeroinitializer
define i8* @extract_ifname(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i8* @strchr(i8* %5, i8 signext 58)
store i8* %6, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %15
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = load i8*, i8** %2
%11 = ptrtoint i8* %9 to i64
%12 = ptrtoint i8* %10 to i64
%13 = sub i64 %11, %12
%14 = trunc i64 %13 to i32
store i32 %14, i32* %4
br label %18
15: ; preds = %1
%16 = load i8*, i8** %2
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %4
br label %18
18: ; preds = %15, %8
%19 = load i32, i32* %4
%20 = call i32 @MIN(i32 %19, i32 63)
store i32 %20, i32* %4
%21 = load i8*, i8** %2
%22 = load i32, i32* %4
%23 = call i32 @strncpy(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @extract_ifname.ifname, i64 0, i64 0), i8* %21, i32 %22)
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [64 x i8], [64 x i8]* @extract_ifname.ifname, i64 0, i64 %25
store i8 0, i8* %26
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @extract_ifname.ifname, i64 0, i64 0)
}

LLVM IR (-O2):
@extract_ifname.ifname = internal global [64 x i8] zeroinitializer
define i8* @extract_ifname(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 58)
%3 = icmp eq i8* %2, null
br i1 %3, label %9, label %4
4: ; preds = %1
%5 = ptrtoint i8* %2 to i64
%6 = ptrtoint i8* %0 to i64
%7 = sub i64 %5, %6
%8 = trunc i64 %7 to i32
br label %11
9: ; preds = %1
%10 = tail call i32 @strlen(i8* %0)
br label %11
11: ; preds = %9, %4
%12 = phi i32 [ %8, %4 ], [ %10, %9 ]
%13 = tail call i32 @MIN(i32 %12, i32 63)
%14 = tail call i32 @strncpy(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @extract_ifname.ifname, i64 0, i64 0), i8* %0, i32 %13)
%15 = sext i32 %13 to i64
%16 = getelementptr inbounds [64 x i8], [64 x i8]* @extract_ifname.ifname, i64 0, i64 %15
store i8 0, i8* %16
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @extract_ifname.ifname, i64 0, i64 0)
}