#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 find_user_note(int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read(int, char *, int);
scalar_t__ search_note(char *, char *);
int print_notes(int fd, int uid, char *searchstring) {
  int note_length;
  char byte = 0, note_buffer[100];
  note_length = find_user_note(fd, uid);
  if (note_length == -1)
    return 0;
  read(fd, note_buffer, note_length);
  note_buffer[note_length] = 0;
  if (search_note(note_buffer, searchstring)) {
    printf("Found: \"");
    printf(searchstring);
    printf("\": ");
    printf(note_buffer);
  }
  return 1;
}


x86 assembly (clang, -O0):
<print_notes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movb   $0x0,-0x1d(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <find_user_note@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    117d <print_notes+0x3d>
movl   $0x0,-0x4(%rbp)
jmp    11e9 <print_notes+0xa9>
mov    -0x8(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1060 <read@plt>
movslq -0x1c(%rbp),%rax
movb   $0x0,-0x90(%rbp,%rax,1)
lea    -0x90(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <search_note@plt>
cmp    $0x0,%rax
je     11e2 <print_notes+0xa2>
lea    0xe44(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <printf@plt>
lea    0xe38(%rip),%rdi
call   1040 <printf@plt>
lea    -0x90(%rbp),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_notes>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %rdx,%r14
mov    %edi,%ebp
call   1030 <find_user_note@plt>
cmp    $0xffffffff,%eax
je     11b0 <print_notes+0x70>
mov    %eax,%ebx
mov    %rsp,%r15
mov    %ebp,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1060 <read@plt>
movslq %ebx,%rax
movb   $0x0,(%rsp,%rax,1)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <search_note@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     11b2 <print_notes+0x72>
lea    0xe73(%rip),%rdi
call   1040 <printf@plt>
mov    %r14,%rdi
call   1040 <printf@plt>
lea    0xe68(%rip),%rdi
call   1040 <printf@plt>
mov    %rsp,%rdi
call   1040 <printf@plt>
jmp    11b2 <print_notes+0x72>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"Found: \22\00"
@.str.1 = [4 x i8] c"\22: \00"
define i32 @print_notes(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8
%10 = alloca [100 x i8]
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8 0, i8* %9
%11 = load i32, i32* %5
%12 = load i32, i32* %6
%13 = call i32 @find_user_note(i32 %11, i32 %12)
store i32 %13, i32* %8
%14 = load i32, i32* %8
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 0, i32* %4
br label %37
17: ; preds = %3
%18 = load i32, i32* %5
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%20 = load i32, i32* %8
%21 = call i32 @read(i32 %18, i8* %19, i32 %20)
%22 = load i32, i32* %8
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 %23
store i8 0, i8* %24
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%26 = load i8*, i8** %7
%27 = call i64 @search_note(i8* %25, i8* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %17
%30 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%31 = load i8*, i8** %7
%32 = call i32 @printf(i8* %31)
%33 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%35 = call i32 @printf(i8* %34)
br label %36
36: ; preds = %29, %17
store i32 1, i32* %4
br label %37
37: ; preds = %36, %16
%38 = load i32, i32* %4
ret i32 %38
}

LLVM IR (-O2):
@.str = [9 x i8] c"Found: \22\00"
@.str.1 = [4 x i8] c"\22: \00"
define i32 @print_notes(i32 %0, i32 %1, i8* %2) {
%4 = alloca [100 x i8]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @find_user_note(i32 %0, i32 %1)
%7 = icmp eq i32 %6, -1
br i1 %7, label %19, label %8
8: ; preds = %3
%9 = call i32 @read(i32 %0, i8* %5, i32 %6)
%10 = sext i32 %6 to i64
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %10
store i8 0, i8* %11
%12 = call i64 @search_note(i8* %5, i8* %2)
%13 = icmp eq i64 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %8
%15 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @printf(i8* dereferenceable(1) %2)
%17 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @printf(i8* %5)
br label %19
19: ; preds = %8, %14, %3
%20 = phi i32 [ 0, %3 ], [ 1, %14 ], [ 1, %8 ]
ret i32 %20
}