#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*/ O_RDONLY;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
char *find_section_start(char *, int);
int open(char *, int /*<<< orphan*/);
char *readfile(int);
void test_section_jumping() {
  int fd;
  char *p, *s;
  fd = open("input_sections", O_RDONLY);
  assert(fd > 1 && "Couldn't open file to read test input");
  p = readfile(fd);
  s = find_section_start(p, 0);
  assert(p == s && "Couldn't find zeroth section");
  s = find_section_start(p, 1);
  assert(p + 3 == s && "Couldn't find first section");
  s = find_section_start(p, 2);
  assert(p + 3 + 5 == s && "Couldn't find third section");
}


x86 assembly (clang, -O0):
<test_section_jumping>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
lea    0xea8(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x4(%rbp)
xor    %eax,%eax
cmpl   $0x1,-0x4(%rbp)
mov    %al,-0x19(%rbp)
jle    1179 <test_section_jumping+0x39>
mov    $0x1,%al
mov    %al,-0x19(%rbp)
jmp    1179 <test_section_jumping+0x39>
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x4(%rbp),%edi
call   1060 <readfile@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1030 <find_section_start@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmp    -0x18(%rbp),%rcx
mov    %al,-0x1a(%rbp)
jne    11be <test_section_jumping+0x7e>
mov    $0x1,%al
mov    %al,-0x1a(%rbp)
jmp    11be <test_section_jumping+0x7e>
mov    -0x1a(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1030 <find_section_start@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rcx
add    $0x3,%rcx
xor    %eax,%eax
cmp    -0x18(%rbp),%rcx
mov    %al,-0x1b(%rbp)
jne    11fe <test_section_jumping+0xbe>
mov    $0x1,%al
mov    %al,-0x1b(%rbp)
jmp    11fe <test_section_jumping+0xbe>
mov    -0x1b(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    $0x2,%esi
call   1030 <find_section_start@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rcx
add    $0x3,%rcx
add    $0x5,%rcx
xor    %eax,%eax
cmp    -0x18(%rbp),%rcx
mov    %al,-0x1c(%rbp)
jne    1242 <test_section_jumping+0x102>
mov    $0x1,%al
mov    %al,-0x1c(%rbp)
jmp    1242 <test_section_jumping+0x102>
mov    -0x1c(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_section_jumping>:
push   %rbx
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
lea    0xeaf(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
xor    %edi,%edi
cmp    $0x2,%eax
setge  %dil
call   1040 <assert@plt>
mov    %ebx,%edi
call   1060 <readfile@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
call   1030 <find_section_start@plt>
xor    %edi,%edi
cmp    %rax,%rbx
sete   %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <find_section_start@plt>
lea    0x3(%rbx),%rcx
xor    %edi,%edi
cmp    %rax,%rcx
sete   %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
call   1030 <find_section_start@plt>
add    $0x8,%rbx
xor    %edi,%edi
cmp    %rax,%rbx
sete   %dil
pop    %rbx
jmp    1040 <assert@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"input_sections\00"
@O_RDONLY = global i32 0
@.str.1 = [38 x i8] c"Couldn't open file to read test input\00"
@.str.2 = [29 x i8] c"Couldn't find zeroth section\00"
@.str.3 = [28 x i8] c"Couldn't find first section\00"
@.str.4 = [28 x i8] c"Couldn't find third section\00"
define void @test_section_jumping() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = load i32, i32* @O_RDONLY
%5 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %1
%6 = load i32, i32* %1
%7 = icmp sgt i32 %6, 1
br i1 %7, label %8, label %9
8: ; preds = %0
br label %9
9: ; preds = %8, %0
%10 = phi i1 [ false, %0 ], [ true, %8 ]
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i32, i32* %1
%14 = call i8* @readfile(i32 %13)
store i8* %14, i8** %2
%15 = load i8*, i8** %2
%16 = call i8* @find_section_start(i8* %15, i32 0)
store i8* %16, i8** %3
%17 = load i8*, i8** %2
%18 = load i8*, i8** %3
%19 = icmp eq i8* %17, %18
br i1 %19, label %20, label %21
20: ; preds = %9
br label %21
21: ; preds = %20, %9
%22 = phi i1 [ false, %9 ], [ true, %20 ]
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = load i8*, i8** %2
%26 = call i8* @find_section_start(i8* %25, i32 1)
store i8* %26, i8** %3
%27 = load i8*, i8** %2
%28 = getelementptr inbounds i8, i8* %27, i64 3
%29 = load i8*, i8** %3
%30 = icmp eq i8* %28, %29
br i1 %30, label %31, label %32
31: ; preds = %21
br label %32
32: ; preds = %31, %21
%33 = phi i1 [ false, %21 ], [ true, %31 ]
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = load i8*, i8** %2
%37 = call i8* @find_section_start(i8* %36, i32 2)
store i8* %37, i8** %3
%38 = load i8*, i8** %2
%39 = getelementptr inbounds i8, i8* %38, i64 3
%40 = getelementptr inbounds i8, i8* %39, i64 5
%41 = load i8*, i8** %3
%42 = icmp eq i8* %40, %41
br i1 %42, label %43, label %44
43: ; preds = %32
br label %44
44: ; preds = %43, %32
%45 = phi i1 [ false, %32 ], [ true, %43 ]
%46 = zext i1 %45 to i32
%47 = call i32 @assert(i32 %46)
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"input_sections\00"
@O_RDONLY = global i32 0
define void @test_section_jumping() {
%1 = load i32, i32* @O_RDONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp sgt i32 %2, 1
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = tail call i8* @readfile(i32 %2)
%7 = tail call i8* @find_section_start(i8* %6, i32 0)
%8 = icmp eq i8* %6, %7
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = tail call i8* @find_section_start(i8* %6, i32 1)
%12 = getelementptr inbounds i8, i8* %6, i64 3
%13 = icmp eq i8* %12, %11
%14 = zext i1 %13 to i32
%15 = tail call i32 @assert(i32 %14)
%16 = tail call i8* @find_section_start(i8* %6, i32 2)
%17 = getelementptr inbounds i8, i8* %6, i64 8
%18 = icmp eq i8* %17, %16
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
ret void
}