#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 *, 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 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("%s", note_buffer);
  return 1;
}


x86 assembly (clang, -O0):
<print_notes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <find_user_note@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1179 <print_notes+0x39>
movl   $0x0,-0x4(%rbp)
jmp    11bf <print_notes+0x7f>
mov    -0x8(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1060 <read@plt>
movslq -0x1c(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
lea    -0x80(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <search_note@plt>
cmp    $0x0,%rax
je     11b8 <print_notes+0x78>
lea    -0x80(%rbp),%rsi
lea    0xe4d(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%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     1197 <print_notes+0x57>
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     1199 <print_notes+0x59>
lea    0xe73(%rip),%rdi
mov    %rsp,%rsi
call   1040 <printf@plt>
jmp    1199 <print_notes+0x59>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%s\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 %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* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %16
16: ; preds = %8, %14, %3
%17 = phi i32 [ 0, %3 ], [ 1, %14 ], [ 1, %8 ]
ret i32 %17
}