#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*/ EXIT_FAILURE;
int /*<<< orphan*/ err(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *read_proc_cmdline();
char *strchr(char const *, char);
char *strdup(char const *);
int strlen(char *);
scalar_t__ strncmp(char const *, char *, int);
char *strndup(char const *, int);
char *read_proc_cmdline_ostree(void) {
  char *cmdline = NULL;
  const char *iter;
  char *ret = NULL;
  cmdline = read_proc_cmdline();
  if (!cmdline)
    err(EXIT_FAILURE, "failed to read /proc/cmdline");
  iter = cmdline;
  while (iter != NULL) {
    const char *next = strchr(iter, ' ');
    const char *next_nonspc = next;
    while (next_nonspc && *next_nonspc == ' ')
      next_nonspc += 1;
    if (strncmp(iter, "ostree=", strlen("ostree=")) == 0) {
      const char *start = iter + strlen("ostree=");
      if (next)
        ret = strndup(start, next - start);
      else
        ret = strdup(start);
      break;
    }
    iter = next_nonspc;
  }
  free(cmdline);
  return ret;
}


x86 assembly (clang, -O0):
<read_proc_cmdline_ostree>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movq   $0x0,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1090 <read_proc_cmdline@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11c3 <read_proc_cmdline_ostree+0x43>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe42(%rip),%rsi
call   1080 <err@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     12ce <read_proc_cmdline_ostree+0x14e>
mov    -0x10(%rbp),%rdi
mov    $0x20,%esi
call   1060 <strchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x28(%rbp)
mov    %al,-0x31(%rbp)
je     1210 <read_proc_cmdline_ostree+0x90>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
sete   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    1220 <read_proc_cmdline_ostree+0xa0>
jmp    1231 <read_proc_cmdline_ostree+0xb1>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11f0 <read_proc_cmdline_ostree+0x70>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    0xddd(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%edx
lea    0xdcb(%rip),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    12c1 <read_proc_cmdline_ostree+0x141>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    0xdad(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     12af <read_proc_cmdline_ostree+0x12f>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
call   1070 <strndup@plt>
mov    %rax,-0x18(%rbp)
jmp    12bc <read_proc_cmdline_ostree+0x13c>
mov    -0x30(%rbp),%rdi
call   10a0 <strdup@plt>
mov    %rax,-0x18(%rbp)
jmp    12ce <read_proc_cmdline_ostree+0x14e>
mov    -0x28(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    11cb <read_proc_cmdline_ostree+0x4b>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_proc_cmdline_ostree>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1090 <read_proc_cmdline@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11af <read_proc_cmdline_ostree+0x2f>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
call   1080 <err@plt>
xor    %r15d,%r15d
lea    0xe64(%rip),%r13
mov    %r14,%rbp
jmp    11dc <read_proc_cmdline_ostree+0x5c>
xchg   %ax,%ax
xor    %ebp,%ebp
mov    %r13,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     120f <read_proc_cmdline_ostree+0x8f>
test   %rbp,%rbp
je     1240 <read_proc_cmdline_ostree+0xc0>
mov    %rbp,%rbx
mov    %rbp,%rdi
mov    $0x20,%esi
call   1060 <strchr@plt>
mov    %rax,%r12
test   %rax,%rax
je     11c0 <read_proc_cmdline_ostree+0x40>
lea    -0x1(%r12),%rax
xchg   %ax,%ax
lea    0x1(%rax),%rbp
cmpb   $0x20,0x1(%rax)
mov    %rbp,%rax
je     1200 <read_proc_cmdline_ostree+0x80>
jmp    11c2 <read_proc_cmdline_ostree+0x42>
lea    0xe07(%rip),%rdi
call   1050 <strlen@plt>
cltq
add    %rax,%rbx
test   %r12,%r12
je     1235 <read_proc_cmdline_ostree+0xb5>
sub    %ebx,%r12d
mov    %rbx,%rdi
mov    %r12d,%esi
call   1070 <strndup@plt>
jmp    123d <read_proc_cmdline_ostree+0xbd>
mov    %rbx,%rdi
call   10a0 <strdup@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [29 x i8] c"failed to read /proc/cmdline\00"
@.str.1 = [8 x i8] c"ostree=\00"
define i8* @read_proc_cmdline_ostree() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* null, i8** %1
store i8* null, i8** %3
%7 = call i8* (...) @read_proc_cmdline()
store i8* %7, i8** %1
%8 = load i8*, i8** %1
%9 = icmp ne i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %0
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @err(i32 %11, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %10, %0
%14 = load i8*, i8** %1
store i8* %14, i8** %2
br label %15
15: ; preds = %60, %13
%16 = load i8*, i8** %2
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %62
18: ; preds = %15
%19 = load i8*, i8** %2
%20 = call i8* @strchr(i8* %19, i8 signext 32)
store i8* %20, i8** %4
%21 = load i8*, i8** %4
store i8* %21, i8** %5
br label %22
22: ; preds = %32, %18
%23 = load i8*, i8** %5
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load i8*, i8** %5
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 32
br label %30
30: ; preds = %25, %22
%31 = phi i1 [ false, %22 ], [ %29, %25 ]
br i1 %31, label %32, label %35
32: ; preds = %30
%33 = load i8*, i8** %5
%34 = getelementptr inbounds i8, i8* %33, i64 1
store i8* %34, i8** %5
br label %22
35: ; preds = %30
%36 = load i8*, i8** %2
%37 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%38 = call i64 @strncmp(i8* %36, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %60
40: ; preds = %35
%41 = load i8*, i8** %2
%42 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
store i8* %44, i8** %6
%45 = load i8*, i8** %4
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %56
47: ; preds = %40
%48 = load i8*, i8** %6
%49 = load i8*, i8** %4
%50 = load i8*, i8** %6
%51 = ptrtoint i8* %49 to i64
%52 = ptrtoint i8* %50 to i64
%53 = sub i64 %51, %52
%54 = trunc i64 %53 to i32
%55 = call i8* @strndup(i8* %48, i32 %54)
store i8* %55, i8** %3
br label %59
56: ; preds = %40
%57 = load i8*, i8** %6
%58 = call i8* @strdup(i8* %57)
store i8* %58, i8** %3
br label %59
59: ; preds = %56, %47
br label %62
60: ; preds = %35
%61 = load i8*, i8** %5
store i8* %61, i8** %2
br label %15
62: ; preds = %59, %15
%63 = load i8*, i8** %1
%64 = call i32 @free(i8* %63)
%65 = load i8*, i8** %3
ret i8* %65
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [29 x i8] c"failed to read /proc/cmdline\00"
@.str.1 = [8 x i8] c"ostree=\00"
define noalias i8* @read_proc_cmdline_ostree() {
%1 = tail call i8* (...) @read_proc_cmdline()
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = load i32, i32* @EXIT_FAILURE
%5 = tail call i32 @err(i32 %4, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %3, %0
br label %7
7: ; preds = %6, %18
%8 = phi i8* [ %19, %18 ], [ %1, %6 ]
%9 = icmp eq i8* %8, null
br i1 %9, label %35, label %10
10: ; preds = %7
%11 = tail call i8* @strchr(i8* %8, i8 signext 32)
%12 = icmp eq i8* %11, null
br i1 %12, label %18, label %13
13: ; preds = %10, %13
%14 = phi i8* [ %17, %13 ], [ %11, %10 ]
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 32
%17 = getelementptr inbounds i8, i8* %14, i64 1
br i1 %16, label %13, label %18
18: ; preds = %13, %10
%19 = phi i8* [ null, %10 ], [ %14, %13 ]
%20 = tail call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %7
23: ; preds = %18
%24 = tail call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %8, i64 %25
br i1 %12, label %33, label %27
27: ; preds = %23
%28 = ptrtoint i8* %11 to i64
%29 = ptrtoint i8* %26 to i64
%30 = sub i64 %28, %29
%31 = trunc i64 %30 to i32
%32 = tail call i8* @strndup(i8* %26, i32 %31)
br label %35
33: ; preds = %23
%34 = tail call i8* @strdup(i8* %26)
br label %35
35: ; preds = %7, %27, %33
%36 = phi i8* [ %34, %33 ], [ %32, %27 ], [ null, %7 ]
%37 = tail call i32 @free(i8* %1)
ret i8* %36
}