#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__ isspace(char);
scalar_t__ malloc(int);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int configfile_get_section_name(char *buf, char **name) {
  char *pchstart, *pchend;
  pchstart = &(buf[0]);
  while ((*pchstart) != '[')
    pchstart++;
  pchstart++;
  while (isspace(*pchstart))
    pchstart++;
  pchend = &buf[strlen(buf) - 1];
  while ((*pchend) != ']')
    pchend--;
  pchend--;
  while (isspace(*pchend))
    pchend--;
  *name = (char *)malloc(sizeof(char) * (pchend - pchstart + 2));
  strncpy(*name, pchstart, pchend - pchstart + 1);
  (*name)[pchend - pchstart + 1] = '\0';
  return 1;
}


x86 assembly (clang, -O0):
<configfile_get_section_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5b,%eax
je     1179 <configfile_get_section_name+0x39>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1158 <configfile_get_section_name+0x18>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
je     11ac <configfile_get_section_name+0x6c>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1185 <configfile_get_section_name+0x45>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5d,%eax
je     11f1 <configfile_get_section_name+0xb1>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    11d0 <configfile_get_section_name+0x90>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
je     1224 <configfile_get_section_name+0xe4>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    11fd <configfile_get_section_name+0xbd>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
add    $0x2,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,0x1(%rax,%rcx,1)
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<configfile_get_section_name>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0xfffffffffffffffd,%rbp
nopl   0x0(%rax,%rax,1)
cmpb   $0x5b,0x3(%r15,%rbp,1)
lea    0x1(%rbp),%rbp
jne    1160 <configfile_get_section_name+0x20>
nopl   0x0(%rax)
movsbl 0x3(%r15,%rbp,1),%edi
call   1050 <isspace@plt>
add    $0x1,%rbp
test   %rax,%rax
jne    1170 <configfile_get_section_name+0x30>
mov    %r15,%rdi
call   1040 <strlen@plt>
movslq %eax,%r13
lea    -0x1(%r13),%r12
lea    (%r15,%r13,1),%rbx
add    $0xffffffffffffffff,%rbx
sub    %rbp,%r12
sub    %ebp,%r13d
add    %rbp,%r15
add    $0x2,%r15
nopl   0x0(%rax,%rax,1)
add    $0xffffffffffffffff,%r12
add    $0xffffffff,%r13d
cmpb   $0x5d,(%rbx)
lea    -0x1(%rbx),%rbx
jne    11b0 <configfile_get_section_name+0x70>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl (%rbx),%edi
call   1050 <isspace@plt>
add    $0xffffffff,%r13d
add    $0xffffffffffffffff,%r12
add    $0xffffffffffffffff,%rbx
test   %rax,%rax
jne    11d0 <configfile_get_section_name+0x90>
mov    %r13d,%edi
call   1060 <malloc@plt>
mov    %rax,(%r14)
add    $0xffffffff,%r13d
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r13d,%edx
call   1030 <strncpy@plt>
mov    (%r14),%rax
movb   $0x0,(%rax,%r12,1)
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @configfile_get_section_name(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 = getelementptr inbounds i8, i8* %7, i64 0
store i8* %8, i8** %5
br label %9
9: ; preds = %14, %2
%10 = load i8*, i8** %5
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 91
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %5
br label %9
17: ; preds = %9
%18 = load i8*, i8** %5
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %5
br label %20
20: ; preds = %25, %17
%21 = load i8*, i8** %5
%22 = load i8, i8* %21
%23 = call i64 @isspace(i8 signext %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load i8*, i8** %5
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %5
br label %20
28: ; preds = %20
%29 = load i8*, i8** %3
%30 = load i8*, i8** %3
%31 = call i32 @strlen(i8* %30)
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %29, i64 %33
store i8* %34, i8** %6
br label %35
35: ; preds = %40, %28
%36 = load i8*, i8** %6
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 93
br i1 %39, label %40, label %43
40: ; preds = %35
%41 = load i8*, i8** %6
%42 = getelementptr inbounds i8, i8* %41, i32 -1
store i8* %42, i8** %6
br label %35
43: ; preds = %35
%44 = load i8*, i8** %6
%45 = getelementptr inbounds i8, i8* %44, i32 -1
store i8* %45, i8** %6
br label %46
46: ; preds = %51, %43
%47 = load i8*, i8** %6
%48 = load i8, i8* %47
%49 = call i64 @isspace(i8 signext %48)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %46
%52 = load i8*, i8** %6
%53 = getelementptr inbounds i8, i8* %52, i32 -1
store i8* %53, i8** %6
br label %46
54: ; preds = %46
%55 = load i8*, i8** %6
%56 = load i8*, i8** %5
%57 = ptrtoint i8* %55 to i64
%58 = ptrtoint i8* %56 to i64
%59 = sub i64 %57, %58
%60 = add nsw i64 %59, 2
%61 = mul i64 1, %60
%62 = trunc i64 %61 to i32
%63 = call i64 @malloc(i32 %62)
%64 = inttoptr i64 %63 to i8*
%65 = load i8**, i8*** %4
store i8* %64, i8** %65
%66 = load i8**, i8*** %4
%67 = load i8*, i8** %66
%68 = load i8*, i8** %5
%69 = load i8*, i8** %6
%70 = load i8*, i8** %5
%71 = ptrtoint i8* %69 to i64
%72 = ptrtoint i8* %70 to i64
%73 = sub i64 %71, %72
%74 = add nsw i64 %73, 1
%75 = trunc i64 %74 to i32
%76 = call i32 @strncpy(i8* %67, i8* %68, i32 %75)
%77 = load i8**, i8*** %4
%78 = load i8*, i8** %77
%79 = load i8*, i8** %6
%80 = load i8*, i8** %5
%81 = ptrtoint i8* %79 to i64
%82 = ptrtoint i8* %80 to i64
%83 = sub i64 %81, %82
%84 = add nsw i64 %83, 1
%85 = getelementptr inbounds i8, i8* %78, i64 %84
store i8 0, i8* %85
ret i32 1
}

LLVM IR (-O2):
define i32 @configfile_get_section_name(i8* %0, i8** nocapture %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i8* [ %0, %2 ], [ %7, %3 ]
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 91
%7 = getelementptr inbounds i8, i8* %4, i64 1
br i1 %6, label %8, label %3
8: ; preds = %3, %8
%9 = phi i8* [ %10, %8 ], [ %4, %3 ]
%10 = getelementptr inbounds i8, i8* %9, i64 1
%11 = load i8, i8* %10
%12 = tail call i64 @isspace(i8 signext %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %8
14: ; preds = %8
%15 = tail call i32 @strlen(i8* %0)
%16 = add nsw i32 %15, -1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
br label %19
19: ; preds = %19, %14
%20 = phi i8* [ %18, %14 ], [ %23, %19 ]
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 93
%23 = getelementptr inbounds i8, i8* %20, i64 -1
br i1 %22, label %24, label %19
24: ; preds = %19, %24
%25 = phi i8* [ %26, %24 ], [ %20, %19 ]
%26 = getelementptr inbounds i8, i8* %25, i64 -1
%27 = load i8, i8* %26
%28 = tail call i64 @isspace(i8 signext %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %24
30: ; preds = %24
%31 = ptrtoint i8* %26 to i64
%32 = ptrtoint i8* %10 to i64
%33 = sub i64 %31, %32
%34 = trunc i64 %33 to i32
%35 = add i32 %34, 2
%36 = tail call i64 @malloc(i32 %35)
%37 = inttoptr i64 %36 to i8*
store i8* %37, i8** %1
%38 = add nsw i64 %33, 1
%39 = trunc i64 %38 to i32
%40 = tail call i32 @strncpy(i8* %37, i8* %10, i32 %39)
%41 = load i8*, i8** %1
%42 = getelementptr inbounds i8, i8* %41, i64 %38
store i8 0, i8* %42
ret i32 1
}