#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 */
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ addMov(int *, int *);
int /*<<< orphan*/ divide(int *, int *, int *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ mul(int *, int *, int *);
int /*<<< orphan*/ nullCell(int *);
int /*<<< orphan*/ stderr;
void calcPi(uint16_t *mem) {
  uint16_t num = 355;
  uint16_t denum = 113;
  uint16_t result = 0;
  uint16_t digit = 8;
  uint16_t pos = 0;
  uint16_t tmp[10] = {0x00};
  divide(&result, &num, &denum);
  fprintf(stderr, "Pi=%d.", result);
  addMov(&tmp[pos], &num);
  while (digit) {
    uint16_t i = 10;
    uint16_t den = 113;
    nullCell(&tmp[pos + 1]);
    mul(&tmp[pos + 1], &tmp[pos], &i);
    uint16_t num = tmp[pos + 1];
    divide(&tmp[pos + 2], &tmp[pos + 1], &den);
    fprintf(stderr, "%d", tmp[pos + 2]);
    pos++;
    digit--;
  }
  fprintf(stderr, "\n");
}


x86 assembly (clang, -O0):
<calcPi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x163,-0xc(%rbp)
movl   $0x71,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x8,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
lea    -0x14(%rbp),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1030 <divide@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe3d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movslq -0x1c(%rbp),%rax
lea    -0x50(%rbp),%rdi
shl    $0x2,%rax
add    %rax,%rdi
lea    -0xc(%rbp),%rsi
call   1050 <addMov@plt>
cmpl   $0x0,-0x18(%rbp)
je     12b5 <calcPi+0x155>
movl   $0xa,-0x54(%rbp)
movl   $0x71,-0x58(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
lea    -0x50(%rbp),%rdi
shl    $0x2,%rax
add    %rax,%rdi
call   1070 <nullCell@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
lea    -0x50(%rbp),%rdi
shl    $0x2,%rax
add    %rax,%rdi
movslq -0x1c(%rbp),%rax
lea    -0x50(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    -0x54(%rbp),%rdx
call   1080 <mul@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
mov    -0x50(%rbp,%rax,4),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
cltq
lea    -0x50(%rbp),%rdi
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
lea    -0x50(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    -0x58(%rbp),%rdx
call   1030 <divide@plt>
mov    0x2d5e(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
cltq
mov    -0x50(%rbp,%rax,4),%edx
lea    0xd70(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    11e2 <calcPi+0x82>
mov    0x2d24(%rip),%rax
mov    (%rax),%edi
lea    0xd45(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calcPi>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
movl   $0x163,0x1c(%rsp)
movl   $0x71,0x18(%rsp)
movl   $0x0,0xc(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movq   $0x0,0x40(%rsp)
lea    0xc(%rsp),%rdi
lea    0x1c(%rsp),%rbx
lea    0x18(%rsp),%rdx
mov    %rbx,%rsi
call   1030 <divide@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
mov    0xc(%rsp),%edx
lea    0xe49(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0x20(%rsp),%rdi
mov    %rbx,%rsi
call   1040 <addMov@plt>
lea    0x28(%rsp),%rbx
mov    $0xfffffff8,%ebp
lea    0x14(%rsp),%r14
lea    0x10(%rsp),%r15
lea    0xe21(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
movl   $0xa,0x14(%rsp)
movl   $0x71,0x10(%rsp)
lea    -0x4(%rbx),%r13
mov    %r13,%rdi
call   1060 <nullCell@plt>
lea    -0x8(%rbx),%rsi
mov    %r13,%rdi
mov    %r14,%rdx
call   1070 <mul@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
call   1030 <divide@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%edx
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x4,%rbx
inc    %ebp
jne    11f0 <calcPi+0xa0>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
lea    0xdb4(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [7 x i8] c"Pi=%d.\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @calcPi(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [10 x i32]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %2
store i32 355, i32* %3
store i32 113, i32* %4
store i32 0, i32* %5
store i32 8, i32* %6
store i32 0, i32* %7
%12 = bitcast [10 x i32]* %8 to i8*
%13 = call i32 @divide(i32* %5, i32* %3, i32* %4)
%14 = load i32, i32* @stderr
%15 = load i32, i32* %5
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [10 x i32], [10 x i32]* %8, i64 0, i64 %18
%20 = call i32 @addMov(i32* %19, i32* %3)
br label %21
21: ; preds = %24, %1
%22 = load i32, i32* %6
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %63
24: ; preds = %21
store i32 10, i32* %9
store i32 113, i32* %10
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [10 x i32], [10 x i32]* %8, i64 0, i64 %27
%29 = call i32 @nullCell(i32* %28)
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [10 x i32], [10 x i32]* %8, i64 0, i64 %32
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [10 x i32], [10 x i32]* %8, i64 0, i64 %35
%37 = call i32 @mul(i32* %33, i32* %36, i32* %9)
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [10 x i32], [10 x i32]* %8, i64 0, i64 %40
%42 = load i32, i32* %41
store i32 %42, i32* %11
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 2
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [10 x i32], [10 x i32]* %8, i64 0, i64 %45
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [10 x i32], [10 x i32]* %8, i64 0, i64 %49
%51 = call i32 @divide(i32* %46, i32* %50, i32* %10)
%52 = load i32, i32* @stderr
%53 = load i32, i32* %7
%54 = add nsw i32 %53, 2
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [10 x i32], [10 x i32]* %8, i64 0, i64 %55
%57 = load i32, i32* %56
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %57)
%59 = load i32, i32* %7
%60 = add nsw i32 %59, 1
store i32 %60, i32* %7
%61 = load i32, i32* %6
%62 = add nsw i32 %61, -1
store i32 %62, i32* %6
br label %21
63: ; preds = %21
%64 = load i32, i32* @stderr
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [7 x i8] c"Pi=%d.\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @calcPi(i32* nocapture readnone %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [10 x i32]
%6 = alloca i32
%7 = alloca i32
%8 = bitcast i32* %2 to i8*
store i32 355, i32* %2
%9 = bitcast i32* %3 to i8*
store i32 113, i32* %3
%10 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%11 = bitcast [10 x i32]* %5 to i8*
%12 = call i32 @divide(i32* %4, i32* %2, i32* %3)
%13 = load i32, i32* @stderr
%14 = load i32, i32* %4
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = getelementptr inbounds [10 x i32], [10 x i32]* %5, i64 0, i64 0
%17 = call i32 @addMov(i32* %16, i32* %2)
%18 = bitcast i32* %6 to i8*
%19 = bitcast i32* %7 to i8*
br label %20
20: ; preds = %1, %20
%21 = phi i64 [ 0, %1 ], [ %23, %20 ]
%22 = phi i32 [ 8, %1 ], [ %34, %20 ]
store i32 10, i32* %6
store i32 113, i32* %7
%23 = add nuw nsw i64 %21, 1
%24 = getelementptr inbounds [10 x i32], [10 x i32]* %5, i64 0, i64 %23
%25 = call i32 @nullCell(i32* %24)
%26 = getelementptr inbounds [10 x i32], [10 x i32]* %5, i64 0, i64 %21
%27 = call i32 @mul(i32* %24, i32* %26, i32* %6)
%28 = add nuw nsw i64 %21, 2
%29 = getelementptr inbounds [10 x i32], [10 x i32]* %5, i64 0, i64 %28
%30 = call i32 @divide(i32* %29, i32* %24, i32* %7)
%31 = load i32, i32* @stderr
%32 = load i32, i32* %29
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = add nsw i32 %22, -1
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %20
36: ; preds = %20
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}