#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 */
struct book_node {
  int dummy;
};
struct book {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ change(struct book *, struct book_node *);
struct book *find_by_id(struct book_node *, long);
int get_long(long *);
int /*<<< orphan*/ printf(char *, ...);
void search_and_update(struct book_node *head) {
  printf("\nPlease introduce the ID of the book you wish to modify: ");
  long id;
  int status = get_long(&id);
  if (status == 1) {
    return;
  }
  struct book *ptr = find_by_id(head, id);
  if (ptr == NULL) {
    printf("There is no book with id: %ld", id);
    search_and_update(head);
  } else {
    change(ptr, head);
  }
}


x86 assembly (clang, -O0):
<search_and_update>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x10(%rbp),%rdi
call   1050 <get_long@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    1185 <search_and_update+0x35>
jmp    11ce <search_and_update+0x7e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <find_by_id@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c1 <search_and_update+0x71>
mov    -0x10(%rbp),%rsi
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1070 <search_and_update@plt>
jmp    11ce <search_and_update+0x7e>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <change@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<search_and_update>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xea1(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x8(%rsp),%rdi
call   1050 <get_long@plt>
cmp    $0x1,%eax
je     11af <search_and_update+0x5f>
mov    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <find_by_id@plt>
test   %rax,%rax
je     1194 <search_and_update+0x44>
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <change@plt>
jmp    11af <search_and_update+0x5f>
mov    0x8(%rsp),%rsi
lea    0xe9a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1070 <search_and_update@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.book_node = type { i32 }
%struct.book = type { i32 }
@.str = [58 x i8] c"\0APlease introduce the ID of the book you wish to modify: \00"
@.str.1 = [30 x i8] c"There is no book with id: %ld\00"
define void @search_and_update(%struct.book_node* %0) {
%2 = alloca %struct.book_node*
%3 = alloca i64
%4 = alloca i32
%5 = alloca %struct.book*
store %struct.book_node* %0, %struct.book_node** %2
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @get_long(i64* %3)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %11
10: ; preds = %1
br label %25
11: ; preds = %1
%12 = load %struct.book_node*, %struct.book_node** %2
%13 = load i64, i64* %3
%14 = call %struct.book* @find_by_id(%struct.book_node* %12, i64 %13)
store %struct.book* %14, %struct.book** %5
%15 = load %struct.book*, %struct.book** %5
%16 = icmp eq %struct.book* %15, null
br i1 %16, label %17, label %21
17: ; preds = %11
%18 = load i64, i64* %3
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i64 %18)
%20 = load %struct.book_node*, %struct.book_node** %2
br label %25
21: ; preds = %11
%22 = load %struct.book*, %struct.book** %5
%23 = load %struct.book_node*, %struct.book_node** %2
%24 = call i32 @change(%struct.book* %22, %struct.book_node* %23)
br label %25
25: ; preds = %10, %21, %17
ret void
}

LLVM IR (-O2):
%struct.book_node = type { i32 }
%struct.book = type { i32 }
@.str = [58 x i8] c"\0APlease introduce the ID of the book you wish to modify: \00"
@.str.1 = [30 x i8] c"There is no book with id: %ld\00"
define void @search_and_update(%struct.book_node* %0) {
%2 = alloca i64
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
%4 = bitcast i64* %2 to i8*
%5 = call i32 @get_long(i64* %2)
%6 = icmp eq i32 %5, 1
br i1 %6, label %16, label %7
7: ; preds = %1
%8 = load i64, i64* %2
%9 = call %struct.book* @find_by_id(%struct.book_node* %0, i64 %8)
%10 = icmp eq %struct.book* %9, null
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = load i64, i64* %2
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i64 %12)
br label %16
14: ; preds = %7
%15 = call i32 @change(%struct.book* %9, %struct.book_node* %0)
br label %16
16: ; preds = %11, %14, %1
ret void
}