#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 /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *strchr(char *, char);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, scalar_t__);
char *strstr(char *, char *);
char *getattr(char *buffer, char *what) {
  char *aux;
  char *aux2;
  char *result = (char *)malloc(1024);
  memset(result, 0, 1024);
  aux = strstr(buffer, what);
  if (aux) {
    char c;
    aux += strlen(what);
    c = *aux++;
    aux2 = strchr(aux, c);
    if (aux2) {
      strncpy(result, aux, strlen(aux) - strlen(aux2));
      return result;
    }
  }
  free(result);
  return NULL;
}


x86 assembly (clang, -O0):
<getattr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x400,%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1247 <getattr+0xd7>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%al
mov    %al,-0x31(%rbp)
mov    -0x20(%rbp),%rdi
movsbl -0x31(%rbp),%esi
call   1060 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1242 <getattr+0xd2>
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x50(%rbp),%rdx
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
sub    %rax,%rdx
call   1040 <strncpy@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1258 <getattr+0xe8>
jmp    1247 <getattr+0xd7>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getattr>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x400,%edi
call   1080 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     11f7 <getattr+0x87>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    (%rbx,%rax,1),%r14
add    $0x1,%r14
movsbl (%rbx,%rax,1),%esi
mov    %r14,%rdi
call   1060 <strchr@plt>
test   %rax,%rax
je     11f7 <getattr+0x87>
mov    %rax,%r15
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
sub    %rax,%rbx
mov    %r12,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <strncpy@plt>
jmp    1202 <getattr+0x92>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %r12d,%r12d
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @getattr(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = call i64 @malloc(i32 1024)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %8
%12 = load i8*, i8** %8
%13 = call i32 @memset(i8* %12, i32 0, i32 1024)
%14 = load i8*, i8** %4
%15 = load i8*, i8** %5
%16 = call i8* @strstr(i8* %14, i8* %15)
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %43
19: ; preds = %2
%20 = load i8*, i8** %5
%21 = call i64 @strlen(i8* %20)
%22 = load i8*, i8** %6
%23 = getelementptr inbounds i8, i8* %22, i64 %21
store i8* %23, i8** %6
%24 = load i8*, i8** %6
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %6
%26 = load i8, i8* %24
store i8 %26, i8* %9
%27 = load i8*, i8** %6
%28 = load i8, i8* %9
%29 = call i8* @strchr(i8* %27, i8 signext %28)
store i8* %29, i8** %7
%30 = load i8*, i8** %7
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %42
32: ; preds = %19
%33 = load i8*, i8** %8
%34 = load i8*, i8** %6
%35 = load i8*, i8** %6
%36 = call i64 @strlen(i8* %35)
%37 = load i8*, i8** %7
%38 = call i64 @strlen(i8* %37)
%39 = sub nsw i64 %36, %38
%40 = call i32 @strncpy(i8* %33, i8* %34, i64 %39)
%41 = load i8*, i8** %8
store i8* %41, i8** %3
br label %46
42: ; preds = %19
br label %43
43: ; preds = %42, %2
%44 = load i8*, i8** %8
%45 = call i32 @free(i8* %44)
store i8* null, i8** %3
br label %46
46: ; preds = %43, %32
%47 = load i8*, i8** %3
ret i8* %47
}

LLVM IR (-O2):
define i8* @getattr(i8* %0, i8* nocapture %1) {
%3 = tail call i64 @malloc(i32 1024)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 @memset(i8* %4, i32 0, i32 1024)
%6 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%7 = icmp eq i8* %6, null
br i1 %7, label %20, label %8
8: ; preds = %2
%9 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%10 = getelementptr inbounds i8, i8* %6, i64 %9
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = load i8, i8* %10
%13 = tail call i8* @strchr(i8* %11, i8 signext %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %20, label %15
15: ; preds = %8
%16 = tail call i64 @strlen(i8* %11)
%17 = tail call i64 @strlen(i8* %13)
%18 = sub nsw i64 %16, %17
%19 = tail call i32 @strncpy(i8* %4, i8* %11, i64 %18)
br label %22
20: ; preds = %8, %2
%21 = tail call i32 @free(i8* %4)
br label %22
22: ; preds = %15, %20
%23 = phi i8* [ null, %20 ], [ %4, %15 ]
ret i8* %23
}