#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 *str_getline(char *, char *, int);
int strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
char *mime_find_next_section(char *buffer, char *boundary) {
  char linebuf[1024];
  char *curptr = buffer;
  while (1) {
    char *nextptr;
    if (!curptr)
      return (0);
    nextptr = str_getline(curptr, linebuf, 1024);
    if (linebuf[0] == '-' && linebuf[1] == '-') {
      if (!strncmp(linebuf + 2, boundary, strlen(boundary))) {
        if (linebuf[2 + strlen(boundary)] == '-')
          return (0);
        else
          return (curptr);
      }
    }
    curptr = nextptr;
  }
}


x86 assembly (clang, -O0):
<mime_find_next_section>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
jne    1169 <mime_find_next_section+0x39>
movq   $0x0,-0x8(%rbp)
jmp    1240 <mime_find_next_section+0x110>
mov    -0x428(%rbp),%rdi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1040 <str_getline@plt>
mov    %rax,-0x430(%rbp)
movsbl -0x420(%rbp),%eax
cmp    $0x2d,%eax
jne    122d <mime_find_next_section+0xfd>
movsbl -0x41f(%rbp),%eax
cmp    $0x2d,%eax
jne    122d <mime_find_next_section+0xfd>
lea    -0x420(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x440(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x438(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x440(%rbp),%rdi
mov    -0x438(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1228 <mime_find_next_section+0xf8>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x2,%eax
cltq
movsbl -0x420(%rbp,%rax,1),%eax
ff
cmp    $0x2d,%eax
jne    1218 <mime_find_next_section+0xe8>
movq   $0x0,-0x8(%rbp)
jmp    1240 <mime_find_next_section+0x110>
mov    -0x428(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1240 <mime_find_next_section+0x110>
jmp    122d <mime_find_next_section+0xfd>
mov    -0x430(%rbp),%rax
mov    %rax,-0x428(%rbp)
jmp    114e <mime_find_next_section+0x1e>
mov    -0x8(%rbp),%rax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mime_find_next_section>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x400,%rsp
test   %rdi,%rdi
je     11b9 <mime_find_next_section+0x89>
mov    %rsi,%r14
mov    %rdi,%r13
lea    0x2(%rsp),%r12
mov    %rsp,%r15
jmp    1168 <mime_find_next_section+0x38>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%r13
test   %rbx,%rbx
je     11b9 <mime_find_next_section+0x89>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0x400,%edx
call   1040 <str_getline@plt>
mov    %rax,%rbx
cmpb   $0x2d,(%rsp)
jne    1160 <mime_find_next_section+0x30>
cmpb   $0x2d,0x1(%rsp)
jne    1160 <mime_find_next_section+0x30>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1160 <mime_find_next_section+0x30>
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
xor    %ecx,%ecx
cmpb   $0x2d,0x2(%rax,%r15,1)
cmove  %rcx,%r13
jmp    11bc <mime_find_next_section+0x8c>
xor    %r13d,%r13d
mov    %r13,%rax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @mime_find_next_section(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [1024 x i8]
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
store i8* %9, i8** %7
br label %10
10: ; preds = %2, %48
%11 = load i8*, i8** %7
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %10
store i8* null, i8** %3
br label %50
14: ; preds = %10
%15 = load i8*, i8** %7
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%17 = call i8* @str_getline(i8* %15, i8* %16, i32 1024)
store i8* %17, i8** %8
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 45
br i1 %21, label %22, label %48
22: ; preds = %14
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 1
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 45
br i1 %26, label %27, label %48
27: ; preds = %22
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%29 = getelementptr inbounds i8, i8* %28, i64 2
%30 = load i8*, i8** %5
%31 = load i8*, i8** %5
%32 = call i32 @strlen(i8* %31)
%33 = call i32 @strncmp(i8* %29, i8* %30, i32 %32)
%34 = icmp ne i32 %33, 0
br i1 %34, label %47, label %35
35: ; preds = %27
%36 = load i8*, i8** %5
%37 = call i32 @strlen(i8* %36)
%38 = add nsw i32 2, %37
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 45
br i1 %43, label %44, label %45
44: ; preds = %35
store i8* null, i8** %3
br label %50
45: ; preds = %35
%46 = load i8*, i8** %7
store i8* %46, i8** %3
br label %50
47: ; preds = %27
br label %48
48: ; preds = %47, %22, %14
%49 = load i8*, i8** %8
store i8* %49, i8** %7
br label %10
50: ; preds = %45, %44, %13
%51 = load i8*, i8** %3
ret i8* %51
}

LLVM IR (-O2):
define i8* @mime_find_next_section(i8* %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp eq i8* %0, null
br i1 %5, label %31, label %6
6: ; preds = %2
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 1
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 2
br label %9
9: ; preds = %6, %29
%10 = phi i8* [ %0, %6 ], [ %11, %29 ]
%11 = call i8* @str_getline(i8* %10, i8* %4, i32 1024)
%12 = load i8, i8* %4
%13 = icmp eq i8 %12, 45
%14 = load i8, i8* %7
%15 = icmp eq i8 %14, 45
%16 = select i1 %13, i1 %15, i1 false
br i1 %16, label %17, label %29
17: ; preds = %9
%18 = call i32 @strlen(i8* %1)
%19 = call i32 @strncmp(i8* %8, i8* %1, i32 %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %17
%22 = call i32 @strlen(i8* %1)
%23 = add nsw i32 %22, 2
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 45
%28 = select i1 %27, i8* null, i8* %10
br label %31
29: ; preds = %9, %17
%30 = icmp eq i8* %11, null
br i1 %30, label %31, label %9
31: ; preds = %29, %2, %21
%32 = phi i8* [ %28, %21 ], [ null, %2 ], [ null, %29 ]
ret i8* %32
}