#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 gcd(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  char d;
  int k = 0;
  while (k == 0) {
    int a = 0;
    int b = 0;
    int c = 0;
    printf("Please enter a positve integer. Enter 0 to quit: ");
    scanf("%d", &a);
    scanf("%c", &d);
    if (a == 0) {
      k = 1;
    } else if (a < 0) {
      printf("Error! This is not a positive integer.\nPlease try again.\n");
    } else if (a > 0) {
      printf("Please enter the second positive integer: ");
      scanf("%d", &b);
      scanf("%c", &d);
      while (b < 1) {
        printf("Error! This is not a positive integer.\n");
        printf("Please enter the second positive integer: ");
        scanf("%d", &b);
        scanf("%c", &d);
      }
      if (b > 0) {
        printf("The gcd of %d and %d is %d.\n", a, b, gcd(a, b));
      }
    } else {
      printf("Error\n");
    }
  }
  printf("Have a nice day.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    12ae <main+0x17e>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb8(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xea9(%rip),%rdi
lea    -0x5(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
cmpl   $0x0,-0x10(%rbp)
jne    11ad <main+0x7d>
movl   $0x1,-0xc(%rbp)
jmp    12a9 <main+0x179>
cmpl   $0x0,-0x10(%rbp)
jge    11ca <main+0x9a>
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12a4 <main+0x174>
cmpl   $0x0,-0x10(%rbp)
jle    1291 <main+0x161>
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe49(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xe3a(%rip),%rdi
lea    -0x5(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
cmpl   $0x1,-0x14(%rbp)
jge    1255 <main+0x125>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdff(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xdf0(%rip),%rdi
lea    -0x5(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
jmp    1206 <main+0xd6>
cmpl   $0x0,-0x14(%rbp)
jle    128c <main+0x15c>
mov    -0x10(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1050 <gcd@plt>
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    %eax,%ecx
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    129f <main+0x16f>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12a4 <main+0x174>
jmp    12a9 <main+0x179>
jmp    1146 <main+0x16>
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0x0,0x10(%rsp)
movl   $0x0,0x14(%rsp)
lea    0xe9b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xebf(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xeaf(%rip),%rdi
lea    0xf(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x10(%rsp),%eax
test   %eax,%eax
je     1291 <main+0x151>
lea    0xe8d(%rip),%rbx
lea    0xe89(%rip),%r15
lea    0xf(%rsp),%r13
lea    0x14(%rsp),%rbp
lea    0xed4(%rip),%r14
jmp    1236 <main+0xf6>
nop
mov    %r15,%r13
mov    %rbx,%r15
mov    0x10(%rsp),%ebx
mov    %ebx,%edi
mov    %r12d,%esi
call   1060 <gcd@plt>
lea    0xe88(%rip),%rdi
mov    %ebx,%esi
mov    %r15,%rbx
mov    %r13,%r15
lea    0xf(%rsp),%r13
mov    %r12d,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0x0,0x10(%rsp)
movl   $0x0,0x14(%rsp)
lea    0xdf5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x10(%rsp),%eax
test   %eax,%eax
je     1291 <main+0x151>
test   %eax,%eax
js     1280 <main+0x140>
nopw   0x0(%rax,%rax,1)
lea    0xdf1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x14(%rsp),%r12d
test   %r12d,%r12d
jg     11c0 <main+0x80>
mov    %r14,%rdi
call   1030 <puts@plt>
jmp    1240 <main+0x100>
lea    0xe31(%rip),%rdi
call   1030 <puts@plt>
jmp    11f4 <main+0xb4>
lea    0xde8(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [50 x i8] c"Please enter a positve integer. Enter 0 to quit: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [58 x i8] c"Error! This is not a positive integer.\0APlease try again.\0A\00"
@.str.4 = [43 x i8] c"Please enter the second positive integer: \00"
@.str.5 = [40 x i8] c"Error! This is not a positive integer.\0A\00"
@.str.6 = [29 x i8] c"The gcd of %d and %d is %d.\0A\00"
@.str.7 = [7 x i8] c"Error\0A\00"
@.str.8 = [18 x i8] c"Have a nice day.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
br label %7
7: ; preds = %52, %0
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %53
10: ; preds = %7
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %10
store i32 1, i32* %3
br label %52
17: ; preds = %10
%18 = load i32, i32* %4
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.3, i64 0, i64 0))
br label %51
22: ; preds = %17
%23 = load i32, i32* %4
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %48
25: ; preds = %22
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
%27 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%28 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
br label %29
29: ; preds = %32, %25
%30 = load i32, i32* %5
%31 = icmp slt i32 %30, 1
br i1 %31, label %32, label %37
32: ; preds = %29
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
%35 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%36 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
br label %29
37: ; preds = %29
%38 = load i32, i32* %5
%39 = icmp sgt i32 %38, 0
br i1 %39, label %40, label %47
40: ; preds = %37
%41 = load i32, i32* %4
%42 = load i32, i32* %5
%43 = load i32, i32* %4
%44 = load i32, i32* %5
%45 = call i32 @gcd(i32 %43, i32 %44)
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i32 %41, i32 %42, i32 %45)
br label %47
47: ; preds = %40, %37
br label %50
48: ; preds = %22
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
br label %50
50: ; preds = %48, %47
br label %51
51: ; preds = %50, %20
br label %52
52: ; preds = %51, %16
br label %7
53: ; preds = %7
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [50 x i8] c"Please enter a positve integer. Enter 0 to quit: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"%c\00"
@.str.4 = [43 x i8] c"Please enter the second positive integer: \00"
@.str.6 = [29 x i8] c"The gcd of %d and %d is %d.\0A\00"
@str = [17 x i8] c"Have a nice day.\00"
@str.9 = [39 x i8] c"Error! This is not a positive integer.\00"
@str.10 = [57 x i8] c"Error! This is not a positive integer.\0APlease try again.\00"
define i32 @main() {
%1 = alloca i8
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %2
store i32 0, i32* %3
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, 0
br i1 %10, label %40, label %11
11: ; preds = %0, %34
%12 = phi i32 [ %38, %34 ], [ %9, %0 ]
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str.10, i64 0, i64 0))
br label %34
16: ; preds = %11
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%19 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%20 = load i32, i32* %3
%21 = icmp slt i32 %20, 1
br i1 %21, label %22, label %29
22: ; preds = %16, %22
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.9, i64 0, i64 0))
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
%25 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%26 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%27 = load i32, i32* %3
%28 = icmp slt i32 %27, 1
br i1 %28, label %22, label %29
29: ; preds = %22, %16
%30 = phi i32 [ %20, %16 ], [ %27, %22 ]
%31 = load i32, i32* %2
%32 = call i32 @gcd(i32 %31, i32 %30)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i32 %31, i32 %30, i32 %32)
br label %34
34: ; preds = %14, %29
store i32 0, i32* %2
store i32 0, i32* %3
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%36 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%37 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%38 = load i32, i32* %2
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %11
40: ; preds = %34, %0
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
ret i32 0
}