#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 */
scalar_t__ doit(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main(int argc, char *argv[]) {
  int x = 0;
  printf("Enter a value: ");
  while (!scanf("%d", &x)) {
    scanf("%*s");
    printf("ERROR enter a number: ");
  }
  int xp = 0;
  printf("Enter a maximum value: ");
  while (!scanf("%d", &xp)) {
    scanf("%*s");
    printf("ERROR enter max '*value' in numbers please: ");
  }
  if (doit(&x, xp))
    printf("Value you entered %d is changed to the maximum allowable value:  "
           "%d.\n",
           x, xp);
  else
    printf("No change in the value that was input %d \n", x);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeae(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1182 <main+0x52>
jmp    11a3 <main+0x73>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    115b <main+0x2b>
movl   $0x0,-0x18(%rbp)
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe51(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11df <main+0xaf>
jmp    1200 <main+0xd0>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b8 <main+0x88>
mov    -0x18(%rbp),%esi
lea    -0x14(%rbp),%rdi
call   1040 <doit@plt>
cmp    $0x0,%rax
je     122f <main+0xff>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1240 <main+0x110>
mov    -0x14(%rbp),%esi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
movl   $0x0,0x4(%rsp)
lea    0xeb9(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xebb(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
test   %eax,%eax
jne    11a5 <main+0x75>
lea    0xea7(%rip),%r14
lea    0xea4(%rip),%r15
lea    0xe96(%rip),%r12
lea    0x4(%rsp),%rbx
nop
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
test   %eax,%eax
je     1180 <main+0x50>
movl   $0x0,(%rsp)
lea    0xe7b(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe4f(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
test   %eax,%eax
jne    1215 <main+0xe5>
lea    0xe3d(%rip),%r14
lea    0xe69(%rip),%r15
lea    0xe2c(%rip),%r12
mov    %rsp,%rbx
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
test   %eax,%eax
je     11f0 <main+0xc0>
mov    (%rsp),%esi
lea    0x4(%rsp),%rdi
call   1040 <doit@plt>
mov    0x4(%rsp),%esi
test   %rax,%rax
je     123e <main+0x10e>
mov    (%rsp),%edx
lea    0xe3e(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    124c <main+0x11c>
lea    0xe74(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Enter a value: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%*s\00"
@.str.3 = [23 x i8] c"ERROR enter a number: \00"
@.str.4 = [24 x i8] c"Enter a maximum value: \00"
@.str.5 = [45 x i8] c"ERROR enter max '*value' in numbers please: \00"
@.str.6 = [70 x i8] c"Value you entered %d is changed to the maximum allowable value: %d.\0A\00"
@.str.7 = [43 x i8] c"No change in the value that was input %d \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %13, %2
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%11 = icmp ne i32 %10, 0
%12 = xor i1 %11, true
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %9
16: ; preds = %9
store i32 0, i32* %7
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %18
18: ; preds = %22, %16
%19 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%20 = icmp ne i32 %19, 0
%21 = xor i1 %20, true
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0))
br label %18
25: ; preds = %18
%26 = load i32, i32* %7
%27 = call i64 @doit(i32* %6, i32 %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = load i32, i32* %6
%31 = load i32, i32* %7
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.6, i64 0, i64 0), i32 %30, i32 %31)
br label %36
33: ; preds = %25
%34 = load i32, i32* %6
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.7, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %33, %29
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"Enter a value: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%*s\00"
@.str.3 = [23 x i8] c"ERROR enter a number: \00"
@.str.4 = [24 x i8] c"Enter a maximum value: \00"
@.str.5 = [45 x i8] c"ERROR enter max '*value' in numbers please: \00"
@.str.6 = [70 x i8] c"Value you entered %d is changed to the maximum allowable value: %d.\0A\00"
@.str.7 = [43 x i8] c"No change in the value that was input %d \0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 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* %3)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %2, %9
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, 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* %3)
%13 = icmp eq i32 %12, 0
br i1 %13, label %9, label %14
14: ; preds = %9, %2
%15 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %14, %19
%20 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0))
%22 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%23 = icmp eq i32 %22, 0
br i1 %23, label %19, label %24
24: ; preds = %19, %14
%25 = load i32, i32* %4
%26 = call i64 @doit(i32* %3, i32 %25)
%27 = icmp eq i64 %26, 0
%28 = load i32, i32* %3
br i1 %27, label %32, label %29
29: ; preds = %24
%30 = load i32, i32* %4
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @.str.6, i64 0, i64 0), i32 %28, i32 %30)
br label %34
32: ; preds = %24
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.7, i64 0, i64 0), i32 %28)
br label %34
34: ; preds = %32, %29
ret i32 0
}