#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 */
typedef int uint8_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ memcmp(int const *, char *, int);
int /*<<< orphan*/ memcpy(int *, int const *, int);
int /*<<< orphan*/ printf(char *, ...);
void identify_sigret_code(const void *address) {
  uint32_t i;
  const uint8_t *addr = (const uint8_t *)address;
  if (!memcmp(addr, "\x48\xc7\xc0", 3) && !memcmp(addr + 7, "\x0f\x05", 2)) {
    memcpy(&i, addr + 3, 4);
    printf("... code: syscall(%u)\n", i);
    return;
  }
  printf("... unknown code. Here are some bytes:");
  for (i = 0; i < 8; i++) {
    printf(" %02x", addr[i]);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<identify_sigret_code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeb1(%rip),%rsi
mov    $0x3,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%eax
jne    11b0 <identify_sigret_code+0x80>
mov    -0x18(%rbp),%rdi
add    $0x1c,%rdi
lea    0xe93(%rip),%rsi
mov    $0x2,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%eax
jne    11b0 <identify_sigret_code+0x80>
mov    -0x18(%rbp),%rsi
add    $0xc,%rsi
lea    -0xc(%rbp),%rdi
mov    $0x4,%edx
call   1050 <memcpy@plt>
mov    -0xc(%rbp),%esi
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1204 <identify_sigret_code+0xd4>
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x8,-0xc(%rbp)
jge    11f6 <identify_sigret_code+0xc6>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11c5 <identify_sigret_code+0x95>
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<identify_sigret_code>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xeb2(%rip),%rsi
mov    $0x3,%edx
call   1050 <memcmp@plt>
test   %eax,%eax
jne    1179 <identify_sigret_code+0x39>
lea    0x1c(%rbx),%rdi
lea    0xe9d(%rip),%rsi
mov    $0x2,%edx
call   1050 <memcmp@plt>
test   %eax,%eax
je     1206 <identify_sigret_code+0xc6>
lea    0xe9e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%esi
lea    0xeb5(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x14(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x1c(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <putchar@plt>
add    $0xc,%rbx
lea    0x4(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1060 <memcpy@plt>
mov    0x4(%rsp),%esi
lea    0xde0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"H\C7\C0\00"
@.str.1 = [3 x i8] c"\0F\05\00"
@.str.2 = [23 x i8] c"... code: syscall(%u)\0A\00"
@.str.3 = [39 x i8] c"... unknown code. Here are some bytes:\00"
@.str.4 = [6 x i8] c" %02x\00"
@.str.5 = [2 x i8] c"\0A\00"
define void @identify_sigret_code(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = bitcast i8* %5 to i32*
store i32* %6, i32** %4
%7 = load i32*, i32** %4
%8 = call i32 @memcmp(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%9 = icmp ne i32 %8, 0
br i1 %9, label %21, label %10
10: ; preds = %1
%11 = load i32*, i32** %4
%12 = getelementptr inbounds i32, i32* %11, i64 7
%13 = call i32 @memcmp(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%14 = icmp ne i32 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %10
%16 = load i32*, i32** %4
%17 = getelementptr inbounds i32, i32* %16, i64 3
%18 = call i32 @memcpy(i32* %3, i32* %17, i32 4)
%19 = load i32, i32* %3
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %19)
br label %38
21: ; preds = %10, %1
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %23
23: ; preds = %33, %21
%24 = load i32, i32* %3
%25 = icmp slt i32 %24, 8
br i1 %25, label %26, label %36
26: ; preds = %23
%27 = load i32*, i32** %4
%28 = load i32, i32* %3
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = load i32, i32* %30
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %26
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 1
store i32 %35, i32* %3
br label %23
36: ; preds = %23
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %38
38: ; preds = %36, %15
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"H\C7\C0\00"
@.str.1 = [3 x i8] c"\0F\05\00"
@.str.2 = [23 x i8] c"... code: syscall(%u)\0A\00"
@.str.3 = [39 x i8] c"... unknown code. Here are some bytes:\00"
@.str.4 = [6 x i8] c" %02x\00"
define void @identify_sigret_code(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = bitcast i8* %0 to i32*
%5 = tail call i32 @memcmp(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %18
7: ; preds = %1
%8 = getelementptr inbounds i8, i8* %0, i64 28
%9 = bitcast i8* %8 to i32*
%10 = tail call i32 @memcmp(i32* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %7
%13 = getelementptr inbounds i8, i8* %0, i64 12
%14 = bitcast i8* %13 to i32*
%15 = call i32 @memcpy(i32* %2, i32* %14, i32 4)
%16 = load i32, i32* %2
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %16)
br label %51
18: ; preds = %7, %1
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
%20 = load i32, i32* %4
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %20)
%22 = getelementptr inbounds i8, i8* %0, i64 4
%23 = bitcast i8* %22 to i32*
%24 = load i32, i32* %23
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %24)
%26 = getelementptr inbounds i8, i8* %0, i64 8
%27 = bitcast i8* %26 to i32*
%28 = load i32, i32* %27
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %28)
%30 = getelementptr inbounds i8, i8* %0, i64 12
%31 = bitcast i8* %30 to i32*
%32 = load i32, i32* %31
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %32)
%34 = getelementptr inbounds i8, i8* %0, i64 16
%35 = bitcast i8* %34 to i32*
%36 = load i32, i32* %35
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %36)
%38 = getelementptr inbounds i8, i8* %0, i64 20
%39 = bitcast i8* %38 to i32*
%40 = load i32, i32* %39
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %40)
%42 = getelementptr inbounds i8, i8* %0, i64 24
%43 = bitcast i8* %42 to i32*
%44 = load i32, i32* %43
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %44)
%46 = getelementptr inbounds i8, i8* %0, i64 28
%47 = bitcast i8* %46 to i32*
%48 = load i32, i32* %47
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %48)
%50 = tail call i32 @putchar(i32 10)
br label %51
51: ; preds = %18, %12
ret void
}