#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*/ sprintf(unsigned char *, char *, unsigned int);
int /*<<< orphan*/ strcpy(unsigned char *, char *);
void find_pname(unsigned int id, unsigned char *pname) {
  unsigned int j;
  struct {
    char name[20];
    int code;
  } pcodes[] = {{"M3Boot", 0x20000},
                {"M3Boot-ptable", 0x10000},
                {"M3Boot_R11", 0x200000},
                {"Ptable", 0x10000},
                {"Fastboot", 0x110000},
                {"Logo", 0x130000},
                {"Kernel", 0x30000},
                {"Kernel_R11", 0x90000},
                {"VxWorks", 0x40000},
                {"VxWorks_R11", 0x220000},
                {"M3Image", 0x50000},
                {"M3Image_R11", 0x230000},
                {"DSP", 0x60000},
                {"DSP_R11", 0x240000},
                {"Nvdload", 0x70000},
                {"Nvdload_R11", 0x250000},
                {"Nvimg", 0x80000},
                {"System", 0x590000},
                {"System", 0x100000},
                {"APP", 0x570000},
                {"APP", 0x5a0000},
                {"Oeminfo", 0xa0000},
                {"CDROMISO", 0xb0000},
                {"Oeminfo", 0x550000},
                {"Oeminfo", 0x510000},
                {"Oeminfo", 0x1a0000},
                {"WEBUI", 0x560000},
                {"WEBUI", 0x5b0000},
                {"Wimaxcfg", 0x170000},
                {"Wimaxcrf", 0x180000},
                {"Userdata", 0x190000},
                {"Online", 0x1b0000},
                {"Online", 0x5d0000},
                {"Online", 0x5e0000},
                {0, 0}};
  for (j = 0; pcodes[j].code != 0; j++) {
    if (pcodes[j].code == id)
      break;
  }
  if (pcodes[j].code != 0)
    strcpy(pname, pcodes[j].name);
  else
    sprintf(pname, "U%08x", id);
}


x86 assembly (clang, -O0):
<find_pname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x360,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x360(%rbp),%rdi
lea    0xeb0(%rip),%rsi
mov    $0x348,%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
lea    -0x360(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
cmpl   $0x0,0x14(%rax)
je     11b5 <find_pname+0x85>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
lea    -0x360(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    0x14(%rax),%eax
cmp    -0x4(%rbp),%eax
jne    11a2 <find_pname+0x72>
jmp    11b5 <find_pname+0x85>
jmp    11a7 <find_pname+0x77>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1161 <find_pname+0x31>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
lea    -0x360(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
cmpl   $0x0,0x14(%rax)
je     11f1 <find_pname+0xc1>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%eax
lea    -0x360(%rbp),%rsi
imul   $0x18,%rax,%rax
add    %rax,%rsi
call   1030 <strcpy@plt>
jmp    1204 <find_pname+0xd4>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0x1149(%rip),%rsi
call   1050 <sprintf@plt>
add    $0x360,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_pname>:
push   %rbp
push   %rbx
sub    $0x348,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xebb(%rip),%rsi
mov    %rsp,%rdi
mov    $0x348,%edx
call   1040 <memcpy@plt>
mov    $0xffffffff,%eax
nopw   0x0(%rax,%rax,1)
add    $0x1,%eax
lea    (%rax,%rax,2),%rcx
mov    0x14(%rsp,%rcx,8),%ecx
test   %ecx,%ecx
je     1173 <find_pname+0x43>
cmp    %ebp,%ecx
jne    1160 <find_pname+0x30>
test   %ecx,%ecx
je     1193 <find_pname+0x63>
mov    %eax,%eax
lea    (%rax,%rax,2),%rax
lea    (%rsp,%rax,8),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
add    $0x348,%rsp
pop    %rbx
pop    %rbp
ret
lea    0x11ae(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
add    $0x348,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <sprintf@plt>

LLVM IR (-O0):
%struct.anon = type { [20 x i8], i32 }
@__const.find_pname.pcodes = [35 x %struct.anon] [%struct.anon { [20 x i8] c"M3Boot\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 131072 }, %struct.anon { [20 x i8] c"M3Boot-ptable\00\00\00\00\00\00\00", i32 65536 }, %struct.anon { [20 x i8] c"M3Boot_R11\00\00\00\00\00\00\00\00\00\00", i32 2097152 }, %struct.anon { [20 x i8] c"Ptable\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 65536 }, %struct.anon { [20 x i8] c"Fastboot\00\00\00\00\00\00\00\00\00\00\00\00", i32 1114112 }, %struct.anon { [20 x i8] c"Logo\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 1245184 }, %struct.anon { [20 x i8] c"Kernel\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 196608 }, %struct.anon { [20 x i8] c"Kernel_R11\00\00\00\00\00\00\00\00\00\00", i32 589824 }, %struct.anon { [20 x i8] c"VxWorks\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 262144 }, %struct.anon { [20 x i8] c"VxWorks_R11\00\00\00\00\00\00\00\00\00", i32 2228224 }, %struct.anon { [20 x i8] c"M3Image\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 327680 }, %struct.anon { [20 x i8] c"M3Image_R11\00\00\00\00\00\00\00\00\00", i32 2293760 }, %struct.anon { [20 x i8] c"DSP\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 393216 }, %struct.anon { [20 x i8] c"DSP_R11\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 2359296 }, %struct.anon { [20 x i8] c"Nvdload\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 458752 }, %struct.anon { [20 x i8] c"Nvdload_R11\00\00\00\00\00\00\00\00\00", i32 2424832 }, %struct.anon { [20 x i8] c"Nvimg\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 524288 }, %struct.anon { [20 x i8] c"System\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 5832704 }, %struct.anon { [20 x i8] c"System\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 1048576 }, %struct.anon { [20 x i8] c"APP\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 5701632 }, %struct.anon { [20 x i8] c"APP\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 5898240 }, %struct.anon { [20 x i8] c"Oeminfo\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 655360 }, %struct.anon { [20 x i8] c"CDROMISO\00\00\00\00\00\00\00\00\00\00\00\00", i32 720896 }, %struct.anon { [20 x i8] c"Oeminfo\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 5570560 }, %struct.anon { [20 x i8] c"Oeminfo\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 5308416 }, %struct.anon { [20 x i8] c"Oeminfo\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 1703936 }, %struct.anon { [20 x i8] c"WEBUI\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 5636096 }, %struct.anon { [20 x i8] c"WEBUI\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 5963776 }, %struct.anon { [20 x i8] c"Wimaxcfg\00\00\00\00\00\00\00\00\00\00\00\00", i32 1507328 }, %struct.anon { [20 x i8] c"Wimaxcrf\00\00\00\00\00\00\00\00\00\00\00\00", i32 1572864 }, %struct.anon { [20 x i8] c"Userdata\00\00\00\00\00\00\00\00\00\00\00\00", i32 1638400 }, %struct.anon { [20 x i8] c"Online\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 1769472 }, %struct.anon { [20 x i8] c"Online\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 6094848 }, %struct.anon { [20 x i8] c"Online\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 6160384 }, %struct.anon zeroinitializer]
@.str = [6 x i8] c"U%08x\00"
define void @find_pname(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [35 x %struct.anon]
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = bitcast [35 x %struct.anon]* %6 to i8*
store i32 0, i32* %5
br label %8
8: ; preds = %25, %2
%9 = load i32, i32* %5
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds [35 x %struct.anon], [35 x %struct.anon]* %6, i64 0, i64 %10
%12 = getelementptr inbounds %struct.anon, %struct.anon* %11, i32 0, i32 1
%13 = load i32, i32* %12
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %28
15: ; preds = %8
%16 = load i32, i32* %5
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds [35 x %struct.anon], [35 x %struct.anon]* %6, i64 0, i64 %17
%19 = getelementptr inbounds %struct.anon, %struct.anon* %18, i32 0, i32 1
%20 = load i32, i32* %19
%21 = load i32, i32* %3
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %15
br label %28
24: ; preds = %15
br label %25
25: ; preds = %24
%26 = load i32, i32* %5
%27 = add i32 %26, 1
store i32 %27, i32* %5
br label %8
28: ; preds = %23, %8
%29 = load i32, i32* %5
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds [35 x %struct.anon], [35 x %struct.anon]* %6, i64 0, i64 %30
%32 = getelementptr inbounds %struct.anon, %struct.anon* %31, i32 0, i32 1
%33 = load i32, i32* %32
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %43
35: ; preds = %28
%36 = load i8*, i8** %4
%37 = load i32, i32* %5
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds [35 x %struct.anon], [35 x %struct.anon]* %6, i64 0, i64 %38
%40 = getelementptr inbounds %struct.anon, %struct.anon* %39, i32 0, i32 0
%41 = getelementptr inbounds [20 x i8], [20 x i8]* %40, i64 0, i64 0
%42 = call i32 @strcpy(i8* %36, i8* %41)
br label %47
43: ; preds = %28
%44 = load i8*, i8** %4
%45 = load i32, i32* %3
%46 = call i32 @sprintf(i8* %44, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %45)
br label %47
47: ; preds = %43, %35
ret void
}

LLVM IR (-O2):
%struct.anon = type { [20 x i8], i32 }
@__const.find_pname.pcodes = [35 x %struct.anon] [%struct.anon { [20 x i8] c"M3Boot\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 131072 }, %struct.anon { [20 x i8] c"M3Boot-ptable\00\00\00\00\00\00\00", i32 65536 }, %struct.anon { [20 x i8] c"M3Boot_R11\00\00\00\00\00\00\00\00\00\00", i32 2097152 }, %struct.anon { [20 x i8] c"Ptable\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 65536 }, %struct.anon { [20 x i8] c"Fastboot\00\00\00\00\00\00\00\00\00\00\00\00", i32 1114112 }, %struct.anon { [20 x i8] c"Logo\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 1245184 }, %struct.anon { [20 x i8] c"Kernel\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 196608 }, %struct.anon { [20 x i8] c"Kernel_R11\00\00\00\00\00\00\00\00\00\00", i32 589824 }, %struct.anon { [20 x i8] c"VxWorks\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 262144 }, %struct.anon { [20 x i8] c"VxWorks_R11\00\00\00\00\00\00\00\00\00", i32 2228224 }, %struct.anon { [20 x i8] c"M3Image\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 327680 }, %struct.anon { [20 x i8] c"M3Image_R11\00\00\00\00\00\00\00\00\00", i32 2293760 }, %struct.anon { [20 x i8] c"DSP\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 393216 }, %struct.anon { [20 x i8] c"DSP_R11\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 2359296 }, %struct.anon { [20 x i8] c"Nvdload\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 458752 }, %struct.anon { [20 x i8] c"Nvdload_R11\00\00\00\00\00\00\00\00\00", i32 2424832 }, %struct.anon { [20 x i8] c"Nvimg\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 524288 }, %struct.anon { [20 x i8] c"System\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 5832704 }, %struct.anon { [20 x i8] c"System\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 1048576 }, %struct.anon { [20 x i8] c"APP\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 5701632 }, %struct.anon { [20 x i8] c"APP\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 5898240 }, %struct.anon { [20 x i8] c"Oeminfo\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 655360 }, %struct.anon { [20 x i8] c"CDROMISO\00\00\00\00\00\00\00\00\00\00\00\00", i32 720896 }, %struct.anon { [20 x i8] c"Oeminfo\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 5570560 }, %struct.anon { [20 x i8] c"Oeminfo\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 5308416 }, %struct.anon { [20 x i8] c"Oeminfo\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 1703936 }, %struct.anon { [20 x i8] c"WEBUI\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 5636096 }, %struct.anon { [20 x i8] c"WEBUI\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 5963776 }, %struct.anon { [20 x i8] c"Wimaxcfg\00\00\00\00\00\00\00\00\00\00\00\00", i32 1507328 }, %struct.anon { [20 x i8] c"Wimaxcrf\00\00\00\00\00\00\00\00\00\00\00\00", i32 1572864 }, %struct.anon { [20 x i8] c"Userdata\00\00\00\00\00\00\00\00\00\00\00\00", i32 1638400 }, %struct.anon { [20 x i8] c"Online\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 1769472 }, %struct.anon { [20 x i8] c"Online\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 6094848 }, %struct.anon { [20 x i8] c"Online\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 6160384 }, %struct.anon zeroinitializer]
@.str = [6 x i8] c"U%08x\00"
define void @find_pname(i32 %0, i8* %1) {
%3 = alloca [35 x %struct.anon]
%4 = getelementptr inbounds [35 x %struct.anon], [35 x %struct.anon]* %3, i64 0, i64 0, i32 0, i64 0
br label %5
5: ; preds = %5, %2
%6 = phi i32 [ 0, %2 ], [ %13, %5 ]
%7 = zext i32 %6 to i64
%8 = getelementptr inbounds [35 x %struct.anon], [35 x %struct.anon]* %3, i64 0, i64 %7, i32 1
%9 = load i32, i32* %8
%10 = icmp eq i32 %9, 0
%11 = icmp eq i32 %9, %0
%12 = or i1 %10, %11
%13 = add i32 %6, 1
br i1 %12, label %14, label %5
14: ; preds = %5
br i1 %10, label %19, label %15
15: ; preds = %14
%16 = zext i32 %6 to i64
%17 = getelementptr inbounds [35 x %struct.anon], [35 x %struct.anon]* %3, i64 0, i64 %16, i32 0, i64 0
%18 = call i32 @strcpy(i8* %1, i8* %17)
br label %21
19: ; preds = %14
%20 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %21
21: ; preds = %19, %15
ret void
}