#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*/ assert(int /*<<< orphan*/);
char *find_section_start(char *s, int n) {
  int i = 0;
  assert(n >= 0 && "Invalid section number");
  if (n == 0)
    return s;
  int idx = 0;
  while (i < n && (*s) != (char)0) {
    if (s[0] == '%' && s[1] == '%' && s[2] == '\n') {
      i++;
    }
    s++;
    idx++;
  }
  if (*s != (char)0)
    return s + 2;
  return s;
}


x86 assembly (clang, -O0):
<find_section_start>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x1d(%rbp)
jl     113f <find_section_start+0x2f>
mov    $0x1,%al
mov    %al,-0x1d(%rbp)
jmp    113f <find_section_start+0x2f>
mov    -0x1d(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0x0,-0x14(%rbp)
jne    1163 <find_section_start+0x53>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1219 <find_section_start+0x109>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%ecx
xor    %eax,%eax
cmp    -0x14(%rbp),%ecx
mov    %al,-0x1e(%rbp)
jge    118b <find_section_start+0x7b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x1e(%rbp)
mov    -0x1e(%rbp),%al
test   $0x1,%al
jne    119b <find_section_start+0x8b>
jmp    11f0 <find_section_start+0xe0>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    11d6 <find_section_start+0xc6>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x25,%eax
jne    11d6 <find_section_start+0xc6>
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0xa,%eax
jne    11d6 <find_section_start+0xc6>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116a <find_section_start+0x5a>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1211 <find_section_start+0x101>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
jmp    1219 <find_section_start+0x109>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_section_start>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %esi,%edi
not    %edi
shr    $0x1f,%edi
call   1030 <assert@plt>
test   %ebp,%ebp
je     1163 <find_section_start+0x53>
jle    1157 <find_section_start+0x47>
xor    %eax,%eax
jmp    113c <find_section_start+0x2c>
xchg   %ax,%ax
test   %cl,%cl
je     1157 <find_section_start+0x47>
add    $0x1,%rbx
cmp    %ebp,%eax
jge    1157 <find_section_start+0x47>
movzbl (%rbx),%ecx
cmp    $0x25,%cl
jne    1130 <find_section_start+0x20>
cmpb   $0x25,0x1(%rbx)
jne    1134 <find_section_start+0x24>
xor    %ecx,%ecx
cmpb   $0xa,0x2(%rbx)
sete   %cl
add    %ecx,%eax
jmp    1134 <find_section_start+0x24>
xor    %eax,%eax
cmpb   $0x0,(%rbx)
setne  %al
lea    (%rbx,%rax,2),%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Invalid section number\00"
define i8* @find_section_start(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 0, i32* %6
%8 = load i32, i32* %5
%9 = icmp sge i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
br label %11
11: ; preds = %10, %2
%12 = phi i1 [ false, %2 ], [ true, %10 ]
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i32, i32* %5
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = load i8*, i8** %4
store i8* %18, i8** %3
br label %67
19: ; preds = %11
store i32 0, i32* %7
br label %20
20: ; preds = %52, %19
%21 = load i32, i32* %6
%22 = load i32, i32* %5
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %29
24: ; preds = %20
%25 = load i8*, i8** %4
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 0
br label %29
29: ; preds = %24, %20
%30 = phi i1 [ false, %20 ], [ %28, %24 ]
br i1 %30, label %31, label %57
31: ; preds = %29
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 37
br i1 %36, label %37, label %52
37: ; preds = %31
%38 = load i8*, i8** %4
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 37
br i1 %42, label %43, label %52
43: ; preds = %37
%44 = load i8*, i8** %4
%45 = getelementptr inbounds i8, i8* %44, i64 2
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 10
br i1 %48, label %49, label %52
49: ; preds = %43
%50 = load i32, i32* %6
%51 = add nsw i32 %50, 1
store i32 %51, i32* %6
br label %52
52: ; preds = %49, %43, %37, %31
%53 = load i8*, i8** %4
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %4
%55 = load i32, i32* %7
%56 = add nsw i32 %55, 1
store i32 %56, i32* %7
br label %20
57: ; preds = %29
%58 = load i8*, i8** %4
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %65
62: ; preds = %57
%63 = load i8*, i8** %4
%64 = getelementptr inbounds i8, i8* %63, i64 2
store i8* %64, i8** %3
br label %67
65: ; preds = %57
%66 = load i8*, i8** %4
store i8* %66, i8** %3
br label %67
67: ; preds = %65, %62, %17
%68 = load i8*, i8** %3
ret i8* %68
}

LLVM IR (-O2):
define i8* @find_section_start(i8* %0, i32 %1) {
%3 = xor i32 %1, -1
%4 = lshr i32 %3, 31
%5 = tail call i32 @assert(i32 %4)
%6 = icmp eq i32 %1, 0
br i1 %6, label %33, label %7
7: ; preds = %2
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %27
9: ; preds = %7, %23
%10 = phi i32 [ %24, %23 ], [ 0, %7 ]
%11 = phi i8* [ %25, %23 ], [ %0, %7 ]
%12 = load i8, i8* %11
switch i8 %12, label %23 [
i8 0, label %27
i8 37, label %13
]
13: ; preds = %9
%14 = getelementptr inbounds i8, i8* %11, i64 1
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 37
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = getelementptr inbounds i8, i8* %11, i64 2
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 10
%21 = zext i1 %20 to i32
%22 = add nsw i32 %10, %21
br label %23
23: ; preds = %17, %9, %13
%24 = phi i32 [ %10, %13 ], [ %10, %9 ], [ %22, %17 ]
%25 = getelementptr inbounds i8, i8* %11, i64 1
%26 = icmp slt i32 %24, %1
br i1 %26, label %9, label %27
27: ; preds = %23, %9, %7
%28 = phi i8* [ %0, %7 ], [ %11, %9 ], [ %25, %23 ]
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 0
%31 = select i1 %30, i64 0, i64 2
%32 = getelementptr i8, i8* %28, i64 %31
br label %33
33: ; preds = %2, %27
%34 = phi i8* [ %32, %27 ], [ %0, %2 ]
ret i8* %34
}