#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 atoi(char *);
scalar_t__ checkForOverflow(int, int, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    printf("usage: %s [POSITIVE NUMBER]\n", argv[0]);
    exit(0);
  }
  if (atoi(argv[1]) < 1) {
    printf("usage: %s [POSITIVE NUMBER]\n", argv[0]);
    exit(0);
  }
  int baseNum = 0x7FFFFFFF;
  int x = atoi(argv[1]);
  int ans;
  int temp = -1;
  printf("\nEnter\n1: Multiplication\n2: Addition\n");
  do {
    printf(">> ");
    scanf("%d", &temp);
  } while ((temp != 1) && (temp != 2));
  printf("You entered %d\n", x);
  printf("The largest signed 32-bit integer is 0x7FFFFFFF = %d\n", baseNum);
  switch (temp) {
  case 1:
    ans = x * baseNum;
    printf("%d x %d = %d\n", baseNum, x, ans);
    break;
  case 2:
    ans = x + baseNum;
    printf("%d + %d = %d\n", baseNum, x, ans);
  }
  printf("In hex:\n%d = 0x%x\n%d = 0x%x\n%d = 0x%x\n", baseNum, baseNum, x, x,
         ans, ans);
  if (checkForOverflow(baseNum, x, ans)) {
    printf("\nOverflow exists.\n");
  } else {
    printf("\nOverflow does not exist.\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     118c <main+0x3c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
cmp    $0x1,%eax
jge    11be <main+0x6e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
movl   $0x7fffffff,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
movl   $0xffffffff,-0x20(%rbp)
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe48(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <scanf@plt>
xor    %eax,%eax
cmpl   $0x1,-0x20(%rbp)
mov    %al,-0x21(%rbp)
je     1221 <main+0xd1>
cmpl   $0x2,-0x20(%rbp)
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11ea <main+0x9a>
mov    -0x18(%rbp),%esi
lea    0xe14(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x29(%rbp)
call   1040 <printf@plt>
mov    -0x29(%rbp),%al
mov    -0x14(%rbp),%esi
lea    0xe0d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
sub    $0x1,%eax
je     1277 <main+0x127>
jmp    1266 <main+0x116>
mov    -0x28(%rbp),%eax
sub    $0x2,%eax
je     129d <main+0x14d>
jmp    12bd <main+0x16d>
mov    -0x18(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12bd <main+0x16d>
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
mov    -0x1c(%rbp),%eax
lea    0xdd4(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1030 <checkForOverflow@plt>
cmp    $0x0,%rax
je     130d <main+0x1bd>
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    131b <main+0x1cb>
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    12a0 <main+0x140>
mov    0x8(%rbx),%rdi
call   1070 <atoi@plt>
test   %eax,%eax
jle    12a0 <main+0x140>
mov    %eax,%r14d
movl   $0xffffffff,0x14(%rsp)
ff
lea    0xf14(%rip),%rdi
call   1040 <puts@plt>
lea    0xe78(%rip),%r15
lea    0xe75(%rip),%rbx
lea    0x14(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <scanf@plt>
mov    0x14(%rsp),%eax
add    $0xfffffffd,%eax
cmp    $0xfffffffe,%eax
jb     11c0 <main+0x60>
lea    0xe3c(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe3b(%rip),%rdi
mov    $0x7fffffff,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x14(%rsp),%eax
cmp    $0x2,%eax
je     1225 <main+0xc5>
cmp    $0x1,%eax
jne    1246 <main+0xe6>
mov    %r14d,%ebp
shl    $0x1f,%ebp
sub    %r14d,%ebp
lea    0xe47(%rip),%rdi
jmp    1235 <main+0xd5>
mov    %r14d,%ebp
add    $0x7fffffff,%ebp
lea    0xe43(%rip),%rdi
mov    $0x7fffffff,%esi
mov    %r14d,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,(%rsp)
lea    0xe36(%rip),%rdi
mov    $0x7fffffff,%esi
mov    $0x7fffffff,%edx
mov    %r14d,%ecx
mov    %r14d,%r8d
mov    %ebp,%r9d
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x7fffffff,%edi
mov    %r14d,%esi
mov    %ebp,%edx
call   1030 <checkForOverflow@plt>
test   %rax,%rax
lea    0xe4f(%rip),%rax
lea    0xe62(%rip),%rdi
cmove  %rax,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0xd56(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"usage: %s [POSITIVE NUMBER]\0A\00"
@.str.1 = [38 x i8] c"\0AEnter\0A1: Multiplication\0A2: Addition\0A\00"
@.str.2 = [4 x i8] c">> \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [16 x i8] c"You entered %d\0A\00"
@.str.5 = [54 x i8] c"The largest signed 32-bit integer is 0x7FFFFFFF = %d\0A\00"
@.str.6 = [14 x i8] c"%d x %d = %d\0A\00"
@.str.7 = [14 x i8] c"%d + %d = %d\0A\00"
@.str.8 = [39 x i8] c"In hex:\0A%d = 0x%x\0A%d = 0x%x\0A%d = 0x%x\0A\00"
@.str.9 = [19 x i8] c"\0AOverflow exists.\0A\00"
@.str.10 = [27 x i8] c"\0AOverflow does not exist.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 0)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
%23 = icmp slt i32 %22, 1
br i1 %23, label %24, label %30
24: ; preds = %18
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 0)
unreachable
30: ; preds = %18
store i32 2147483647, i32* %6
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @atoi(i8* %33)
store i32 %34, i32* %7
store i32 -1, i32* %9
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %36
36: ; preds = %45, %30
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %9)
br label %39
39: ; preds = %36
%40 = load i32, i32* %9
%41 = icmp ne i32 %40, 1
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i32, i32* %9
%44 = icmp ne i32 %43, 2
br label %45
45: ; preds = %42, %39
%46 = phi i1 [ false, %39 ], [ %44, %42 ]
br i1 %46, label %36, label %47
47: ; preds = %45
%48 = load i32, i32* %7
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %48)
%50 = load i32, i32* %6
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0), i32 %50)
%52 = load i32, i32* %9
switch i32 %52, label %69 [
i32 1, label %53
i32 2, label %61
]
53: ; preds = %47
%54 = load i32, i32* %7
%55 = load i32, i32* %6
%56 = mul nsw i32 %54, %55
store i32 %56, i32* %8
%57 = load i32, i32* %6
%58 = load i32, i32* %7
%59 = load i32, i32* %8
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i32 %57, i32 %58, i32 %59)
br label %69
61: ; preds = %47
%62 = load i32, i32* %7
%63 = load i32, i32* %6
%64 = add nsw i32 %62, %63
store i32 %64, i32* %8
%65 = load i32, i32* %6
%66 = load i32, i32* %7
%67 = load i32, i32* %8
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i32 %65, i32 %66, i32 %67)
br label %69
69: ; preds = %61, %47, %53
%70 = load i32, i32* %6
%71 = load i32, i32* %6
%72 = load i32, i32* %7
%73 = load i32, i32* %7
%74 = load i32, i32* %8
%75 = load i32, i32* %8
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i64 0, i64 0), i32 %70, i32 %71, i32 %72, i32 %73, i32 %74, i32 %75)
%77 = load i32, i32* %6
%78 = load i32, i32* %7
%79 = load i32, i32* %8
%80 = call i64 @checkForOverflow(i32 %77, i32 %78, i32 %79)
%81 = icmp ne i64 %80, 0
br i1 %81, label %82, label %84
82: ; preds = %69
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0))
br label %86
84: ; preds = %69
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0))
br label %86
86: ; preds = %84, %82
%87 = load i32, i32* %3
ret i32 %87
}

LLVM IR (-O2):
@.str = [29 x i8] c"usage: %s [POSITIVE NUMBER]\0A\00"
@.str.2 = [4 x i8] c">> \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [16 x i8] c"You entered %d\0A\00"
@.str.5 = [54 x i8] c"The largest signed 32-bit integer is 0x7FFFFFFF = %d\0A\00"
@.str.6 = [14 x i8] c"%d x %d = %d\0A\00"
@.str.7 = [14 x i8] c"%d + %d = %d\0A\00"
@.str.8 = [39 x i8] c"In hex:\0A%d = 0x%x\0A%d = 0x%x\0A%d = 0x%x\0A\00"
@str = [37 x i8] c"\0AEnter\0A1: Multiplication\0A2: Addition\00"
@str.11 = [26 x i8] c"\0AOverflow does not exist.\00"
@str.12 = [18 x i8] c"\0AOverflow exists.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp eq i32 %0, 2
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 0)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = icmp slt i32 %12, 1
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i8*, i8** %1
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = tail call i32 @exit(i32 0)
unreachable
18: ; preds = %9
%19 = bitcast i32* %3 to i8*
store i32 -1, i32* %3
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
br label %21
21: ; preds = %21, %18
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%24 = load i32, i32* %3
%25 = add i32 %24, -3
%26 = icmp ult i32 %25, -2
br i1 %26, label %21, label %27
27: ; preds = %21
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %12)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0), i32 2147483647)
%30 = load i32, i32* %3
switch i32 %30, label %37 [
i32 1, label %31
i32 2, label %34
]
31: ; preds = %27
%32 = mul nsw i32 %12, 2147483647
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i32 2147483647, i32 %12, i32 %32)
br label %37
34: ; preds = %27
%35 = add nsw i32 %12, 2147483647
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i32 2147483647, i32 %12, i32 %35)
br label %37
37: ; preds = %34, %27, %31
%38 = phi i32 [ undef, %27 ], [ %35, %34 ], [ %32, %31 ]
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i64 0, i64 0), i32 2147483647, i32 2147483647, i32 %12, i32 %12, i32 %38, i32 %38)
%40 = call i64 @checkForOverflow(i32 2147483647, i32 %12, i32 %38)
%41 = icmp eq i64 %40, 0
%42 = select i1 %41, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @str.11, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @str.12, i64 0, i64 0)
%43 = call i32 @puts(i8* dereferenceable(1) %42)
ret i32 0
}