#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ isdigit(char);
int /*<<< orphan*/ printf(char *);
int check_arg(char *s) {
  int digit = 0;
  if (*s != '-' && *s != '+') {
    printf("Wrong Input: Usage ./program -n +m\n");
    exit(EXIT_FAILURE);
  }
  ++s;
  while (*s != '\0') {
    if (isdigit(*s))
      digit = digit * 10 + (*s - '0');
    else {
      printf("Input must contain only the characters '-' and '+' and "
             "digits\nLeaving......\n");
      exit(EXIT_FAILURE);
    }
    s++;
  }
  return digit;
}


x86 assembly (clang, -O0):
<check_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     117d <check_arg+0x4d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
je     117d <check_arg+0x4d>
lea    0xe96(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11f2 <check_arg+0xc2>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11c7 <check_arg+0x97>
imul   $0xa,-0xc(%rbp),%eax
mov    -0x8(%rbp),%rcx
movsbl (%rcx),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
jmp    11e1 <check_arg+0xb1>
lea    0xe56(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1189 <check_arg+0x59>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_arg>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%al
cmp    $0x2b,%al
je     1141 <check_arg+0x11>
cmp    $0x2d,%al
jne    11a2 <check_arg+0x72>
mov    0x1(%rbx),%al
test   %al,%al
je     117a <check_arg+0x4a>
add    $0x2,%rbx
xor    %r14d,%r14d
nop
movsbl %al,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1188 <check_arg+0x58>
lea    (%r14,%r14,4),%eax
movsbl -0x1(%rbx),%ecx
lea    (%rcx,%rax,2),%r14d
add    $0xffffffd0,%r14d
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1150 <check_arg+0x20>
jmp    117d <check_arg+0x4d>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe71(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
lea    0xea3(%rip),%rdi
jmp    118f <check_arg+0x5f>

LLVM IR (-O0):
@.str = [36 x i8] c"Wrong Input: Usage ./program -n +m\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [77 x i8] c"Input must contain only the characters '-' and '+' and digits\0ALeaving......\0A\00"
define i32 @check_arg(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%4 = load i8*, i8** %2
%5 = load i8, i8* %4
%6 = sext i8 %5 to i32
%7 = icmp ne i32 %6, 45
br i1 %7, label %8, label %17
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 43
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %8, %1
%18 = load i8*, i8** %2
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %2
br label %20
20: ; preds = %42, %17
%21 = load i8*, i8** %2
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %45
25: ; preds = %20
%26 = load i8*, i8** %2
%27 = load i8, i8* %26
%28 = call i64 @isdigit(i8 signext %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %38
30: ; preds = %25
%31 = load i32, i32* %3
%32 = mul nsw i32 %31, 10
%33 = load i8*, i8** %2
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = sub nsw i32 %35, 48
%37 = add nsw i32 %32, %36
store i32 %37, i32* %3
br label %42
38: ; preds = %25
%39 = call i32 @printf(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.1, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %30
%43 = load i8*, i8** %2
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %2
br label %20
45: ; preds = %20
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@str = [76 x i8] c"Input must contain only the characters '-' and '+' and digits\0ALeaving......\00"
@str.2 = [35 x i8] c"Wrong Input: Usage ./program -n +m\00"
define i32 @check_arg(i8* nocapture %0) {
%2 = load i8, i8* %0
switch i8 %2, label %3 [
i8 45, label %7
i8 43, label %7
]
3: ; preds = %1
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.2, i64 0, i64 0))
%5 = load i32, i32* @EXIT_FAILURE
%6 = tail call i32 @exit(i32 %5)
unreachable
7: ; preds = %1, %1
%8 = getelementptr inbounds i8, i8* %0, i64 1
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %30, label %11
11: ; preds = %7, %17
%12 = phi i8 [ %24, %17 ], [ %9, %7 ]
%13 = phi i8* [ %23, %17 ], [ %8, %7 ]
%14 = phi i32 [ %22, %17 ], [ 0, %7 ]
%15 = tail call i64 @isdigit(i8 signext %12)
%16 = icmp eq i64 %15, 0
br i1 %16, label %26, label %17
17: ; preds = %11
%18 = mul nsw i32 %14, 10
%19 = load i8, i8* %13
%20 = sext i8 %19 to i32
%21 = add i32 %18, -48
%22 = add i32 %21, %20
%23 = getelementptr inbounds i8, i8* %13, i64 1
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 0
br i1 %25, label %30, label %11
26: ; preds = %11
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([76 x i8], [76 x i8]* @str, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = tail call i32 @exit(i32 %28)
unreachable
30: ; preds = %17, %7
%31 = phi i32 [ 0, %7 ], [ %22, %17 ]
ret i32 %31
}