#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 const *);
scalar_t__ isNumber(char const *);
int /*<<< orphan*/ snprintf(char *, size_t, char *, ...);
int validation_id(const char *pparam, char *perr, size_t size) {
  const char *pcomm = "id is invalid value";
  int id;
  if (pparam == NULL) {
    (void)snprintf(perr, size, "id is NULL");
    return 1;
  }
  if (isNumber(pparam) == 0) {
    (void)snprintf(perr, size, "%s", pcomm);
    return 1;
  }
  id = atoi(pparam);
  if ((id < 0) || (id > 999)) {
    (void)snprintf(perr, size, "%s", pcomm);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<validation_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    0xeb5(%rip),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117c <validation_id+0x4c>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    0xeab(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1205 <validation_id+0xd5>
mov    -0x10(%rbp),%rdi
call   1040 <isNumber@plt>
cmp    $0x0,%rax
jne    11b5 <validation_id+0x85>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rcx
lea    0xe7d(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1205 <validation_id+0xd5>
mov    -0x10(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jl     11d8 <validation_id+0xa8>
cmpl   $0x3e7,-0x2c(%rbp)
jle    11fe <validation_id+0xce>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rcx
lea    0xe34(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1205 <validation_id+0xd5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validation_id>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
test   %rdi,%rdi
je     117e <validation_id+0x4e>
mov    %rdi,%rbx
call   1040 <isNumber@plt>
test   %rax,%rax
je     1161 <validation_id+0x31>
mov    %rbx,%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x3e8,%ecx
jb     1197 <validation_id+0x67>
lea    0xeb7(%rip),%rdx
lea    0xe91(%rip),%rcx
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <snprintf@plt>
jmp    1192 <validation_id+0x62>
lea    0xe8f(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <snprintf@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [20 x i8] c"id is invalid value\00"
@.str.1 = [11 x i8] c"id is NULL\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @validation_id(i8* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8** %8
%10 = load i8*, i8** %5
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %3
%13 = load i8*, i8** %6
%14 = load i64, i64* %7
%15 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %13, i64 %14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %4
br label %39
16: ; preds = %3
%17 = load i8*, i8** %5
%18 = call i64 @isNumber(i8* %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = load i8*, i8** %6
%22 = load i64, i64* %7
%23 = load i8*, i8** %8
%24 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %21, i64 %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %23)
store i32 1, i32* %4
br label %39
25: ; preds = %16
%26 = load i8*, i8** %5
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %9
%28 = load i32, i32* %9
%29 = icmp slt i32 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %25
%31 = load i32, i32* %9
%32 = icmp sgt i32 %31, 999
br i1 %32, label %33, label %38
33: ; preds = %30, %25
%34 = load i8*, i8** %6
%35 = load i64, i64* %7
%36 = load i8*, i8** %8
%37 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %34, i64 %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %36)
store i32 1, i32* %4
br label %39
38: ; preds = %30
store i32 0, i32* %4
br label %39
39: ; preds = %38, %33, %20, %12
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
@.str = [20 x i8] c"id is invalid value\00"
@.str.1 = [11 x i8] c"id is NULL\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @validation_id(i8* %0, i8* nocapture writeonly %1, i64 %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %17
7: ; preds = %3
%8 = tail call i64 @isNumber(i8* %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %17
12: ; preds = %7
%13 = tail call i32 @atoi(i8* %0)
%14 = icmp ugt i32 %13, 999
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %12, %15, %10, %5
%18 = phi i32 [ 1, %5 ], [ 1, %10 ], [ 1, %15 ], [ 0, %12 ]
ret i32 %18
}