#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 sscanf(char const *, char *, int *);
int /*<<< orphan*/ strlen(char const *);
scalar_t__ strstr(char const *, char *);
int check_int(const char *p, int *val) {
  if (!strlen(p))
    return 1;
  if (strstr(p, "0x") || strstr(p, "0X")) {
    if (sscanf(p, "%x", val) == 1)
      return 0;
  } else {
    if (sscanf(p, "%u", val) == 1)
      return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<check_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
jne    115e <check_int+0x2e>
movl   $0x1,-0x4(%rbp)
jmp    11f5 <check_int+0xc5>
mov    -0x10(%rbp),%rdi
lea    0xe97(%rip),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%rax
jne    1192 <check_int+0x62>
mov    -0x10(%rbp),%rdi
lea    0xe80(%rip),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%rax
je     11c0 <check_int+0x90>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe65(%rip),%rsi
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    11bb <check_int+0x8b>
movl   $0x0,-0x4(%rbp)
jmp    11f5 <check_int+0xc5>
jmp    11ee <check_int+0xbe>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe3a(%rip),%rsi
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    11e9 <check_int+0xb9>
movl   $0x0,-0x4(%rbp)
jmp    11f5 <check_int+0xc5>
jmp    11ee <check_int+0xbe>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_int>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    $0x1,%eax
test   %ecx,%ecx
je     1192 <check_int+0x62>
lea    0xeaf(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strstr@plt>
test   %rax,%rax
jne    1172 <check_int+0x42>
lea    0xe9e(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strstr@plt>
test   %rax,%rax
je     119a <check_int+0x6a>
lea    0xe8d(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <sscanf@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
je     1192 <check_int+0x62>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe68(%rip),%rsi
jmp    1179 <check_int+0x49>

LLVM IR (-O0):
@.str = [3 x i8] c"0x\00"
@.str.1 = [3 x i8] c"0X\00"
@.str.2 = [3 x i8] c"%x\00"
@.str.3 = [3 x i8] c"%u\00"
define i32 @check_int(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
store i8* %0, i8** %4
store i32* %1, i32** %5
%6 = load i8*, i8** %4
%7 = call i32 @strlen(i8* %6)
%8 = icmp ne i32 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %2
store i32 1, i32* %3
br label %33
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = call i64 @strstr(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%13 = icmp ne i64 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = call i64 @strstr(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %14, %10
%19 = load i8*, i8** %4
%20 = load i32*, i32** %5
%21 = call i32 @sscanf(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %20)
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %24
23: ; preds = %18
store i32 0, i32* %3
br label %33
24: ; preds = %18
br label %32
25: ; preds = %14
%26 = load i8*, i8** %4
%27 = load i32*, i32** %5
%28 = call i32 @sscanf(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %27)
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %31
30: ; preds = %25
store i32 0, i32* %3
br label %33
31: ; preds = %25
br label %32
32: ; preds = %31, %24
store i32 1, i32* %3
br label %33
33: ; preds = %32, %30, %23, %9
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@.str = [3 x i8] c"0x\00"
@.str.1 = [3 x i8] c"0X\00"
@.str.2 = [3 x i8] c"%x\00"
@.str.3 = [3 x i8] c"%u\00"
define i32 @check_int(i8* %0, i32* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %18, label %5
5: ; preds = %2
%6 = tail call i64 @strstr(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = tail call i64 @strstr(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %8, %5
%12 = tail call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%13 = icmp eq i32 %12, 1
br i1 %13, label %18, label %17
14: ; preds = %8
%15 = tail call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%16 = icmp eq i32 %15, 1
br i1 %16, label %18, label %17
17: ; preds = %14, %11
br label %18
18: ; preds = %14, %11, %2, %17
%19 = phi i32 [ 1, %17 ], [ 1, %2 ], [ 0, %11 ], [ 0, %14 ]
ret i32 %19
}