#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 check();
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int ret;
  int count = 0;
  printf("Insert some text (quit with q\n");
  while (1) {
    ret = check();
    if (ret) {
      if (ret == 2) {
        printf("quiting\n");
        break;
      }
      printf("Error, aborting.\n");
      return ret;
    }
    printf("next iteration in while %d\n", count++);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <check@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     118e <main+0x6e>
cmpl   $0x2,-0x8(%rbp)
jne    1175 <main+0x55>
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ac <main+0x8c>
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b3 <main+0x93>
mov    -0xc(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1144 <main+0x24>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
lea    0xee1(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb9(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <check@plt>
test   %eax,%eax
jne    116e <main+0x3e>
lea    0x1(%rbx),%ebp
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%ebx
jmp    1150 <main+0x20>
mov    %eax,%ebp
cmp    $0x2,%eax
jne    1180 <main+0x50>
xor    %ebp,%ebp
lea    0xecd(%rip),%rdi
jmp    1187 <main+0x57>
lea    0xeb3(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Insert some text (quit with q\0A\00"
@.str.1 = [9 x i8] c"quiting\0A\00"
@.str.2 = [18 x i8] c"Error, aborting.\0A\00"
@.str.3 = [28 x i8] c"next iteration in while %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %0, %17
%6 = call i32 (...) @check()
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %5
%10 = load i32, i32* %2
%11 = icmp eq i32 %10, 2
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %21
14: ; preds = %9
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%16 = load i32, i32* %2
store i32 %16, i32* %1
br label %22
17: ; preds = %5
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %18)
br label %5
21: ; preds = %12
store i32 0, i32* %1
br label %22
22: ; preds = %21, %14
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@.str.3 = [28 x i8] c"next iteration in while %d\0A\00"
@str = [30 x i8] c"Insert some text (quit with q\00"
@str.4 = [17 x i8] c"Error, aborting.\00"
@str.5 = [8 x i8] c"quiting\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
br label %2
2: ; preds = %5, %0
%3 = phi i32 [ 0, %0 ], [ %6, %5 ]
%4 = tail call i32 (...) @check()
switch i32 %4, label %8 [
i32 0, label %5
i32 2, label %9
]
5: ; preds = %2
%6 = add nuw nsw i32 %3, 1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %3)
br label %2
8: ; preds = %2
br label %9
9: ; preds = %2, %8
%10 = phi i8* [ getelementptr inbounds ([17 x i8], [17 x i8]* @str.4, i64 0, i64 0), %8 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @str.5, i64 0, i64 0), %2 ]
%11 = phi i32 [ %4, %8 ], [ 0, %2 ]
%12 = tail call i32 @puts(i8* dereferenceable(1) %10)
ret i32 %11
}