#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 *skip_char(char const *, char);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
char *until_first(char const *, char);
const char *extract_part(const char str[], char separator, char part_buf[]) {
  const char *end = NULL;
  str = skip_char(str, separator);
  if (str[0] != '\0') {
    end = until_first(str, separator);
    snprintf(part_buf, end - str + 1, "%s", str);
    if (*end != '\0') {
      end++;
    }
  }
  return end;
}


x86 assembly (clang, -O0):
<extract_part>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
movsbl -0x9(%rbp),%esi
call   1040 <skip_char@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11c6 <extract_part+0x96>
mov    -0x8(%rbp),%rdi
movsbl -0x9(%rbp),%esi
call   1050 <until_first@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%esi
mov    -0x8(%rbp),%rcx
lea    0xe60(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11c1 <extract_part+0x91>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11c6 <extract_part+0x96>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_part>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %esi,%ebx
call   1040 <skip_char@plt>
cmpb   $0x0,(%rax)
je     1178 <extract_part+0x48>
mov    %rax,%r15
movsbl %bl,%esi
mov    %rax,%rdi
call   1050 <until_first@plt>
mov    %rax,%rbx
mov    %ebx,%esi
sub    %r15d,%esi
add    $0x1,%esi
lea    0xe9c(%rip),%rdx
mov    %r14,%rdi
mov    %r15,%rcx
call   1030 <snprintf@plt>
cmpb   $0x1,(%rbx)
sbb    $0xffffffffffffffff,%rbx
jmp    117a <extract_part+0x4a>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define i8* @extract_part(i8* %0, i8 signext %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i8 %1, i8* %5
store i8* %2, i8** %6
store i8* null, i8** %7
%8 = load i8*, i8** %4
%9 = load i8, i8* %5
%10 = call i8* @skip_char(i8* %8, i8 signext %9)
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = getelementptr inbounds i8, i8* %11, i64 0
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %38
16: ; preds = %3
%17 = load i8*, i8** %4
%18 = load i8, i8* %5
%19 = call i8* @until_first(i8* %17, i8 signext %18)
store i8* %19, i8** %7
%20 = load i8*, i8** %6
%21 = load i8*, i8** %7
%22 = load i8*, i8** %4
%23 = ptrtoint i8* %21 to i64
%24 = ptrtoint i8* %22 to i64
%25 = sub i64 %23, %24
%26 = add nsw i64 %25, 1
%27 = trunc i64 %26 to i32
%28 = load i8*, i8** %4
%29 = call i32 @snprintf(i8* %20, i32 %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %28)
%30 = load i8*, i8** %7
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %16
%35 = load i8*, i8** %7
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %7
br label %37
37: ; preds = %34, %16
br label %38
38: ; preds = %37, %3
%39 = load i8*, i8** %7
ret i8* %39
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define i8* @extract_part(i8* %0, i8 signext %1, i8* %2) {
%4 = tail call i8* @skip_char(i8* %0, i8 signext %1)
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 0
br i1 %6, label %19, label %7
7: ; preds = %3
%8 = tail call i8* @until_first(i8* %4, i8 signext %1)
%9 = ptrtoint i8* %8 to i64
%10 = ptrtoint i8* %4 to i64
%11 = sub i64 %9, %10
%12 = trunc i64 %11 to i32
%13 = add i32 %12, 1
%14 = tail call i32 @snprintf(i8* %2, i32 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
%15 = load i8, i8* %8
%16 = icmp ne i8 %15, 0
%17 = zext i1 %16 to i64
%18 = getelementptr i8, i8* %8, i64 %17
br label %19
19: ; preds = %7, %3
%20 = phi i8* [ null, %3 ], [ %18, %7 ]
ret i8* %20
}