#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 Categories {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ addCategory(char *, struct Categories **);
int /*<<< orphan*/ addProduct(struct Categories **, int, char *, double, char *,
                              int, char **);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ search(char *, int, struct Categories *);
void test2() {
  printf("\nsearch(\"ABC\",150,NULL):\n");
  search("ABC", 150, NULL);
  struct Categories *head = NULL;
  char *names[] = {"Electronics", "Books", "Computers", "Grocery"};
  addCategory("Electronics", &head);
  addCategory("Books", &head);
  addCategory("Computers", &head);
  printf("\nsearch(\"XYZ\",22,head):\n");
  search("XYZ", 22, head);
  printf("\nsearch(\"Books\", 50, head):\n");
  search("Books", 50, head);
  addProduct(&head, 2, "Programming in C", 60.00, "ABC-Bookstore", 1,
             names + 1);
  addProduct(&head, 3, "IPOD Shuffle", 49.00, "Apple", 1, names);
  addProduct(&head, 4, "Amazon Kindle", 139.00, "Amazon", 2, names);
  printf("\nsearch(\"Books\", 40, head):\n");
  search("Books", 40, head);
  printf("\nsearch(\"Books\", 100, head):\n");
  search("Books", 100, head);
  printf("\nsearch(\"Books\", 200, head):\n");
  search("Books", 200, head);
}


x86 assembly (clang, -O0):
<test2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xec9(%rip),%rdi
call   1030 <printf@plt>
lea    0xed7(%rip),%rdi
mov    $0x96,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <search@plt>
movq   $0x0,-0x8(%rbp)
mov    0x2c88(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c85(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2c82(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2c7f(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe92(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <addCategory@plt>
lea    0xe8e(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <addCategory@plt>
lea    0xe84(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <addCategory@plt>
lea    0xe86(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdx
lea    0xe8f(%rip),%rdi
mov    $0x16,%esi
call   1050 <search@plt>
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdx
lea    0xe3d(%rip),%rdi
mov    $0x32,%esi
call   1050 <search@plt>
lea    -0x30(%rbp),%r9
add    $0x8,%r9
lea    -0x8(%rbp),%rdi
mov    $0x2,%esi
lea    0xe6d(%rip),%rdx
movsd  0xde1(%rip),%xmm0
lea    0xe6f(%rip),%rcx
mov    $0x1,%r8d
call   1040 <addProduct@plt>
lea    -0x30(%rbp),%r9
lea    -0x8(%rbp),%rdi
mov    $0x3,%esi
lea    0xe5e(%rip),%rdx
movsd  0xdab(%rip),%xmm0
lea    0xe5c(%rip),%rcx
mov    $0x1,%r8d
call   1040 <addProduct@plt>
lea    -0x30(%rbp),%r9
lea    -0x8(%rbp),%rdi
mov    $0x4,%esi
lea    0xe43(%rip),%rdx
movsd  0xd75(%rip),%xmm0
lea    0xe42(%rip),%rcx
mov    $0x2,%r8d
call   1040 <addProduct@plt>
lea    0xe37(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdx
lea    0xd8e(%rip),%rdi
mov    $0x28,%esi
call   1050 <search@plt>
lea    0xe33(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdx
lea    0xd6d(%rip),%rdi
mov    $0x64,%esi
call   1050 <search@plt>
lea    0xe30(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdx
lea    0xd4c(%rip),%rdi
mov    $0xc8,%esi
call   1050 <search@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test2>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
lea    0xf3b(%rip),%rdi
call   1030 <puts@plt>
lea    0xebc(%rip),%rdi
mov    $0x96,%esi
xor    %edx,%edx
call   1050 <search@plt>
movq   $0x0,0x8(%rsp)
movaps 0x2c98(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0x2c7c(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xe8c(%rip),%rdi
lea    0x8(%rsp),%rbx
mov    %rbx,%rsi
call   1060 <addCategory@plt>
lea    0xe84(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <addCategory@plt>
lea    0xe78(%rip),%rdi
mov    %rbx,%rsi
call   1060 <addCategory@plt>
lea    0xedf(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%rdx
lea    0xe6a(%rip),%rdi
mov    $0x16,%esi
call   1050 <search@plt>
lea    0xed5(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%rdx
mov    %r14,%rdi
mov    $0x32,%esi
call   1050 <search@plt>
lea    0x18(%rsp),%r9
lea    0xe3a(%rip),%rdx
lea    0xe44(%rip),%rcx
movsd  0xde7(%rip),%xmm0
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0x1,%r8d
call   1040 <addProduct@plt>
lea    0xe30(%rip),%rdx
lea    0xe36(%rip),%rcx
movsd  0xdc6(%rip),%xmm0
lea    0x10(%rsp),%r15
mov    %rbx,%rdi
mov    $0x3,%esi
mov    $0x1,%r8d
mov    %r15,%r9
call   1040 <addProduct@plt>
lea    0xe12(%rip),%rdx
lea    0xe19(%rip),%rcx
movsd  0xd9d(%rip),%xmm0
mov    %rbx,%rdi
mov    $0x4,%esi
mov    $0x2,%r8d
mov    %r15,%r9
call   1040 <addProduct@plt>
lea    0xe48(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%rdx
mov    %r14,%rdi
mov    $0x28,%esi
call   1050 <search@plt>
lea    0xe46(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%rdx
mov    %r14,%rdi
mov    $0x64,%esi
call   1050 <search@plt>
lea    0xe45(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%rdx
mov    %r14,%rdi
mov    $0xc8,%esi
call   1050 <search@plt>
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.Categories = type { i32 }
@.str = [26 x i8] c"\0Asearch(\22ABC\22,150,NULL):\0A\00"
@.str.1 = [4 x i8] c"ABC\00"
@.str.2 = [12 x i8] c"Electronics\00"
@.str.3 = [6 x i8] c"Books\00"
@.str.4 = [10 x i8] c"Computers\00"
@.str.5 = [8 x i8] c"Grocery\00"
@__const.test2.names = [4 x i8*] [i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i32 0, i32 0)]
@.str.6 = [25 x i8] c"\0Asearch(\22XYZ\22,22,head):\0A\00"
@.str.7 = [4 x i8] c"XYZ\00"
@.str.8 = [29 x i8] c"\0Asearch(\22Books\22, 50, head):\0A\00"
@.str.9 = [17 x i8] c"Programming in C\00"
@.str.10 = [14 x i8] c"ABC-Bookstore\00"
@.str.11 = [13 x i8] c"IPOD Shuffle\00"
@.str.12 = [6 x i8] c"Apple\00"
@.str.13 = [14 x i8] c"Amazon Kindle\00"
@.str.14 = [7 x i8] c"Amazon\00"
@.str.15 = [29 x i8] c"\0Asearch(\22Books\22, 40, head):\0A\00"
@.str.16 = [30 x i8] c"\0Asearch(\22Books\22, 100, head):\0A\00"
@.str.17 = [30 x i8] c"\0Asearch(\22Books\22, 200, head):\0A\00"
define void @test2() {
%1 = alloca %struct.Categories*
%2 = alloca [4 x i8*]
%3 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @search(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 150, %struct.Categories* null)
store %struct.Categories* null, %struct.Categories** %1
%5 = bitcast [4 x i8*]* %2 to i8*
%6 = call i32 @addCategory(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), %struct.Categories** %1)
%7 = call i32 @addCategory(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), %struct.Categories** %1)
%8 = call i32 @addCategory(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), %struct.Categories** %1)
%9 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
%10 = load %struct.Categories*, %struct.Categories** %1
%11 = call i32 @search(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 22, %struct.Categories* %10)
%12 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0))
%13 = load %struct.Categories*, %struct.Categories** %1
%14 = call i32 @search(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 50, %struct.Categories* %13)
%15 = getelementptr inbounds [4 x i8*], [4 x i8*]* %2, i64 0, i64 0
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = call i32 @addProduct(%struct.Categories** %1, i32 2, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0), double 6.000000e+01, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0), i32 1, i8** %16)
%18 = getelementptr inbounds [4 x i8*], [4 x i8*]* %2, i64 0, i64 0
%19 = call i32 @addProduct(%struct.Categories** %1, i32 3, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0), double 4.900000e+01, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0), i32 1, i8** %18)
%20 = getelementptr inbounds [4 x i8*], [4 x i8*]* %2, i64 0, i64 0
%21 = call i32 @addProduct(%struct.Categories** %1, i32 4, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.13, i64 0, i64 0), double 1.390000e+02, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.14, i64 0, i64 0), i32 2, i8** %20)
%22 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.15, i64 0, i64 0))
%23 = load %struct.Categories*, %struct.Categories** %1
%24 = call i32 @search(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 40, %struct.Categories* %23)
%25 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.16, i64 0, i64 0))
%26 = load %struct.Categories*, %struct.Categories** %1
%27 = call i32 @search(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 100, %struct.Categories* %26)
%28 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.17, i64 0, i64 0))
%29 = load %struct.Categories*, %struct.Categories** %1
%30 = call i32 @search(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 200, %struct.Categories* %29)
ret void
}

LLVM IR (-O2):
%struct.Categories = type { i32 }
@.str.1 = [4 x i8] c"ABC\00"
@.str.2 = [12 x i8] c"Electronics\00"
@.str.3 = [6 x i8] c"Books\00"
@.str.4 = [10 x i8] c"Computers\00"
@.str.5 = [8 x i8] c"Grocery\00"
@__const.test2.names = [4 x i8*] [i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i32 0, i32 0)]
@.str.7 = [4 x i8] c"XYZ\00"
@.str.9 = [17 x i8] c"Programming in C\00"
@.str.10 = [14 x i8] c"ABC-Bookstore\00"
@.str.11 = [13 x i8] c"IPOD Shuffle\00"
@.str.12 = [6 x i8] c"Apple\00"
@.str.13 = [14 x i8] c"Amazon Kindle\00"
@.str.14 = [7 x i8] c"Amazon\00"
@str = [25 x i8] c"\0Asearch(\22ABC\22,150,NULL):\00"
@str.18 = [24 x i8] c"\0Asearch(\22XYZ\22,22,head):\00"
@str.19 = [28 x i8] c"\0Asearch(\22Books\22, 50, head):\00"
@str.20 = [28 x i8] c"\0Asearch(\22Books\22, 40, head):\00"
@str.21 = [29 x i8] c"\0Asearch(\22Books\22, 100, head):\00"
@str.22 = [29 x i8] c"\0Asearch(\22Books\22, 200, head):\00"
define void @test2() {
%1 = alloca %struct.Categories*
%2 = alloca [4 x i8*]
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @search(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 150, %struct.Categories* null)
%5 = bitcast %struct.Categories** %1 to i8*
store %struct.Categories* null, %struct.Categories** %1
%6 = bitcast [4 x i8*]* %2 to i8*
%7 = call i32 @addCategory(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), %struct.Categories** %1)
%8 = call i32 @addCategory(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), %struct.Categories** %1)
%9 = call i32 @addCategory(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), %struct.Categories** %1)
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.18, i64 0, i64 0))
%11 = load %struct.Categories*, %struct.Categories** %1
%12 = call i32 @search(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 22, %struct.Categories* %11)
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.19, i64 0, i64 0))
%14 = load %struct.Categories*, %struct.Categories** %1
%15 = call i32 @search(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 50, %struct.Categories* %14)
%16 = getelementptr inbounds [4 x i8*], [4 x i8*]* %2, i64 0, i64 0
%17 = getelementptr inbounds [4 x i8*], [4 x i8*]* %2, i64 0, i64 1
%18 = call i32 @addProduct(%struct.Categories** %1, i32 2, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0), double 6.000000e+01, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0), i32 1, i8** %17)
%19 = call i32 @addProduct(%struct.Categories** %1, i32 3, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0), double 4.900000e+01, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0), i32 1, i8** %16)
%20 = call i32 @addProduct(%struct.Categories** %1, i32 4, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.13, i64 0, i64 0), double 1.390000e+02, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.14, i64 0, i64 0), i32 2, i8** %16)
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.20, i64 0, i64 0))
%22 = load %struct.Categories*, %struct.Categories** %1
%23 = call i32 @search(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 40, %struct.Categories* %22)
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.21, i64 0, i64 0))
%25 = load %struct.Categories*, %struct.Categories** %1
%26 = call i32 @search(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 100, %struct.Categories* %25)
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.22, i64 0, i64 0))
%28 = load %struct.Categories*, %struct.Categories** %1
%29 = call i32 @search(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 200, %struct.Categories* %28)
ret void
}