#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(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    11c8 <print_notes+0x88>
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     11c1 <print_notes+0x81>
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     1190 <print_notes+0x50>
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,%ebx
test   %rax,%rax
je     1192 <print_notes+0x52>
mov    %rsp,%rdi
call   1040 <printf@plt>
jmp    1192 <print_notes+0x52>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
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 %33
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 %32
29: ; preds = %17
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%31 = call i32 @printf(i8* %30)
br label %32
32: ; preds = %29, %17
store i32 1, i32* %4
br label %33
33: ; preds = %32, %16
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
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 %16, 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 %16, label %14
14: ; preds = %8
%15 = call i32 @printf(i8* %5)
br label %16
16: ; preds = %8, %14, %3
%17 = phi i32 [ 0, %3 ], [ 1, %14 ], [ 1, %8 ]
ret i32 %17
}