#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*/ puts(char *);
int /*<<< orphan*/ scanf(char *, int *);
void fig03_10() {
  unsigned int passes = 0;
  unsigned int failures = 0;
  unsigned int student = 1;
  int result;
  while (student <= 10) {
    printf("%s", "Enter result ( 1=pass,2=fail ): ");
    scanf("%d", &result);
    if (result == 1) {
      passes = passes + 1;
    } else {
      failures = failures + 1;
    }
    student = student + 1;
  }
  printf("Passed %u\n", passes);
  printf("Failed %u\n", failures);
  if (passes > 8) {
    puts("Bonus to instructor!");
  }
}


x86 assembly (clang, -O0):
<fig03_10>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
ja     11ab <fig03_10+0x7b>
lea    0xea2(%rip),%rdi
lea    0xe9e(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb1(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x1,-0x10(%rbp)
jne    1194 <fig03_10+0x64>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    119d <fig03_10+0x6d>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114d <fig03_10+0x1d>
mov    -0x4(%rbp),%esi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x8,-0x4(%rbp)
jbe    11e3 <fig03_10+0xb3>
lea    0xe5f(%rip),%rdi
call   1030 <puts@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fig03_10>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xebe(%rip),%rbx
lea    0xeba(%rip),%r12
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec7(%rip),%rbp
lea    0x4(%rsp),%r13
mov    %rbp,%rdi
mov    %r13,%rsi
call   1050 <scanf@plt>
xor    %r14d,%r14d
xor    %r15d,%r15d
cmpl   $0x1,0x4(%rsp)
setne  %r14b
sete   %r15b
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1050 <scanf@plt>
xor    %ebp,%ebp
xor    %ebx,%ebx
cmpl   $0x1,0x4(%rsp)
setne  %bpl
sete   %bl
add    %r15d,%ebx
add    %r14d,%ebp
lea    0xe4b(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe5e(%rip),%rdi
mov    %rdi,%r12
mov    %r13,%rsi
call   1050 <scanf@plt>
xor    %r14d,%r14d
xor    %r15d,%r15d
cmpl   $0x1,0x4(%rsp)
setne  %r14b
sete   %r15b
add    %ebx,%r15d
add    %ebp,%r14d
lea    0xe0f(%rip),%r13
mov    %r13,%rdi
lea    0xe08(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
lea    0x4(%rsp),%rbx
mov    %rbx,%rsi
call   1050 <scanf@plt>
xor    %ebp,%ebp
xor    %r12d,%r12d
cmpl   $0x1,0x4(%rsp)
setne  %bpl
sete   %r12b
add    %r15d,%r12d
add    %r14d,%ebp
mov    %r13,%rdi
lea    0xdcf(%rip),%r15
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xddf(%rip),%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
xor    %r14d,%r14d
xor    %ebx,%ebx
cmpl   $0x1,0x4(%rsp)
setne  %r14b
sete   %bl
add    %r12d,%ebx
add    %ebp,%r14d
mov    %r13,%r12
mov    %r13,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xda9(%rip),%r13
mov    %r13,%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
xor    %r15d,%r15d
xor    %ebp,%ebp
cmpl   $0x1,0x4(%rsp)
setne  %r15b
sete   %bpl
add    %ebx,%ebp
add    %r14d,%r15d
mov    %r12,%rdi
lea    0xd5a(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
xor    %r14d,%r14d
xor    %ebx,%ebx
cmpl   $0x1,0x4(%rsp)
setne  %r14b
sete   %bl
add    %ebp,%ebx
add    %r15d,%r14d
mov    %r12,%rdi
lea    0xd26(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
xor    %r15d,%r15d
xor    %ebp,%ebp
cmpl   $0x1,0x4(%rsp)
setne  %r15b
sete   %bpl
add    %ebx,%ebp
add    %r14d,%r15d
mov    %r12,%rdi
lea    0xcf1(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rdi
lea    0x4(%rsp),%rbx
mov    %rbx,%rsi
call   1050 <scanf@plt>
xor    %r14d,%r14d
xor    %r12d,%r12d
cmpl   $0x1,0x4(%rsp)
setne  %r14b
sete   %r12b
add    %ebp,%r12d
add    %r15d,%r14d
lea    0xcb7(%rip),%rdi
lea    0xcb3(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
xor    %ebx,%ebx
xor    %ebp,%ebp
cmpl   $0x1,0x4(%rsp)
setne  %bl
sete   %bpl
add    %r12d,%ebp
add    %r14d,%ebx
lea    0xca8(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xca3(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x9,%ebp
jb     13a9 <fig03_10+0x279>
lea    0xc99(%rip),%rdi
call   1030 <puts@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [33 x i8] c"Enter result ( 1=pass,2=fail ): \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [11 x i8] c"Passed %u\0A\00"
@.str.4 = [11 x i8] c"Failed %u\0A\00"
@.str.5 = [21 x i8] c"Bonus to instructor!\00"
define void @fig03_10() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 1, i32* %3
br label %5
5: ; preds = %19, %0
%6 = load i32, i32* %3
%7 = icmp ule i32 %6, 10
br i1 %7, label %8, label %22
8: ; preds = %5
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i32, i32* %1
%15 = add i32 %14, 1
store i32 %15, i32* %1
br label %19
16: ; preds = %8
%17 = load i32, i32* %2
%18 = add i32 %17, 1
store i32 %18, i32* %2
br label %19
19: ; preds = %16, %13
%20 = load i32, i32* %3
%21 = add i32 %20, 1
store i32 %21, i32* %3
br label %5
22: ; preds = %5
%23 = load i32, i32* %1
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %2
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %1
%28 = icmp ugt i32 %27, 8
br i1 %28, label %29, label %31
29: ; preds = %22
%30 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %31
31: ; preds = %29, %22
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [33 x i8] c"Enter result ( 1=pass,2=fail ): \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [11 x i8] c"Passed %u\0A\00"
@.str.4 = [11 x i8] c"Failed %u\0A\00"
@.str.5 = [21 x i8] c"Bonus to instructor!\00"
define void @fig03_10() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp eq i32 %5, 1
%7 = zext i1 %6 to i32
%8 = xor i1 %6, true
%9 = zext i1 %8 to i32
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%12 = load i32, i32* %1
%13 = icmp eq i32 %12, 1
%14 = zext i1 %13 to i32
%15 = add nuw nsw i32 %7, %14
%16 = xor i1 %13, true
%17 = zext i1 %16 to i32
%18 = add nuw nsw i32 %9, %17
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%21 = load i32, i32* %1
%22 = icmp eq i32 %21, 1
%23 = zext i1 %22 to i32
%24 = add nuw nsw i32 %15, %23
%25 = xor i1 %22, true
%26 = zext i1 %25 to i32
%27 = add nuw nsw i32 %18, %26
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%30 = load i32, i32* %1
%31 = icmp eq i32 %30, 1
%32 = zext i1 %31 to i32
%33 = add nuw nsw i32 %24, %32
%34 = xor i1 %31, true
%35 = zext i1 %34 to i32
%36 = add nuw nsw i32 %27, %35
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%38 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%39 = load i32, i32* %1
%40 = icmp eq i32 %39, 1
%41 = zext i1 %40 to i32
%42 = add nuw nsw i32 %33, %41
%43 = xor i1 %40, true
%44 = zext i1 %43 to i32
%45 = add nuw nsw i32 %36, %44
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%47 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%48 = load i32, i32* %1
%49 = icmp eq i32 %48, 1
%50 = zext i1 %49 to i32
%51 = add nuw nsw i32 %42, %50
%52 = xor i1 %49, true
%53 = zext i1 %52 to i32
%54 = add nuw nsw i32 %45, %53
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%56 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%57 = load i32, i32* %1
%58 = icmp eq i32 %57, 1
%59 = zext i1 %58 to i32
%60 = add nuw nsw i32 %51, %59
%61 = xor i1 %58, true
%62 = zext i1 %61 to i32
%63 = add nuw nsw i32 %54, %62
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%65 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%66 = load i32, i32* %1
%67 = icmp eq i32 %66, 1
%68 = zext i1 %67 to i32
%69 = add nuw nsw i32 %60, %68
%70 = xor i1 %67, true
%71 = zext i1 %70 to i32
%72 = add nuw nsw i32 %63, %71
%73 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%74 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%75 = load i32, i32* %1
%76 = icmp eq i32 %75, 1
%77 = zext i1 %76 to i32
%78 = add nuw nsw i32 %69, %77
%79 = xor i1 %76, true
%80 = zext i1 %79 to i32
%81 = add nuw nsw i32 %72, %80
%82 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%83 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%84 = load i32, i32* %1
%85 = icmp eq i32 %84, 1
%86 = zext i1 %85 to i32
%87 = add nuw nsw i32 %78, %86
%88 = xor i1 %85, true
%89 = zext i1 %88 to i32
%90 = add nuw nsw i32 %81, %89
%91 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %87)
%92 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %90)
%93 = icmp ugt i32 %87, 8
br i1 %93, label %94, label %96
94: ; preds = %0
%95 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %96
96: ; preds = %94, %0
ret void
}