#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 wirth(unsigned int n) {
  unsigned int y, z, iy, iz, i, m[n], min;
  m[0] = 1;
  printf("  1:   1\n");
  iy = iz = 0;
  for (i = 1; i < 100; ++i) {
    y = 2 * m[iy] + 1;
    z = 3 * m[iz] + 1;
    min = z < y ? z : y;
    m[i] = min;
    printf("%3d: %3d\n", i + 1, min);
    if (y <= m[i])
      ++iy;
    if (z <= m[i])
      ++iz;
  }
  return;
}


x86 assembly (clang, -O0):
<wirth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,%ecx
mov    %rsp,%rax
mov    %rax,-0x20(%rbp)
lea    0xf(,%rcx,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rax
sub    %rdx,%rax
mov    %rax,-0x38(%rbp)
mov    %rax,%rsp
mov    %rcx,-0x28(%rbp)
movl   $0x1,(%rax)
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x1,-0x18(%rbp)
cmpl   $0x64,-0x18(%rbp)
jae    1229 <wirth+0x119>
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    (%rax,%rcx,4),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
mov    %ecx,-0x8(%rbp)
mov    -0x14(%rbp),%ecx
imul   $0x3,(%rax,%rcx,4),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    11ae <wirth+0x9e>
mov    -0xc(%rbp),%eax
mov    %eax,-0x3c(%rbp)
jmp    11b4 <wirth+0xa4>
mov    -0x8(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x3c(%rbp),%ecx
mov    %ecx,-0x2c(%rbp)
mov    -0x2c(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%esi
add    $0x1,%esi
mov    -0x2c(%rbp),%edx
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rcx
mov    -0x8(%rbp),%eax
mov    -0x18(%rbp),%edx
cmp    (%rcx,%rdx,4),%eax
ja     11fa <wirth+0xea>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x38(%rbp),%rcx
mov    -0xc(%rbp),%eax
mov    -0x18(%rbp),%edx
cmp    (%rcx,%rdx,4),%eax
ja     1216 <wirth+0x106>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    121b <wirth+0x10b>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    116d <wirth+0x5d>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wirth>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%eax
mov    %rsp,%rcx
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
mov    %rcx,%r15
sub    %rax,%r15
mov    %r15,%rsp
neg    %rax
movl   $0x1,(%rcx,%rax,1)
lea    0xeb1(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%r12d
mov    $0x1,%eax
mov    $0x1,%ecx
xor    %ebx,%ebx
movl   $0x0,-0x2c(%rbp)
nopw   0x0(%rax,%rax,1)
lea    (%rcx,%rcx,1),%edx
add    $0x1,%edx
lea    (%rax,%rax,2),%eax
add    $0x1,%eax
cmp    %edx,%eax
sbb    $0xffffffff,%ebx
xor    %r14d,%r14d
cmp    %edx,%eax
cmovb  %eax,%edx
mov    %r15,%r13
mov    %edx,(%r15,%r12,4)
setbe  %r15b
lea    0x1(%r12),%esi
lea    0xe50(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x63,%r12
je     11e0 <wirth+0xc0>
mov    %r15b,%r14b
mov    -0x2c(%rbp),%edx
add    %r14d,%edx
mov    %ebx,%eax
mov    %r13,%r15
mov    0x0(%r13,%rax,4),%ecx
mov    %edx,-0x2c(%rbp)
mov    %edx,%eax
mov    0x0(%r13,%rax,4),%eax
add    $0x1,%r12
jmp    1180 <wirth+0x60>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c" 1: 1\0A\00"
@.str.1 = [10 x i8] c"%3d: %3d\0A\00"
define void @wirth(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
store i32 %0, i32* %2
%11 = load i32, i32* %2
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %8
%14 = alloca i32, i64 %12
store i64 %12, i64* %9
%15 = getelementptr inbounds i32, i32* %14, i64 0
store i32 1, i32* %15
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %6
store i32 0, i32* %5
store i32 1, i32* %7
br label %17
17: ; preds = %70, %1
%18 = load i32, i32* %7
%19 = icmp ult i32 %18, 100
br i1 %19, label %20, label %73
20: ; preds = %17
%21 = load i32, i32* %5
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %14, i64 %22
%24 = load i32, i32* %23
%25 = mul i32 2, %24
%26 = add i32 %25, 1
store i32 %26, i32* %3
%27 = load i32, i32* %6
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %14, i64 %28
%30 = load i32, i32* %29
%31 = mul i32 3, %30
%32 = add i32 %31, 1
store i32 %32, i32* %4
%33 = load i32, i32* %4
%34 = load i32, i32* %3
%35 = icmp ult i32 %33, %34
br i1 %35, label %36, label %38
36: ; preds = %20
%37 = load i32, i32* %4
br label %40
38: ; preds = %20
%39 = load i32, i32* %3
br label %40
40: ; preds = %38, %36
%41 = phi i32 [ %37, %36 ], [ %39, %38 ]
store i32 %41, i32* %10
%42 = load i32, i32* %10
%43 = load i32, i32* %7
%44 = zext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %14, i64 %44
store i32 %42, i32* %45
%46 = load i32, i32* %7
%47 = add i32 %46, 1
%48 = load i32, i32* %10
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %47, i32 %48)
%50 = load i32, i32* %3
%51 = load i32, i32* %7
%52 = zext i32 %51 to i64
%53 = getelementptr inbounds i32, i32* %14, i64 %52
%54 = load i32, i32* %53
%55 = icmp ule i32 %50, %54
br i1 %55, label %56, label %59
56: ; preds = %40
%57 = load i32, i32* %5
%58 = add i32 %57, 1
store i32 %58, i32* %5
br label %59
59: ; preds = %56, %40
%60 = load i32, i32* %4
%61 = load i32, i32* %7
%62 = zext i32 %61 to i64
%63 = getelementptr inbounds i32, i32* %14, i64 %62
%64 = load i32, i32* %63
%65 = icmp ule i32 %60, %64
br i1 %65, label %66, label %69
66: ; preds = %59
%67 = load i32, i32* %6
%68 = add i32 %67, 1
store i32 %68, i32* %6
br label %69
69: ; preds = %66, %59
br label %70
70: ; preds = %69
%71 = load i32, i32* %7
%72 = add i32 %71, 1
store i32 %72, i32* %7
br label %17
73: ; preds = %17
%74 = load i8*, i8** %8
ret void
}

LLVM IR (-O2):
@.str.1 = [10 x i8] c"%3d: %3d\0A\00"
@str = [9 x i8] c" 1: 1\00"
define void @wirth(i32 %0) {
%2 = zext i32 %0 to i64
%3 = alloca i32, i64 %2
store i32 1, i32* %3
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %5
5: ; preds = %28, %1
%6 = phi i32 [ 1, %1 ], [ %34, %28 ]
%7 = phi i32 [ 1, %1 ], [ %31, %28 ]
%8 = phi i64 [ 1, %1 ], [ %18, %28 ]
%9 = phi i32 [ 0, %1 ], [ %23, %28 ]
%10 = phi i32 [ 0, %1 ], [ %26, %28 ]
%11 = shl i32 %7, 1
%12 = or i32 %11, 1
%13 = mul i32 %6, 3
%14 = add i32 %13, 1
%15 = icmp ult i32 %14, %12
%16 = select i1 %15, i32 %14, i32 %12
%17 = getelementptr inbounds i32, i32* %3, i64 %8
store i32 %16, i32* %17
%18 = add nuw nsw i64 %8, 1
%19 = trunc i64 %18 to i32
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 %16)
%21 = xor i1 %15, true
%22 = zext i1 %21 to i32
%23 = add i32 %9, %22
%24 = icmp ule i32 %14, %12
%25 = zext i1 %24 to i32
%26 = add i32 %10, %25
%27 = icmp eq i64 %18, 100
br i1 %27, label %35, label %28
28: ; preds = %5
%29 = zext i32 %23 to i64
%30 = getelementptr inbounds i32, i32* %3, i64 %29
%31 = load i32, i32* %30
%32 = zext i32 %26 to i64
%33 = getelementptr inbounds i32, i32* %3, i64 %32
%34 = load i32, i32* %33
br label %5
35: ; preds = %5
ret void
}