#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*/ free(char *);
int /*<<< orphan*/ printf(char *);
char *read_raw(char *);
int /*<<< orphan*/ sanity_check(char *);
unsigned char *section_data(char *, int);
int text_section_header(char *);
char *get_text_data(char *path) {
  char *buf = read_raw(path);
  int text_shd;
  sanity_check(buf);
  if ((text_shd = text_section_header(buf)) < 0)
    printf("text section not found\n");
  unsigned char *text = section_data(buf, text_shd);
  free(buf);
  return text;
}


x86 assembly (clang, -O0):
<get_text_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <read_raw@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <sanity_check@plt>
mov    -0x10(%rbp),%rdi
call   1080 <text_section_header@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11a3 <get_text_data+0x43>
lea    0xe62(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <section_data@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_text_data>:
push   %rbp
push   %rbx
push   %rax
call   1050 <read_raw@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <sanity_check@plt>
mov    %rbx,%rdi
call   1080 <text_section_header@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    118d <get_text_data+0x2d>
lea    0xe78(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <section_data@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"text section not found\0A\00"
define i8* @get_text_data(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i8* @read_raw(i8* %6)
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @sanity_check(i8* %8)
%10 = load i8*, i8** %3
%11 = call i32 @text_section_header(i8* %10)
store i32 %11, i32* %4
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %1
%16 = load i8*, i8** %3
%17 = load i32, i32* %4
%18 = call i8* @section_data(i8* %16, i32 %17)
store i8* %18, i8** %5
%19 = load i8*, i8** %3
%20 = call i32 @free(i8* %19)
%21 = load i8*, i8** %5
ret i8* %21
}

LLVM IR (-O2):
@str = [23 x i8] c"text section not found\00"
define i8* @get_text_data(i8* %0) {
%2 = tail call i8* @read_raw(i8* %0)
%3 = tail call i32 @sanity_check(i8* %2)
%4 = tail call i32 @text_section_header(i8* %2)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
%9 = tail call i8* @section_data(i8* %2, i32 %4)
%10 = tail call i32 @free(i8* %2)
ret i8* %9
}