#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);
char *strdup(char *);
int /*<<< orphan*/ strlen(char *);
char *strstr(char *, char *);
char *extract(char *src, char *string) {
  char *s, *t;
  s = strstr(src, string);
  if (s) {
    s += strlen(string);
    s = strdup(s);
    t = strchr(s, ';');
    if (t) {
      *t = '\0';
    }
  }
  return s;
}


x86 assembly (clang, -O0):
<extract>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11bb <extract+0x7b>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x3b,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11b6 <extract+0x76>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
jmp    11bb <extract+0x7b>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
call   1060 <strstr@plt>
test   %rax,%rax
je     1183 <extract+0x43>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
add    %rax,%rbx
mov    %rbx,%rdi
call   1050 <strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x3b,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1185 <extract+0x45>
movb   $0x0,(%rax)
jmp    1185 <extract+0x45>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i8* @extract(i8* %0, i8* %1) {
%3 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%4 = icmp eq i8* %3, null
br i1 %4, label %13, label %5
5: ; preds = %2
%6 = tail call i32 @strlen(i8* %1)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %3, i64 %7
%9 = tail call i8* @strdup(i8* %8)
%10 = tail call i8* @strchr(i8* dereferenceable(1) %9, i8 signext 59)
%11 = icmp eq i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %5
store i8 0, i8* %10
br label %13
13: ; preds = %5, %12, %2
%14 = phi i8* [ %9, %12 ], [ %9, %5 ], [ null, %2 ]
ret i8* %14
}