#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int foo() {
  int a, b;
  do {
    scanf("%i", &a);
    if (a < 0)
      break;
    scanf("%i", &b);
    if (b < 0)
      break;
    printf("all good %i %i\n", a, b);
    return 0;
  } while (0);
  a = b = 0;
  printf("failed\n");
  return 1;
}


x86 assembly (clang, -O0):
<foo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xed1(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jge    1147 <foo+0x27>
jmp    1186 <foo+0x66>
lea    0xeb2(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0xc(%rbp)
jge    1166 <foo+0x46>
jmp    1186 <foo+0x66>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11a9 <foo+0x89>
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<foo>:
push   %rbx
sub    $0x10,%rsp
lea    0xec4(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,0x8(%rsp)
js     117c <foo+0x4c>
lea    0xeac(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%edx
test   %edx,%edx
js     117c <foo+0x4c>
mov    0x8(%rsp),%esi
lea    0xe92(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    119d <foo+0x6d>
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
lea    0xe80(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%i\00"
@.str.1 = [16 x i8] c"all good %i %i\0A\00"
@.str.2 = [8 x i8] c"failed\0A\00"
define i32 @foo() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
br label %4
4: ; preds = %0
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %4
br label %18
9: ; preds = %4
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %9
br label %18
14: ; preds = %9
%15 = load i32, i32* %2
%16 = load i32, i32* %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %16)
store i32 0, i32* %1
br label %20
18: ; preds = %13, %8
store i32 0, i32* %3
store i32 0, i32* %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %20
20: ; preds = %18, %14
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@.str = [3 x i8] c"%i\00"
@.str.1 = [16 x i8] c"all good %i %i\0A\00"
@str = [7 x i8] c"failed\00"
define i32 @foo() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 0
br i1 %7, label %15, label %8
8: ; preds = %0
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%10 = load i32, i32* %2
%11 = icmp slt i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %8
%13 = load i32, i32* %1
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %10)
br label %17
15: ; preds = %8, %0
store i32 0, i32* %2
store i32 0, i32* %1
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
%18 = phi i32 [ 1, %15 ], [ 0, %12 ]
ret i32 %18
}