#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*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
void grab_amd_to_space(char *model_string, char *base_type, int max_len) {
  char *result;
  int i;
  result = strstr(model_string, "AMD ");
  if (result == NULL) {
    strncpy(base_type, "Unknown", 8);
  } else {
    result += 4;
    for (i = 0; i < max_len; i++) {
      if (result[i] == ' ')
        break;
      if (result[i] == '(')
        break;
      if (result[i] == 0)
        break;
      base_type[i] = result[i];
    }
    result[i] = 0;
  }
}


x86 assembly (clang, -O0):
<grab_amd_to_space>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xec2(%rip),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    116c <grab_amd_to_space+0x4c>
mov    -0x10(%rbp),%rdi
lea    0xea8(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
jmp    1209 <grab_amd_to_space+0xe9>
mov    -0x20(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11fd <grab_amd_to_space+0xdd>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    11a5 <grab_amd_to_space+0x85>
jmp    11fd <grab_amd_to_space+0xdd>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x28,%eax
jne    11bf <grab_amd_to_space+0x9f>
jmp    11fd <grab_amd_to_space+0xdd>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    11d9 <grab_amd_to_space+0xb9>
jmp    11fd <grab_amd_to_space+0xdd>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    117f <grab_amd_to_space+0x5f>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grab_amd_to_space>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%rbx
lea    0xed1(%rip),%rsi
call   1040 <strstr@plt>
test   %rax,%rax
je     1170 <grab_amd_to_space+0x50>
test   %ebp,%ebp
jle    118a <grab_amd_to_space+0x6a>
mov    %ebp,%edx
xor    %ecx,%ecx
movabs $0x10100000001,%rsi
jmp    115d <grab_amd_to_space+0x3d>
nopl   (%rax)
mov    %dil,(%rbx,%rcx,1)
add    $0x1,%rcx
cmp    %rcx,%rdx
je     118e <grab_amd_to_space+0x6e>
movzbl 0x4(%rax,%rcx,1),%edi
cmp    $0x28,%rdi
ja     1150 <grab_amd_to_space+0x30>
bt     %rdi,%rsi
jae    1150 <grab_amd_to_space+0x30>
jmp    1190 <grab_amd_to_space+0x70>
lea    0xe8e(%rip),%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <strncpy@plt>
xor    %ecx,%ecx
jmp    1190 <grab_amd_to_space+0x70>
mov    %edx,%ecx
mov    %ecx,%ecx
movb   $0x0,0x4(%rax,%rcx,1)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"AMD \00"
@.str.1 = [8 x i8] c"Unknown\00"
define void @grab_amd_to_space(i8* %0, i8* %1, i32 %2) {
%4 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @strncpy(i8* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 8)
br label %27
8: ; preds = %3
%9 = getelementptr inbounds i8, i8* %4, i64 4
%10 = icmp sgt i32 %2, 0
br i1 %10, label %11, label %23
11: ; preds = %8
%12 = zext i32 %2 to i64
br label %13
13: ; preds = %11, %17
%14 = phi i64 [ 0, %11 ], [ %19, %17 ]
%15 = getelementptr inbounds i8, i8* %9, i64 %14
%16 = load i8, i8* %15
switch i8 %16, label %17 [
i8 32, label %21
i8 40, label %21
i8 0, label %21
]
17: ; preds = %13
%18 = getelementptr inbounds i8, i8* %1, i64 %14
store i8 %16, i8* %18
%19 = add nuw nsw i64 %14, 1
%20 = icmp eq i64 %19, %12
br i1 %20, label %23, label %13
21: ; preds = %13, %13, %13
%22 = trunc i64 %14 to i32
br label %23
23: ; preds = %17, %21, %8
%24 = phi i32 [ 0, %8 ], [ %22, %21 ], [ %2, %17 ]
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %9, i64 %25
store i8 0, i8* %26
br label %27
27: ; preds = %23, %6
ret void
}