#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__ isdigit(char);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int chk_resultcode(char *data, char *stat) {
  int i;
  char *st[] = {"OK", "ERR", 0};
  *stat = 0;
  if (isdigit(data[0]) && isdigit(data[1]) && isdigit(data[2]) &&
      data[3] == ' ') {
    for (i = 0; (st[i] && strcmp(&data[4], st[i]) != 0); i++)
      ;
    if (st[i]) {
      strcpy(stat, &data[4]);
      return (atoi(data));
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<chk_resultcode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2ca9(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0x2ca6(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0x2ca3(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1263 <chk_resultcode+0x123>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1263 <chk_resultcode+0x123>
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1263 <chk_resultcode+0x123>
mov    -0x10(%rbp),%rax
movsbl 0x3(%rax),%eax
cmp    $0x20,%eax
jne    1263 <chk_resultcode+0x123>
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rcx
xor    %eax,%eax
cmpq   $0x0,-0x40(%rbp,%rcx,8)
mov    %al,-0x41(%rbp)
je     1209 <chk_resultcode+0xc9>
mov    -0x10(%rbp),%rdi
add    $0x4,%rdi
movslq -0x1c(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    1219 <chk_resultcode+0xd9>
jmp    122c <chk_resultcode+0xec>
jmp    121e <chk_resultcode+0xde>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d4 <chk_resultcode+0x94>
movslq -0x1c(%rbp),%rax
cmpq   $0x0,-0x40(%rbp,%rax,8)
je     125e <chk_resultcode+0x11e>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x4,%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x4(%rbp)
jmp    126a <chk_resultcode+0x12a>
jmp    1263 <chk_resultcode+0x123>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chk_resultcode>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
movb   $0x0,(%rsi)
movsbl (%rdi),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11a9 <chk_resultcode+0x69>
movsbl 0x1(%rbx),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11a9 <chk_resultcode+0x69>
movsbl 0x2(%rbx),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11a9 <chk_resultcode+0x69>
cmpb   $0x20,0x3(%rbx)
jne    11a9 <chk_resultcode+0x69>
lea    0x4(%rbx),%r15
lea    0xe78(%rip),%rsi
mov    %r15,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11b1 <chk_resultcode+0x71>
lea    0xe67(%rip),%rsi
mov    %r15,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11b1 <chk_resultcode+0x71>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <atoi@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"OK\00"
@.str.1 = [4 x i8] c"ERR\00"
@__const.chk_resultcode.st = [3 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8* null]
define i32 @chk_resultcode(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [3 x i8*]
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = bitcast [3 x i8*]* %7 to i8*
%9 = load i8*, i8** %5
store i8 0, i8* %9
%10 = load i8*, i8** %4
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = call i64 @isdigit(i8 signext %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %69
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i8, i8* %17
%19 = call i64 @isdigit(i8 signext %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %69
21: ; preds = %15
%22 = load i8*, i8** %4
%23 = getelementptr inbounds i8, i8* %22, i64 2
%24 = load i8, i8* %23
%25 = call i64 @isdigit(i8 signext %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %69
27: ; preds = %21
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i64 3
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 32
br i1 %32, label %33, label %69
33: ; preds = %27
store i32 0, i32* %6
br label %34
34: ; preds = %52, %33
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [3 x i8*], [3 x i8*]* %7, i64 0, i64 %36
%38 = load i8*, i8** %37
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %49
40: ; preds = %34
%41 = load i8*, i8** %4
%42 = getelementptr inbounds i8, i8* %41, i64 4
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [3 x i8*], [3 x i8*]* %7, i64 0, i64 %44
%46 = load i8*, i8** %45
%47 = call i64 @strcmp(i8* %42, i8* %46)
%48 = icmp ne i64 %47, 0
br label %49
49: ; preds = %40, %34
%50 = phi i1 [ false, %34 ], [ %48, %40 ]
br i1 %50, label %51, label %55
51: ; preds = %49
br label %52
52: ; preds = %51
%53 = load i32, i32* %6
%54 = add nsw i32 %53, 1
store i32 %54, i32* %6
br label %34
55: ; preds = %49
%56 = load i32, i32* %6
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [3 x i8*], [3 x i8*]* %7, i64 0, i64 %57
%59 = load i8*, i8** %58
%60 = icmp ne i8* %59, null
br i1 %60, label %61, label %68
61: ; preds = %55
%62 = load i8*, i8** %5
%63 = load i8*, i8** %4
%64 = getelementptr inbounds i8, i8* %63, i64 4
%65 = call i32 @strcpy(i8* %62, i8* %64)
%66 = load i8*, i8** %4
%67 = call i32 @atoi(i8* %66)
store i32 %67, i32* %3
br label %70
68: ; preds = %55
br label %69
69: ; preds = %68, %27, %21, %15, %2
store i32 0, i32* %3
br label %70
70: ; preds = %69, %61
%71 = load i32, i32* %3
ret i32 %71
}

LLVM IR (-O2):
@.str = [3 x i8] c"OK\00"
@.str.1 = [4 x i8] c"ERR\00"
define i32 @chk_resultcode(i8* %0, i8* %1) {
store i8 0, i8* %1
%3 = load i8, i8* %0
%4 = tail call i64 @isdigit(i8 signext %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %30, label %6
6: ; preds = %2
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = load i8, i8* %7
%9 = tail call i64 @isdigit(i8 signext %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %30, label %11
11: ; preds = %6
%12 = getelementptr inbounds i8, i8* %0, i64 2
%13 = load i8, i8* %12
%14 = tail call i64 @isdigit(i8 signext %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %30, label %16
16: ; preds = %11
%17 = getelementptr inbounds i8, i8* %0, i64 3
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 32
br i1 %19, label %20, label %30
20: ; preds = %16
%21 = getelementptr inbounds i8, i8* %0, i64 4
%22 = tail call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %20
%25 = tail call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %24, %20
%28 = tail call i32 @strcpy(i8* %1, i8* %21)
%29 = tail call i32 @atoi(i8* %0)
br label %30
30: ; preds = %24, %2, %6, %11, %16, %27
%31 = phi i32 [ %29, %27 ], [ 0, %16 ], [ 0, %11 ], [ 0, %6 ], [ 0, %2 ], [ 0, %24 ]
ret i32 %31
}