#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;
  while (*s != '\0') {
    if (isdigit(*s))
      digit = digit * 10 + (*s - '0');
    else {
      printf("Input must contain only 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    $0x0,%eax
je     11ac <check_arg+0x7c>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1181 <check_arg+0x51>
imul   $0xa,-0xc(%rbp),%eax
mov    -0x8(%rbp),%rcx
movsbl (%rcx),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
jmp    119b <check_arg+0x6b>
lea    0xe78(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1143 <check_arg+0x13>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_arg>:
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%al
test   %al,%al
je     117a <check_arg+0x4a>
mov    %rdi,%rbx
add    $0x1,%rbx
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
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>

LLVM IR (-O0):
@.str = [46 x i8] c"Input must contain only digits\0ALeaving......\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @check_arg(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
br label %4
4: ; preds = %26, %1
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %29
9: ; preds = %4
%10 = load i8*, i8** %2
%11 = load i8, i8* %10
%12 = call i64 @isdigit(i8 signext %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %9
%15 = load i32, i32* %3
%16 = mul nsw i32 %15, 10
%17 = load i8*, i8** %2
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = sub nsw i32 %19, 48
%21 = add nsw i32 %16, %20
store i32 %21, i32* %3
br label %26
22: ; preds = %9
%23 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %14
%27 = load i8*, i8** %2
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %2
br label %4
29: ; preds = %4
%30 = load i32, i32* %3
ret i32 %30
}

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