#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 /*<<< orphan*/ printf(char *);
void printrelation(int j) {
  int i;
  i = j > 0 ? j : -j;
  while (i-- > 3)
    printf("great-");
  if (i == 2 && j > 0)
    printf("grandchild\n");
  else if (i == 2 && j < 0)
    printf("grandparent\n");
  else if (i == 1 && j > 0)
    printf("child\n");
  else if (i == 1 && j < 0)
    printf("parent\n");
}


x86 assembly (clang, -O0):
<printrelation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    1130 <printrelation+0x20>
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1138 <printrelation+0x28>
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x3,%eax
jle    1163 <printrelation+0x53>
lea    0xea7(%rip),%rdi
call   1030 <printf@plt>
jmp    113e <printrelation+0x2e>
cmpl   $0x2,-0x8(%rbp)
jne    1188 <printrelation+0x78>
cmpl   $0x0,-0x4(%rbp)
jle    1188 <printrelation+0x78>
lea    0xe89(%rip),%rdi
call   1030 <printf@plt>
jmp    1201 <printrelation+0xf1>
cmpl   $0x2,-0x8(%rbp)
jne    11ad <printrelation+0x9d>
cmpl   $0x0,-0x4(%rbp)
jge    11ad <printrelation+0x9d>
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
jmp    11fc <printrelation+0xec>
cmpl   $0x1,-0x8(%rbp)
jne    11d2 <printrelation+0xc2>
cmpl   $0x0,-0x4(%rbp)
jle    11d2 <printrelation+0xc2>
lea    0xe44(%rip),%rdi
call   1030 <printf@plt>
jmp    11f7 <printrelation+0xe7>
cmpl   $0x1,-0x8(%rbp)
jne    11f2 <printrelation+0xe2>
cmpl   $0x0,-0x4(%rbp)
jge    11f2 <printrelation+0xe2>
lea    0xe2b(%rip),%rdi
call   1030 <printf@plt>
jmp    11f7 <printrelation+0xe7>
jmp    11fc <printrelation+0xec>
jmp    1201 <printrelation+0xf1>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printrelation>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
mov    %edi,%ebp
neg    %ebp
cmovs  %edi,%ebp
cmp    $0x4,%ebp
jl     115c <printrelation+0x3c>
lea    0xec6(%rip),%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <printf@plt>
add    $0xffffffff,%ebp
cmp    $0x3,%ebp
ja     1140 <printrelation+0x20>
mov    $0x2,%ebp
test   %r14d,%r14d
jg     1164 <printrelation+0x44>
jmp    1172 <printrelation+0x52>
add    $0xffffffff,%ebp
test   %r14d,%r14d
jle    1172 <printrelation+0x52>
cmp    $0x2,%ebp
jne    1172 <printrelation+0x52>
lea    0xea3(%rip),%rdi
jmp    11a9 <printrelation+0x89>
test   %r14d,%r14d
jns    1185 <printrelation+0x65>
cmp    $0x2,%ebp
jne    1185 <printrelation+0x65>
lea    0xe84(%rip),%rdi
jmp    11a9 <printrelation+0x89>
test   %r14d,%r14d
jle    1198 <printrelation+0x78>
cmp    $0x1,%ebp
jne    1198 <printrelation+0x78>
lea    0xe82(%rip),%rdi
jmp    11a9 <printrelation+0x89>
test   %r14d,%r14d
jns    11b2 <printrelation+0x92>
cmp    $0x1,%ebp
jne    11b2 <printrelation+0x92>
lea    0xe63(%rip),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <puts@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"great-\00"
@.str.1 = [12 x i8] c"grandchild\0A\00"
@.str.2 = [13 x i8] c"grandparent\0A\00"
@.str.3 = [7 x i8] c"child\0A\00"
@.str.4 = [8 x i8] c"parent\0A\00"
define void @printrelation(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = load i32, i32* %2
br label %11
8: ; preds = %1
%9 = load i32, i32* %2
%10 = sub nsw i32 0, %9
br label %11
11: ; preds = %8, %6
%12 = phi i32 [ %7, %6 ], [ %10, %8 ]
store i32 %12, i32* %3
br label %13
13: ; preds = %17, %11
%14 = load i32, i32* %3
%15 = add nsw i32 %14, -1
store i32 %15, i32* %3
%16 = icmp sgt i32 %14, 3
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %13
19: ; preds = %13
%20 = load i32, i32* %3
%21 = icmp eq i32 %20, 2
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = load i32, i32* %2
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %54
27: ; preds = %22, %19
%28 = load i32, i32* %3
%29 = icmp eq i32 %28, 2
br i1 %29, label %30, label %35
30: ; preds = %27
%31 = load i32, i32* %2
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %53
35: ; preds = %30, %27
%36 = load i32, i32* %3
%37 = icmp eq i32 %36, 1
br i1 %37, label %38, label %43
38: ; preds = %35
%39 = load i32, i32* %2
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %52
43: ; preds = %38, %35
%44 = load i32, i32* %3
%45 = icmp eq i32 %44, 1
br i1 %45, label %46, label %51
46: ; preds = %43
%47 = load i32, i32* %2
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %51
51: ; preds = %49, %46, %43
br label %52
52: ; preds = %51, %41
br label %53
53: ; preds = %52, %33
br label %54
54: ; preds = %53, %25
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"great-\00"
@str = [7 x i8] c"parent\00"
@str.5 = [6 x i8] c"child\00"
@str.6 = [12 x i8] c"grandparent\00"
@str.7 = [11 x i8] c"grandchild\00"
define void @printrelation(i32 %0) {
%2 = icmp sgt i32 %0, 0
%3 = sub nsw i32 0, %0
%4 = select i1 %2, i32 %0, i32 %3
%5 = add nsw i32 %4, -1
%6 = icmp sgt i32 %4, 3
br i1 %6, label %7, label %12
7: ; preds = %1, %7
%8 = phi i32 [ %10, %7 ], [ %5, %1 ]
%9 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%10 = add nsw i32 %8, -1
%11 = icmp ugt i32 %8, 3
br i1 %11, label %7, label %12
12: ; preds = %7, %1
%13 = phi i32 [ %5, %1 ], [ 2, %7 ]
%14 = icmp eq i32 %13, 2
%15 = and i1 %2, %14
br i1 %15, label %24, label %16
16: ; preds = %12
%17 = icmp slt i32 %0, 0
%18 = and i1 %17, %14
br i1 %18, label %24, label %19
19: ; preds = %16
%20 = icmp eq i32 %13, 1
%21 = and i1 %2, %20
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = and i1 %17, %20
br i1 %23, label %24, label %27
24: ; preds = %22, %19, %16, %12
%25 = phi i8* [ getelementptr inbounds ([11 x i8], [11 x i8]* @str.7, i64 0, i64 0), %12 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @str.6, i64 0, i64 0), %16 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @str.5, i64 0, i64 0), %19 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0), %22 ]
%26 = tail call i32 @puts(i8* dereferenceable(1) %25)
br label %27
27: ; preds = %24, %22
ret void
}