#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 */
char CHAR_MAX;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
void goodB2G() {
  char data;
  data = ' ';
  scanf("%c", &data);
  printf("char = %d\n", data);
  if (data < CHAR_MAX) {
    char result = data + 1;
    printf("Char Max es: %d\n", CHAR_MAX);
    printf("%d\n", result);
  } else {
    printf("data value is too large to perform arithmetic safely.\n");
  }
}


x86 assembly (clang, -O0):
<goodB2G>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movb   $0x20,-0x1(%rbp)
lea    0xecd(%rip),%rdi
lea    -0x1(%rbp),%rsi
call   1040 <scanf@plt>
movsbl -0x1(%rbp),%esi
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsbl -0x1(%rbp),%eax
mov    0x2e8f(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jge    119d <goodB2G+0x7d>
movsbl -0x1(%rbp),%eax
add    $0x1,%eax
mov    %al,-0x2(%rbp)
mov    0x2e73(%rip),%rax
movsbl (%rax),%esi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsbl -0x2(%rbp),%esi
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ab <goodB2G+0x8b>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<goodB2G>:
push   %rbx
sub    $0x10,%rsp
movb   $0x20,0xf(%rsp)
lea    0xebf(%rip),%rdi
lea    0xf(%rsp),%rsi
call   1050 <scanf@plt>
movsbl 0xf(%rsp),%esi
lea    0xeac(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movsbl 0xf(%rsp),%ebx
mov    0x2e7e(%rip),%rax
movsbl (%rax),%esi
cmp    %sil,%bl
jge    1195 <goodB2G+0x65>
add    $0x1,%ebx
lea    0xe92(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe91(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11a1 <goodB2G+0x71>
lea    0xe83(%rip),%rdi
call   1030 <puts@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
@.str.1 = [11 x i8] c"char = %d\0A\00"
@CHAR_MAX = global i8 0
@.str.2 = [17 x i8] c"Char Max es: %d\0A\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [55 x i8] c"data value is too large to perform arithmetic safely.\0A\00"
define void @goodB2G() {
%1 = alloca i8
%2 = alloca i8
store i8 32, i8* %1
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1)
%4 = load i8, i8* %1
%5 = sext i8 %4 to i32
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = load i8, i8* %1
%8 = sext i8 %7 to i32
%9 = load i8, i8* @CHAR_MAX
%10 = sext i8 %9 to i32
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %23
12: ; preds = %0
%13 = load i8, i8* %1
%14 = sext i8 %13 to i32
%15 = add nsw i32 %14, 1
%16 = trunc i32 %15 to i8
store i8 %16, i8* %2
%17 = load i8, i8* @CHAR_MAX
%18 = sext i8 %17 to i32
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = load i8, i8* %2
%21 = sext i8 %20 to i32
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %21)
br label %25
23: ; preds = %0
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0))
br label %25
25: ; preds = %23, %12
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
@.str.1 = [11 x i8] c"char = %d\0A\00"
@CHAR_MAX = global i8 0
@.str.2 = [17 x i8] c"Char Max es: %d\0A\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@str = [54 x i8] c"data value is too large to perform arithmetic safely.\00"
define void @goodB2G() {
%1 = alloca i8
store i8 32, i8* %1
%2 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1)
%3 = load i8, i8* %1
%4 = sext i8 %3 to i32
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = load i8, i8* %1
%7 = load i8, i8* @CHAR_MAX
%8 = icmp slt i8 %6, %7
br i1 %8, label %9, label %15
9: ; preds = %0
%10 = sext i8 %7 to i32
%11 = add nsw i8 %6, 1
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%13 = sext i8 %11 to i32
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %13)
br label %17
15: ; preds = %0
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str, i64 0, i64 0))
br label %17
17: ; preds = %15, %9
ret void
}