#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*/ gcd_get_result(int *);
int /*<<< orphan*/ gcd_get_status(int *);
int /*<<< orphan*/ gcd_set_opa(int);
int /*<<< orphan*/ gcd_set_opb(int);
int /*<<< orphan*/ gcd_start();
int proctime();
int rand();
int /*<<< orphan*/ tty_getc(char *);
int /*<<< orphan*/ tty_printf(char *, int);
int main() {
  int opa;
  int opb;
  int res;
  int iter = 0;
  volatile char c;
  volatile int s;
  while (1) {
    iter++;
    opa = rand();
    opb = rand();
    gcd_set_opa(opa);
    gcd_set_opb(opb);
    gcd_start();
    s = 1;
    while (s != 0) {
      gcd_get_status((int *)&s);
    }
    gcd_get_result(&res);
    tty_printf("############### iter = %d ###############\n", iter);
    tty_printf("   - cycle = %d\n", proctime());
    tty_printf("   - opa   = %d\n", opa);
    tty_printf("   - opb   = %d\n", opb);
    tty_printf("   - pgcd  = %d\n", res);
    tty_getc((char *)&c);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   10a0 <rand@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   10a0 <rand@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1080 <gcd_set_opa@plt>
mov    -0xc(%rbp),%edi
call   1030 <gcd_set_opb@plt>
mov    $0x0,%al
call   1060 <gcd_start@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    $0x0,%eax
je     11fb <main+0x6b>
lea    -0x1c(%rbp),%rdi
call   10b0 <gcd_get_status@plt>
jmp    11e1 <main+0x51>
lea    -0x10(%rbp),%rdi
call   1050 <gcd_get_result@plt>
mov    -0x14(%rbp),%esi
lea    0xdf2(%rip),%rdi
call   1040 <tty_printf@plt>
mov    $0x0,%al
call   1070 <proctime@plt>
mov    %eax,%esi
lea    0xe08(%rip),%rdi
call   1040 <tty_printf@plt>
mov    -0x8(%rbp),%esi
lea    0xe0a(%rip),%rdi
call   1040 <tty_printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe0c(%rip),%rdi
call   1040 <tty_printf@plt>
mov    -0x10(%rbp),%esi
lea    0xe0e(%rip),%rdi
call   1040 <tty_printf@plt>
lea    -0x15(%rbp),%rdi
call   1090 <tty_getc@plt>
jmp    11a6 <main+0x16>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xeb9(%rip),%rbp
lea    0x13(%rsp),%r14
lea    0xc(%rsp),%r15
xor    %r12d,%r12d
jmp    1223 <main+0x93>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r12d
lea    0x14(%rsp),%rdi
call   1050 <gcd_get_result@plt>
lea    0xe2b(%rip),%rdi
mov    %r12d,%esi
call   1040 <tty_printf@plt>
xor    %eax,%eax
call   1070 <proctime@plt>
lea    0xe40(%rip),%rdi
mov    %eax,%esi
call   1040 <tty_printf@plt>
lea    0xe43(%rip),%rdi
mov    %r13d,%esi
call   1040 <tty_printf@plt>
lea    0xe45(%rip),%rdi
mov    %ebx,%esi
call   1040 <tty_printf@plt>
mov    0x14(%rsp),%esi
mov    %rbp,%rdi
call   1040 <tty_printf@plt>
mov    %r14,%rdi
call   1090 <tty_getc@plt>
xor    %eax,%eax
call   10a0 <rand@plt>
mov    %eax,%r13d
xor    %eax,%eax
call   10a0 <rand@plt>
mov    %eax,%ebx
mov    %r13d,%edi
call   1080 <gcd_set_opa@plt>
mov    %ebx,%edi
call   1030 <gcd_set_opb@plt>
xor    %eax,%eax
call   1060 <gcd_start@plt>
movl   $0x1,0xc(%rsp)
cmpl   $0x0,0xc(%rsp)
je     11c0 <main+0x30>
nop
mov    %r15,%rdi
call   10b0 <gcd_get_status@plt>
cmpl   $0x0,0xc(%rsp)
jne    1260 <main+0xd0>
jmp    11c0 <main+0x30>

LLVM IR (-O0):
@.str = [43 x i8] c"############### iter = %d ###############\0A\00"
@.str.1 = [17 x i8] c" - cycle = %d\0A\00"
@.str.2 = [17 x i8] c" - opa = %d\0A\00"
@.str.3 = [17 x i8] c" - opb = %d\0A\00"
@.str.4 = [17 x i8] c" - pgcd = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
br label %8
8: ; preds = %0, %23
%9 = load i32, i32* %5
%10 = add nsw i32 %9, 1
store i32 %10, i32* %5
%11 = call i32 (...) @rand()
store i32 %11, i32* %2
%12 = call i32 (...) @rand()
store i32 %12, i32* %3
%13 = load i32, i32* %2
%14 = call i32 @gcd_set_opa(i32 %13)
%15 = load i32, i32* %3
%16 = call i32 @gcd_set_opb(i32 %15)
%17 = call i32 (...) @gcd_start()
store volatile i32 1, i32* %7
br label %18
18: ; preds = %21, %8
%19 = load volatile i32, i32* %7
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @gcd_get_status(i32* %7)
br label %18
23: ; preds = %18
%24 = call i32 @gcd_get_result(i32* %4)
%25 = load i32, i32* %5
%26 = call i32 @tty_printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = call i32 (...) @proctime()
%28 = call i32 @tty_printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %2
%30 = call i32 @tty_printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %3
%32 = call i32 @tty_printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %31)
%33 = load i32, i32* %4
%34 = call i32 @tty_printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %33)
%35 = call i32 @tty_getc(i8* %6)
br label %8
}

LLVM IR (-O2):
@.str = [43 x i8] c"############### iter = %d ###############\0A\00"
@.str.1 = [17 x i8] c" - cycle = %d\0A\00"
@.str.2 = [17 x i8] c" - opa = %d\0A\00"
@.str.3 = [17 x i8] c" - opb = %d\0A\00"
@.str.4 = [17 x i8] c" - pgcd = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %3 to i8*
br label %6
6: ; preds = %20, %0
%7 = phi i32 [ 0, %0 ], [ %8, %20 ]
%8 = add nuw nsw i32 %7, 1
%9 = call i32 (...) @rand()
%10 = call i32 (...) @rand()
%11 = call i32 @gcd_set_opa(i32 %9)
%12 = call i32 @gcd_set_opb(i32 %10)
%13 = call i32 (...) @gcd_start()
store volatile i32 1, i32* %3
%14 = load volatile i32, i32* %3
%15 = icmp eq i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %6, %16
%17 = call i32 @gcd_get_status(i32* %3)
%18 = load volatile i32, i32* %3
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %16
20: ; preds = %16, %6
%21 = call i32 @gcd_get_result(i32* %1)
%22 = call i32 @tty_printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %8)
%23 = call i32 (...) @proctime()
%24 = call i32 @tty_printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = call i32 @tty_printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%26 = call i32 @tty_printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %10)
%27 = load i32, i32* %1
%28 = call i32 @tty_printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %27)
%29 = call i32 @tty_getc(i8* %2)
br label %6
}