#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*/ clear_s();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(char);
int scanf(char *, ...);
int f_calculate(int i) {
  int r = 0;
  int ix = 0;
  char chr;
  int a_num = 0;
  int x;
  printf("\n");
  printf("Enter a positive integer (> 0): ");
  scanf("%d", &a_num);
  if (a_num >= 1) {
    printf("Result : ");
    while (a_num >= 1) {
      x = a_num % 2;
      putchar(x == 0 ? '0' : '1');
      a_num = a_num / 2;
    }
    printf("\n");
  } else {
    printf("Enter a positive integer!\n");
  }
  while (ix == 0) {
    clear_s();
    printf("\nDo you want to continue the program (y/n) ? ");
    if (scanf("%c", &chr) == 1) {
      if (chr == 'y') {
        ix = 1;
        printf("OK\n");
      } else if (chr == 'n') {
        r = 1;
        ix = 1;
      }
    }
  }
  return r;
}


x86 assembly (clang, -O0):
<f_calculate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xee0(%rip),%rdi
call   1050 <printf@plt>
lea    0xe8d(%rip),%rdi
call   1050 <printf@plt>
lea    0xea2(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
cmpl   $0x1,-0x14(%rbp)
jl     11f7 <f_calculate+0xb7>
lea    0xe89(%rip),%rdi
call   1050 <printf@plt>
cmpl   $0x1,-0x14(%rbp)
jl     11e6 <f_calculate+0xa6>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0x18(%rbp),%edx
mov    $0x31,%eax
mov    $0x30,%ecx
cmp    $0x0,%edx
cmove  %ecx,%eax
movsbl %al,%edi
call   1040 <putchar@plt>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
jmp    11a0 <f_calculate+0x60>
lea    0xe5a(%rip),%rdi
call   1050 <printf@plt>
jmp    1203 <f_calculate+0xc3>
lea    0xe30(%rip),%rdi
call   1050 <printf@plt>
jmp    1208 <f_calculate+0xc8>
cmpl   $0x0,-0xc(%rbp)
jne    128f <f_calculate+0x14f>
mov    $0x0,%al
call   1030 <clear_s@plt>
lea    0xe29(%rip),%rdi
call   1050 <printf@plt>
lea    0xe4b(%rip),%rdi
lea    -0xd(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    128a <f_calculate+0x14a>
movsbl -0xd(%rbp),%eax
cmp    $0x79,%eax
jne    1265 <f_calculate+0x125>
movl   $0x1,-0xc(%rbp)
lea    0xe1f(%rip),%rdi
call   1050 <printf@plt>
jmp    1285 <f_calculate+0x145>
movsbl -0xd(%rbp),%eax
cmp    $0x6e,%eax
jne    1280 <f_calculate+0x140>
movl   $0x1,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
jmp    1285 <f_calculate+0x145>
jmp    128a <f_calculate+0x14a>
jmp    1208 <f_calculate+0xc8>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f_calculate>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xe8e(%rip),%rdi
call   1060 <printf@plt>
lea    0xea3(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11de <f_calculate+0x8e>
lea    0xe8c(%rip),%rdi
call   1060 <printf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    11d2 <f_calculate+0x82>
cs nopw 0x0(%rax,%rax,1)
nop
and    $0x1,%al
or     $0x30,%al
movzbl %al,%edi
call   1040 <putchar@plt>
mov    0xc(%rsp),%ecx
mov    %ecx,%eax
shr    $0x1f,%eax
add    %ecx,%eax
sar    %eax
mov    %eax,0xc(%rsp)
cmp    $0x1,%ecx
jg     11b0 <f_calculate+0x60>
mov    $0xa,%edi
call   1040 <putchar@plt>
jmp    11ea <f_calculate+0x9a>
lea    0xe7a(%rip),%rdi
call   1050 <puts@plt>
lea    0xe3d(%rip),%r14
lea    0xe64(%rip),%r15
lea    0xb(%rsp),%rbx
nopl   (%rax)
xor    %eax,%eax
call   1030 <clear_s@plt>
mov    %r14,%rdi
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
cmp    $0x1,%eax
jne    1200 <f_calculate+0xb0>
movzbl 0xb(%rsp),%eax
cmp    $0x6e,%al
je     123e <f_calculate+0xee>
cmp    $0x79,%al
jne    1200 <f_calculate+0xb0>
lea    0xe44(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
jmp    1243 <f_calculate+0xf3>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [33 x i8] c"Enter a positive integer (> 0): \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [10 x i8] c"Result : \00"
@.str.4 = [27 x i8] c"Enter a positive integer!\0A\00"
@.str.5 = [46 x i8] c"\0ADo you want to continue the program (y/n) ? \00"
@.str.6 = [3 x i8] c"%c\00"
@.str.7 = [4 x i8] c"OK\0A\00"
define i32 @f_calculate(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %6
%8 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%11 = load i32, i32* %6
%12 = icmp sge i32 %11, 1
br i1 %12, label %13, label %31
13: ; preds = %1
%14 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %15
15: ; preds = %18, %13
%16 = load i32, i32* %6
%17 = icmp sge i32 %16, 1
br i1 %17, label %18, label %29
18: ; preds = %15
%19 = load i32, i32* %6
%20 = srem i32 %19, 2
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = icmp eq i32 %21, 0
%23 = zext i1 %22 to i64
%24 = select i1 %22, i32 48, i32 49
%25 = trunc i32 %24 to i8
%26 = call i32 @putchar(i8 signext %25)
%27 = load i32, i32* %6
%28 = sdiv i32 %27, 2
store i32 %28, i32* %6
br label %15
29: ; preds = %15
%30 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %33
31: ; preds = %1
%32 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
br label %33
33: ; preds = %31, %29
br label %34
34: ; preds = %55, %33
%35 = load i32, i32* %4
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %56
37: ; preds = %34
%38 = call i32 (...) @clear_s()
%39 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0))
%40 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %5)
%41 = icmp eq i32 %40, 1
br i1 %41, label %42, label %55
42: ; preds = %37
%43 = load i8, i8* %5
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 121
br i1 %45, label %46, label %48
46: ; preds = %42
store i32 1, i32* %4
%47 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
br label %54
48: ; preds = %42
%49 = load i8, i8* %5
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 110
br i1 %51, label %52, label %53
52: ; preds = %48
store i32 1, i32* %3
store i32 1, i32* %4
br label %53
53: ; preds = %52, %48
br label %54
54: ; preds = %53, %46
br label %55
55: ; preds = %54, %37
br label %34
56: ; preds = %34
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str.1 = [33 x i8] c"Enter a positive integer (> 0): \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [10 x i8] c"Result : \00"
@.str.5 = [46 x i8] c"\0ADo you want to continue the program (y/n) ? \00"
@.str.6 = [3 x i8] c"%c\00"
@str = [26 x i8] c"Enter a positive integer!\00"
@str.8 = [3 x i8] c"OK\00"
define i32 @f_calculate(i32 %0) {
%2 = alloca i8
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = tail call i32 bitcast (i32 (i8)* @putchar to i32 (i32)*)(i32 10)
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%8 = load i32, i32* %3
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %25
10: ; preds = %1
%11 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%12 = load i32, i32* %3
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %23
14: ; preds = %10, %14
%15 = phi i32 [ %21, %14 ], [ %12, %10 ]
%16 = trunc i32 %15 to i8
%17 = and i8 %16, 1
%18 = or i8 %17, 48
%19 = call i32 @putchar(i8 signext %18)
%20 = load i32, i32* %3
%21 = sdiv i32 %20, 2
store i32 %21, i32* %3
%22 = icmp sgt i32 %20, 1
br i1 %22, label %14, label %23
23: ; preds = %14, %10
%24 = call i32 bitcast (i32 (i8)* @putchar to i32 (i32)*)(i32 10)
br label %27
25: ; preds = %1
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %27
27: ; preds = %25, %23
br label %28
28: ; preds = %35, %27
%29 = call i32 (...) @clear_s()
%30 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0))
%31 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %2)
%32 = icmp eq i32 %31, 1
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = load i8, i8* %2
switch i8 %34, label %35 [
i8 121, label %36
i8 110, label %38
]
35: ; preds = %33, %28
br label %28
36: ; preds = %33
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.8, i64 0, i64 0))
br label %38
38: ; preds = %33, %36
%39 = phi i32 [ 0, %36 ], [ 1, %33 ]
ret i32 %39
}