#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 db_lookup(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int db_root_check(char *startingwith, char *lookingfor) {
  int result;
  int n;
  char subject[60];
  char key[60];
  char value[20];
  strcpy(subject, startingwith);
  for (n = 0; n < 5; n++) {
    strcpy(key, subject);
    strcat(key, " > class");
    result = db_lookup(key, value);
    if (result == 0)
      return 0;
    if (strcmp(value, lookingfor) == 0)
      return 1;
    if (strcmp(value, "root") == 0)
      break;
    strcpy(subject, value);
  }
  return 0;
}


x86 assembly (clang, -O0):
<db_root_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x20(%rbp)
cmpl   $0x5,-0x20(%rbp)
jge    1226 <db_root_check+0xe6>
lea    -0xa0(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0xa0(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1060 <strcat@plt>
lea    -0xa0(%rbp),%rdi
lea    -0xc0(%rbp),%rsi
call   1050 <db_lookup@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11c0 <db_root_check+0x80>
movl   $0x0,-0x4(%rbp)
jmp    122d <db_root_check+0xed>
lea    -0xc0(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11e6 <db_root_check+0xa6>
movl   $0x1,-0x4(%rbp)
jmp    122d <db_root_check+0xed>
lea    -0xc0(%rbp),%rdi
lea    0xe15(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1208 <db_root_check+0xc8>
jmp    1226 <db_root_check+0xe6>
lea    -0x60(%rbp),%rdi
lea    -0xc0(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1167 <db_root_check+0x27>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<db_root_check>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xa0,%rsp
mov    %rsi,%r14
mov    %rdi,%rsi
lea    0x20(%rsp),%r15
mov    %r15,%rdi
call   1030 <strcpy@plt>
lea    0x60(%rsp),%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
lea    0xe87(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1050 <db_lookup@plt>
test   %eax,%eax
je     1387 <db_root_check+0x247>
mov    %rsp,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
mov    $0x1,%r12d
test   %rax,%rax
je     138a <db_root_check+0x24a>
lea    0xe54(%rip),%rsi
mov    %rsp,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1387 <db_root_check+0x247>
lea    0x20(%rsp),%rbx
mov    %rsp,%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
lea    0x60(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0xe10(%rip),%rsi
mov    %rbp,%rdi
call   1060 <strcat@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1050 <db_lookup@plt>
test   %eax,%eax
je     1387 <db_root_check+0x247>
mov    %rsp,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     138a <db_root_check+0x24a>
lea    0xde3(%rip),%rsi
mov    %rsp,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1387 <db_root_check+0x247>
lea    0x20(%rsp),%rbx
mov    %rsp,%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
lea    0x60(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0xd9f(%rip),%rsi
mov    %rbp,%rdi
call   1060 <strcat@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1050 <db_lookup@plt>
test   %eax,%eax
je     1387 <db_root_check+0x247>
mov    %rsp,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     138a <db_root_check+0x24a>
lea    0xd72(%rip),%rsi
mov    %rsp,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1387 <db_root_check+0x247>
lea    0x20(%rsp),%rbx
mov    %rsp,%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
lea    0x60(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0xd2e(%rip),%rsi
mov    %rbp,%rdi
call   1060 <strcat@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1050 <db_lookup@plt>
test   %eax,%eax
je     1387 <db_root_check+0x247>
mov    %rsp,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     138a <db_root_check+0x24a>
lea    0xd01(%rip),%rsi
mov    %rsp,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1387 <db_root_check+0x247>
lea    0x20(%rsp),%rbx
mov    %rsp,%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
lea    0x60(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0xcc1(%rip),%rsi
mov    %rbp,%rdi
call   1060 <strcat@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1050 <db_lookup@plt>
test   %eax,%eax
je     1387 <db_root_check+0x247>
mov    %rsp,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     138a <db_root_check+0x24a>
lea    0xc9c(%rip),%rsi
mov    %rsp,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1387 <db_root_check+0x247>
lea    0x20(%rsp),%rdi
mov    %rsp,%rsi
call   1030 <strcpy@plt>
xor    %r12d,%r12d
mov    %r12d,%eax
add    $0xa0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c" > class\00"
@.str.1 = [5 x i8] c"root\00"
define i32 @db_root_check(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [60 x i8]
%9 = alloca [60 x i8]
%10 = alloca [20 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
%11 = getelementptr inbounds [60 x i8], [60 x i8]* %8, i64 0, i64 0
%12 = load i8*, i8** %4
%13 = call i32 @strcpy(i8* %11, i8* %12)
store i32 0, i32* %7
br label %14
14: ; preds = %44, %2
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 5
br i1 %16, label %17, label %47
17: ; preds = %14
%18 = getelementptr inbounds [60 x i8], [60 x i8]* %9, i64 0, i64 0
%19 = getelementptr inbounds [60 x i8], [60 x i8]* %8, i64 0, i64 0
%20 = call i32 @strcpy(i8* %18, i8* %19)
%21 = getelementptr inbounds [60 x i8], [60 x i8]* %9, i64 0, i64 0
%22 = call i32 @strcat(i8* %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%23 = getelementptr inbounds [60 x i8], [60 x i8]* %9, i64 0, i64 0
%24 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%25 = call i32 @db_lookup(i8* %23, i8* %24)
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %17
store i32 0, i32* %3
br label %48
29: ; preds = %17
%30 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%31 = load i8*, i8** %5
%32 = call i64 @strcmp(i8* %30, i8* %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %29
store i32 1, i32* %3
br label %48
35: ; preds = %29
%36 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %35
br label %47
40: ; preds = %35
%41 = getelementptr inbounds [60 x i8], [60 x i8]* %8, i64 0, i64 0
%42 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%43 = call i32 @strcpy(i8* %41, i8* %42)
br label %44
44: ; preds = %40
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 1
store i32 %46, i32* %7
br label %14
47: ; preds = %39, %14
store i32 0, i32* %3
br label %48
48: ; preds = %47, %34, %28
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@.str = [9 x i8] c" > class\00"
@.str.1 = [5 x i8] c"root\00"
define i32 @db_root_check(i8* %0, i8* %1) {
%3 = alloca [60 x i8]
%4 = alloca [60 x i8]
%5 = alloca [20 x i8]
%6 = getelementptr inbounds [60 x i8], [60 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [60 x i8], [60 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%9 = call i32 @strcpy(i8* %6, i8* %0)
%10 = call i32 @strcpy(i8* %7, i8* %6)
%11 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @db_lookup(i8* %7, i8* %8)
%13 = icmp eq i32 %12, 0
br i1 %13, label %70, label %14
14: ; preds = %2
%15 = call i64 @strcmp(i8* %8, i8* %1)
%16 = icmp eq i64 %15, 0
br i1 %16, label %70, label %17
17: ; preds = %14
%18 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %70, label %20
20: ; preds = %17
%21 = call i32 @strcpy(i8* %6, i8* %8)
%22 = call i32 @strcpy(i8* %7, i8* %6)
%23 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @db_lookup(i8* %7, i8* %8)
%25 = icmp eq i32 %24, 0
br i1 %25, label %70, label %26
26: ; preds = %20
%27 = call i64 @strcmp(i8* %8, i8* %1)
%28 = icmp eq i64 %27, 0
br i1 %28, label %70, label %29
29: ; preds = %26
%30 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %70, label %32
32: ; preds = %29
%33 = call i32 @strcpy(i8* %6, i8* %8)
%34 = call i32 @strcpy(i8* %7, i8* %6)
%35 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%36 = call i32 @db_lookup(i8* %7, i8* %8)
%37 = icmp eq i32 %36, 0
br i1 %37, label %70, label %38
38: ; preds = %32
%39 = call i64 @strcmp(i8* %8, i8* %1)
%40 = icmp eq i64 %39, 0
br i1 %40, label %70, label %41
41: ; preds = %38
%42 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%43 = icmp eq i64 %42, 0
br i1 %43, label %70, label %44
44: ; preds = %41
%45 = call i32 @strcpy(i8* %6, i8* %8)
%46 = call i32 @strcpy(i8* %7, i8* %6)
%47 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%48 = call i32 @db_lookup(i8* %7, i8* %8)
%49 = icmp eq i32 %48, 0
br i1 %49, label %70, label %50
50: ; preds = %44
%51 = call i64 @strcmp(i8* %8, i8* %1)
%52 = icmp eq i64 %51, 0
br i1 %52, label %70, label %53
53: ; preds = %50
%54 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%55 = icmp eq i64 %54, 0
br i1 %55, label %70, label %56
56: ; preds = %53
%57 = call i32 @strcpy(i8* %6, i8* %8)
%58 = call i32 @strcpy(i8* %7, i8* %6)
%59 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%60 = call i32 @db_lookup(i8* %7, i8* %8)
%61 = icmp eq i32 %60, 0
br i1 %61, label %70, label %62
62: ; preds = %56
%63 = call i64 @strcmp(i8* %8, i8* %1)
%64 = icmp eq i64 %63, 0
br i1 %64, label %70, label %65
65: ; preds = %62
%66 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%67 = icmp eq i64 %66, 0
br i1 %67, label %70, label %68
68: ; preds = %65
%69 = call i32 @strcpy(i8* %6, i8* %8)
br label %70
70: ; preds = %68, %65, %62, %56, %53, %50, %44, %41, %38, %32, %29, %26, %20, %17, %14, %2
%71 = phi i32 [ 0, %2 ], [ 1, %14 ], [ 0, %17 ], [ 0, %20 ], [ 1, %26 ], [ 0, %29 ], [ 0, %32 ], [ 1, %38 ], [ 0, %41 ], [ 0, %44 ], [ 1, %50 ], [ 0, %53 ], [ 0, %56 ], [ 1, %62 ], [ 0, %65 ], [ 0, %68 ]
ret i32 %71
}