#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 /*<<< orphan*/ prop;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ cache_add_internal(char *, char *);
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
char *strchr(char *, char);
int strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
void cache_repopulate_cmdline_internal() {
  char cmdline[1024];
  char *ptr;
  int fd;
  fd = open("/proc/cmdline", O_RDONLY);
  if (fd >= 0) {
    int n = read(fd, cmdline, 1023);
    if (n < 0)
      n = 0;
    if (n > 0 && cmdline[n - 1] == '\n')
      n--;
    cmdline[n] = 0;
    close(fd);
  } else {
    cmdline[0] = 0;
  }
  ptr = cmdline;
  while (ptr && *ptr) {
    char *x = strchr(ptr, ' ');
    if (x != 0)
      *x++ = 0;
    char *name = ptr;
    ptr = x;
    char *value = strchr(name, '=');
    int name_len = strlen(name);
    if (value == 0)
      continue;
    *value++ = 0;
    if (name_len == 0)
      continue;
    if (!strncmp(name, "androidboot.", 12) && name_len > 12) {
      const char *boot_prop_name = name + 12;
      char prop[32];
      snprintf(prop, sizeof(prop) - 1, "ro.%s", boot_prop_name);
      cache_add_internal(prop, value);
    }
  }
}


x86 assembly (clang, -O0):
<cache_repopulate_cmdline_internal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
lea    0xe65(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x40c(%rbp)
cmpl   $0x0,-0x40c(%rbp)
jl     123e <cache_repopulate_cmdline_internal+0xbe>
mov    -0x40c(%rbp),%edi
lea    -0x400(%rbp),%rsi
mov    $0x3ff,%edx
call   1080 <read@plt>
mov    %eax,-0x410(%rbp)
cmpl   $0x0,-0x410(%rbp)
jge    11e7 <cache_repopulate_cmdline_internal+0x67>
movl   $0x0,-0x410(%rbp)
cmpl   $0x0,-0x410(%rbp)
jle    121f <cache_repopulate_cmdline_internal+0x9f>
mov    -0x410(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x400(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    121f <cache_repopulate_cmdline_internal+0x9f>
mov    -0x410(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x410(%rbp)
movslq -0x410(%rbp),%rax
movb   $0x0,-0x400(%rbp,%rax,1)
mov    -0x40c(%rbp),%edi
call   1070 <close@plt>
jmp    1245 <cache_repopulate_cmdline_internal+0xc5>
movb   $0x0,-0x400(%rbp)
lea    -0x400(%rbp),%rax
mov    %rax,-0x408(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x408(%rbp)
mov    %al,-0x461(%rbp)
je     127f <cache_repopulate_cmdline_internal+0xff>
mov    -0x408(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x461(%rbp)
mov    -0x461(%rbp),%al
test   $0x1,%al
jne    1292 <cache_repopulate_cmdline_internal+0x112>
jmp    13ca <cache_repopulate_cmdline_internal+0x24a>
mov    -0x408(%rbp),%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
je     12d0 <cache_repopulate_cmdline_internal+0x150>
mov    -0x418(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x418(%rbp)
movb   $0x0,(%rax)
mov    -0x408(%rbp),%rax
mov    %rax,-0x420(%rbp)
mov    -0x418(%rbp),%rax
mov    %rax,-0x408(%rbp)
mov    -0x420(%rbp),%rdi
mov    $0x3d,%esi
call   1050 <strchr@plt>
mov    %rax,-0x428(%rbp)
mov    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x42c(%rbp)
cmpq   $0x0,-0x428(%rbp)
jne    1329 <cache_repopulate_cmdline_internal+0x1a9>
jmp    1253 <cache_repopulate_cmdline_internal+0xd3>
mov    -0x428(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x428(%rbp)
movb   $0x0,(%rax)
cmpl   $0x0,-0x42c(%rbp)
jne    1353 <cache_repopulate_cmdline_internal+0x1d3>
jmp    1253 <cache_repopulate_cmdline_internal+0xd3>
mov    -0x420(%rbp),%rdi
lea    0xcad(%rip),%rsi
mov    $0xc,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    13c5 <cache_repopulate_cmdline_internal+0x245>
cmpl   $0xc,-0x42c(%rbp)
jle    13c5 <cache_repopulate_cmdline_internal+0x245>
mov    -0x420(%rbp),%rax
add    $0xc,%rax
mov    %rax,-0x438(%rbp)
lea    -0x460(%rbp),%rdi
mov    -0x438(%rbp),%rcx
mov    $0x1f,%esi
lea    0xc6e(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x460(%rbp),%rdi
mov    -0x428(%rbp),%rsi
call   1090 <cache_add_internal@plt>
jmp    1253 <cache_repopulate_cmdline_internal+0xd3>
add    $0x470,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cache_repopulate_cmdline_internal>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
lea    0xe5f(%rip),%rdi
call   10a0 <open@plt>
test   %eax,%eax
js     11e2 <cache_repopulate_cmdline_internal+0x62>
mov    %eax,%ebx
lea    0x20(%rsp),%rsi
mov    %eax,%edi
mov    $0x3ff,%edx
call   1080 <read@plt>
xor    %ecx,%ecx
test   %eax,%eax
cmovs  %ecx,%eax
jle    11d4 <cache_repopulate_cmdline_internal+0x54>
lea    -0x1(%rax),%ecx
cmpb   $0xa,0x20(%rsp,%rcx,1)
cmove  %ecx,%eax
movslq %eax,%rcx
movb   $0x0,0x20(%rsp,%rcx,1)
mov    %ebx,%edi
call   1070 <close@plt>
jmp    11e7 <cache_repopulate_cmdline_internal+0x67>
movb   $0x0,0x20(%rsp)
lea    0x20(%rsp),%r14
lea    0xe1b(%rip),%r15
mov    %rsp,%r12
jmp    1209 <cache_repopulate_cmdline_internal+0x89>
nopl   0x0(%rax,%rax,1)
test   %r14,%r14
je     12b7 <cache_repopulate_cmdline_internal+0x137>
cmpb   $0x0,(%r14)
je     12b7 <cache_repopulate_cmdline_internal+0x137>
mov    %r14,%rbx
mov    %r14,%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1240 <cache_repopulate_cmdline_internal+0xc0>
mov    %rax,%r14
add    $0x1,%r14
movb   $0x0,(%rax)
jmp    1243 <cache_repopulate_cmdline_internal+0xc3>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %r14d,%r14d
mov    %rbx,%rdi
mov    $0x3d,%esi
call   1050 <strchr@plt>
mov    %rax,%r13
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %r13,%r13
je     1200 <cache_repopulate_cmdline_internal+0x80>
mov    %eax,%ebp
movb   $0x0,0x0(%r13)
test   %eax,%eax
je     1200 <cache_repopulate_cmdline_internal+0x80>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0xc,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1200 <cache_repopulate_cmdline_internal+0x80>
cmp    $0xd,%ebp
jl     1200 <cache_repopulate_cmdline_internal+0x80>
add    $0x1,%r13
add    $0xc,%rbx
mov    %r12,%rdi
mov    $0x1f,%esi
lea    0xd7c(%rip),%rdx
mov    %rbx,%rcx
call   1060 <snprintf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1090 <cache_add_internal@plt>
jmp    1200 <cache_repopulate_cmdline_internal+0x80>
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/cmdline\00"
@O_RDONLY = global i32 0
@.str.1 = [13 x i8] c"androidboot.\00"
@.str.2 = [6 x i8] c"ro.%s\00"
define void @cache_repopulate_cmdline_internal() {
%1 = alloca [1024 x i8]
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca [32 x i8]
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = icmp sge i32 %13, 0
br i1 %14, label %15, label %42
15: ; preds = %0
%16 = load i32, i32* %3
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%18 = call i32 @read(i32 %16, i8* %17, i32 1023)
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %15
store i32 0, i32* %4
br label %22
22: ; preds = %21, %15
%23 = load i32, i32* %4
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %36
25: ; preds = %22
%26 = load i32, i32* %4
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 10
br i1 %32, label %33, label %36
33: ; preds = %25
%34 = load i32, i32* %4
%35 = add nsw i32 %34, -1
store i32 %35, i32* %4
br label %36
36: ; preds = %33, %25, %22
%37 = load i32, i32* %4
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %38
store i8 0, i8* %39
%40 = load i32, i32* %3
%41 = call i32 @close(i32 %40)
br label %44
42: ; preds = %0
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
store i8 0, i8* %43
br label %44
44: ; preds = %42, %36
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
store i8* %45, i8** %2
br label %46
46: ; preds = %96, %79, %73, %44
%47 = load i8*, i8** %2
%48 = icmp ne i8* %47, null
br i1 %48, label %49, label %54
49: ; preds = %46
%50 = load i8*, i8** %2
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp ne i32 %52, 0
br label %54
54: ; preds = %49, %46
%55 = phi i1 [ false, %46 ], [ %53, %49 ]
br i1 %55, label %56, label %97
56: ; preds = %54
%57 = load i8*, i8** %2
%58 = call i8* @strchr(i8* %57, i8 signext 32)
store i8* %58, i8** %5
%59 = load i8*, i8** %5
%60 = icmp ne i8* %59, null
br i1 %60, label %61, label %64
61: ; preds = %56
%62 = load i8*, i8** %5
%63 = getelementptr inbounds i8, i8* %62, i32 1
store i8* %63, i8** %5
store i8 0, i8* %62
br label %64
64: ; preds = %61, %56
%65 = load i8*, i8** %2
store i8* %65, i8** %6
%66 = load i8*, i8** %5
store i8* %66, i8** %2
%67 = load i8*, i8** %6
%68 = call i8* @strchr(i8* %67, i8 signext 61)
store i8* %68, i8** %7
%69 = load i8*, i8** %6
%70 = call i32 @strlen(i8* %69)
store i32 %70, i32* %8
%71 = load i8*, i8** %7
%72 = icmp eq i8* %71, null
br i1 %72, label %73, label %74
73: ; preds = %64
br label %46
74: ; preds = %64
%75 = load i8*, i8** %7
%76 = getelementptr inbounds i8, i8* %75, i32 1
store i8* %76, i8** %7
store i8 0, i8* %75
%77 = load i32, i32* %8
%78 = icmp eq i32 %77, 0
br i1 %78, label %79, label %80
79: ; preds = %74
br label %46
80: ; preds = %74
%81 = load i8*, i8** %6
%82 = call i32 @strncmp(i8* %81, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 12)
%83 = icmp ne i32 %82, 0
br i1 %83, label %96, label %84
84: ; preds = %80
%85 = load i32, i32* %8
%86 = icmp sgt i32 %85, 12
br i1 %86, label %87, label %96
87: ; preds = %84
%88 = load i8*, i8** %6
%89 = getelementptr inbounds i8, i8* %88, i64 12
store i8* %89, i8** %9
%90 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%91 = load i8*, i8** %9
%92 = call i32 @snprintf(i8* %90, i32 31, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %91)
%93 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%94 = load i8*, i8** %7
%95 = call i32 @cache_add_internal(i8* %93, i8* %94)
br label %96
96: ; preds = %87, %84, %80
br label %46
97: ; preds = %54
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cmdline\00"
@O_RDONLY = global i32 0
@.str.1 = [13 x i8] c"androidboot.\00"
@.str.2 = [6 x i8] c"ro.%s\00"
define void @cache_repopulate_cmdline_internal() {
%1 = alloca [1024 x i8]
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp sgt i32 %5, -1
br i1 %6, label %7, label %23
7: ; preds = %0
%8 = call i32 @read(i32 %5, i8* %3, i32 1023)
%9 = icmp sgt i32 %8, 0
%10 = select i1 %9, i32 %8, i32 0
br i1 %9, label %11, label %19
11: ; preds = %7
%12 = add nsw i32 %10, -1
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 10
%17 = select i1 %16, i32 %12, i32 %10
%18 = sext i32 %17 to i64
br label %19
19: ; preds = %11, %7
%20 = phi i64 [ 0, %7 ], [ %18, %11 ]
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %20
store i8 0, i8* %21
%22 = tail call i32 @close(i32 %5)
br label %24
23: ; preds = %0
store i8 0, i8* %3
br label %24
24: ; preds = %23, %19
%25 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
br label %26
26: ; preds = %24, %52
%27 = phi i8* [ %3, %24 ], [ %36, %52 ]
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 0
br i1 %29, label %54, label %30
30: ; preds = %26
%31 = call i8* @strchr(i8* %27, i8 signext 32)
%32 = icmp eq i8* %31, null
br i1 %32, label %35, label %33
33: ; preds = %30
%34 = getelementptr inbounds i8, i8* %31, i64 1
store i8 0, i8* %31
br label %35
35: ; preds = %33, %30
%36 = phi i8* [ %34, %33 ], [ null, %30 ]
%37 = call i8* @strchr(i8* %27, i8 signext 61)
%38 = call i32 @strlen(i8* %27)
%39 = icmp eq i8* %37, null
br i1 %39, label %52, label %40
40: ; preds = %35
%41 = getelementptr inbounds i8, i8* %37, i64 1
store i8 0, i8* %37
%42 = icmp eq i32 %38, 0
br i1 %42, label %52, label %43
43: ; preds = %40
%44 = call i32 @strncmp(i8* %27, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 12)
%45 = icmp eq i32 %44, 0
%46 = icmp sgt i32 %38, 12
%47 = select i1 %45, i1 %46, i1 false
br i1 %47, label %48, label %52
48: ; preds = %43
%49 = getelementptr inbounds i8, i8* %27, i64 12
%50 = call i32 @snprintf(i8* %25, i32 31, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %49)
%51 = call i32 @cache_add_internal(i8* %25, i8* %41)
br label %52
52: ; preds = %43, %48, %40, %35
%53 = icmp eq i8* %36, null
br i1 %53, label %54, label %26
54: ; preds = %52, %26
ret void
}