#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 */
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ strcat(char *, char const *);
scalar_t__ strlen(char const *);
char *strstr(char const *, char *);
char *SearchSection(const char *buf, const char *section) {
  char *found = NULL;
  char *ext_section;
  ext_section = (char *)malloc(1 + strlen(section) + 1 + 1);
  ext_section[0] = '[';
  ext_section[1] = '\0';
  strcat(ext_section, section);
  strcat(ext_section, "]");
  found = strstr(buf, ext_section);
  if (found)
    return found + 1;
  else
    return NULL;
}


x86 assembly (clang, -O0):
<SearchSection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
add    $0x1,%rdi
add    $0x1,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x5b,(%rax)
mov    -0x28(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x28(%rbp),%rdi
lea    0xe60(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11d2 <SearchSection+0x92>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11da <SearchSection+0x9a>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SearchSection>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
lea    0x3(%rax),%rdi
call   1040 <malloc@plt>
mov    %rax,%rbx
movw   $0x5b,(%rax)
mov    %rax,%rdi
mov    %r15,%rsi
call   1050 <strcat@plt>
lea    0xe8a(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <strstr@plt>
lea    0x1(%rax),%rcx
test   %rax,%rax
cmovne %rcx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"]\00"
define i8* @SearchSection(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* null, i8** %6
%8 = load i8*, i8** %5
%9 = call i64 @strlen(i8* %8)
%10 = add nsw i64 1, %9
%11 = add nsw i64 %10, 1
%12 = add nsw i64 %11, 1
%13 = call i64 @malloc(i64 %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %7
%15 = load i8*, i8** %7
%16 = getelementptr inbounds i8, i8* %15, i64 0
store i8 91, i8* %16
%17 = load i8*, i8** %7
%18 = getelementptr inbounds i8, i8* %17, i64 1
store i8 0, i8* %18
%19 = load i8*, i8** %7
%20 = load i8*, i8** %5
%21 = call i32 @strcat(i8* %19, i8* %20)
%22 = load i8*, i8** %7
%23 = call i32 @strcat(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%24 = load i8*, i8** %4
%25 = load i8*, i8** %7
%26 = call i8* @strstr(i8* %24, i8* %25)
store i8* %26, i8** %6
%27 = load i8*, i8** %6
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %32
29: ; preds = %2
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i64 1
store i8* %31, i8** %3
br label %33
32: ; preds = %2
store i8* null, i8** %3
br label %33
33: ; preds = %32, %29
%34 = load i8*, i8** %3
ret i8* %34
}

LLVM IR (-O2):
@.str = [2 x i8] c"]\00"
define i8* @SearchSection(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = add nsw i64 %3, 3
%5 = tail call i64 @malloc(i64 %4)
%6 = inttoptr i64 %5 to i8*
store i8 91, i8* %6
%7 = getelementptr inbounds i8, i8* %6, i64 1
store i8 0, i8* %7
%8 = tail call i32 @strcat(i8* %6, i8* %1)
%9 = tail call i32 @strcat(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* %6)
%11 = icmp eq i8* %10, null
%12 = getelementptr inbounds i8, i8* %10, i64 1
%13 = select i1 %11, i8* null, i8* %12
ret i8* %13
}