#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*/ print_pattern1(int);
int /*<<< orphan*/ print_pattern2(int);
int /*<<< orphan*/ print_pattern3(int);
int /*<<< orphan*/ print_pattern4(int);
int main() {
  int n = 4;
  for (int i = 1; i <= n; i++) {
    print_pattern1(i);
  }
  for (int i = 4; i >= 1; i--) {
    print_pattern2(i);
  }
  for (int i = 4; i >= 1; i--) {
    print_pattern3(i);
  }
  for (int i = 1; i <= n; i++) {
    print_pattern4(i);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x4,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     117f <main+0x3f>
mov    -0xc(%rbp),%edi
call   1050 <print_pattern1@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115d <main+0x1d>
movl   $0x4,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
jl     11a6 <main+0x66>
mov    -0x10(%rbp),%edi
call   1030 <print_pattern2@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1186 <main+0x46>
movl   $0x4,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jl     11cd <main+0x8d>
mov    -0x14(%rbp),%edi
call   1060 <print_pattern3@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11ad <main+0x6d>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11f6 <main+0xb6>
mov    -0x18(%rbp),%edi
call   1040 <print_pattern4@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11d4 <main+0x94>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    $0x1,%edi
call   1050 <print_pattern1@plt>
mov    $0x2,%edi
call   1050 <print_pattern1@plt>
mov    $0x3,%edi
call   1050 <print_pattern1@plt>
mov    $0x4,%edi
call   1050 <print_pattern1@plt>
mov    $0x4,%edi
call   1030 <print_pattern2@plt>
mov    $0x3,%edi
call   1030 <print_pattern2@plt>
mov    $0x2,%edi
call   1030 <print_pattern2@plt>
mov    $0x1,%edi
call   1030 <print_pattern2@plt>
mov    $0x4,%edi
call   1060 <print_pattern3@plt>
mov    $0x3,%edi
call   1060 <print_pattern3@plt>
mov    $0x2,%edi
call   1060 <print_pattern3@plt>
mov    $0x1,%edi
call   1060 <print_pattern3@plt>
mov    $0x1,%edi
call   1040 <print_pattern4@plt>
mov    $0x2,%edi
call   1040 <print_pattern4@plt>
mov    $0x3,%edi
call   1040 <print_pattern4@plt>
mov    $0x4,%edi
call   1040 <print_pattern4@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 4, i32* %2
store i32 1, i32* %3
br label %7
7: ; preds = %14, %0
%8 = load i32, i32* %3
%9 = load i32, i32* %2
%10 = icmp sle i32 %8, %9
br i1 %10, label %11, label %17
11: ; preds = %7
%12 = load i32, i32* %3
%13 = call i32 @print_pattern1(i32 %12)
br label %14
14: ; preds = %11
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
store i32 %16, i32* %3
br label %7
17: ; preds = %7
store i32 4, i32* %4
br label %18
18: ; preds = %24, %17
%19 = load i32, i32* %4
%20 = icmp sge i32 %19, 1
br i1 %20, label %21, label %27
21: ; preds = %18
%22 = load i32, i32* %4
%23 = call i32 @print_pattern2(i32 %22)
br label %24
24: ; preds = %21
%25 = load i32, i32* %4
%26 = add nsw i32 %25, -1
store i32 %26, i32* %4
br label %18
27: ; preds = %18
store i32 4, i32* %5
br label %28
28: ; preds = %34, %27
%29 = load i32, i32* %5
%30 = icmp sge i32 %29, 1
br i1 %30, label %31, label %37
31: ; preds = %28
%32 = load i32, i32* %5
%33 = call i32 @print_pattern3(i32 %32)
br label %34
34: ; preds = %31
%35 = load i32, i32* %5
%36 = add nsw i32 %35, -1
store i32 %36, i32* %5
br label %28
37: ; preds = %28
store i32 1, i32* %6
br label %38
38: ; preds = %45, %37
%39 = load i32, i32* %6
%40 = load i32, i32* %2
%41 = icmp sle i32 %39, %40
br i1 %41, label %42, label %48
42: ; preds = %38
%43 = load i32, i32* %6
%44 = call i32 @print_pattern4(i32 %43)
br label %45
45: ; preds = %42
%46 = load i32, i32* %6
%47 = add nsw i32 %46, 1
store i32 %47, i32* %6
br label %38
48: ; preds = %38
%49 = load i32, i32* %1
ret i32 %49
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call i32 @print_pattern1(i32 1)
%2 = tail call i32 @print_pattern1(i32 2)
%3 = tail call i32 @print_pattern1(i32 3)
%4 = tail call i32 @print_pattern1(i32 4)
%5 = tail call i32 @print_pattern2(i32 4)
%6 = tail call i32 @print_pattern2(i32 3)
%7 = tail call i32 @print_pattern2(i32 2)
%8 = tail call i32 @print_pattern2(i32 1)
%9 = tail call i32 @print_pattern3(i32 4)
%10 = tail call i32 @print_pattern3(i32 3)
%11 = tail call i32 @print_pattern3(i32 2)
%12 = tail call i32 @print_pattern3(i32 1)
%13 = tail call i32 @print_pattern4(i32 1)
%14 = tail call i32 @print_pattern4(i32 2)
%15 = tail call i32 @print_pattern4(i32 3)
%16 = tail call i32 @print_pattern4(i32 4)
ret i32 0
}