#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 */
scalar_t__ cmdline_find_option(char *, char *, int);
int /*<<< orphan*/ early_serial_init(int, int);
int simple_strtoull(char *, char **, int);
int /*<<< orphan*/ strncmp(char *, char *, int);
void parse_earlyprintk(void) {
  int baud = 9600;
  char arg[32];
  int pos = 0;
  int port = 0;
  if (cmdline_find_option("earlyprintk", arg, sizeof arg) > 0) {
    char *e;
    if (!strncmp(arg, "serial", 6)) {
      port = 0x3f8;
      pos += 6;
    }
    if (arg[pos] == ',')
      pos++;
    if (pos == 7 && !strncmp(arg + pos, "0x", 2)) {
      port = simple_strtoull(arg + pos, &e, 16);
      if (port == 0 || arg + pos == e)
        port = 0x3f8;
      else
        pos = e - arg;
    } else if (!strncmp(arg + pos, "ttyS", 4)) {
      static const int bases[] = {0x3f8, 0x2f8};
      int idx = 0;
      if (!strncmp(arg + pos, "ttyS", 4))
        pos += 4;
      if (arg[pos++] == '1')
        idx = 1;
      port = bases[idx];
    }
    if (arg[pos] == ',')
      pos++;
    baud = simple_strtoull(arg + pos, &e, 0);
    if (baud == 0 || arg + pos == e)
      baud = 9600;
  }
  if (port)
    early_serial_init(port, baud);
}


x86 assembly (clang, -O0):
<parse_earlyprintk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x2580,-0x4(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
lea    -0x30(%rbp),%rsi
lea    0xe98(%rip),%rdi
mov    $0x20,%edx
call   1060 <cmdline_find_option@plt>
cmp    $0x0,%rax
jle    133f <parse_earlyprintk+0x1ff>
lea    -0x30(%rbp),%rdi
lea    0xe85(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11aa <parse_earlyprintk+0x6a>
movl   $0x3f8,-0x38(%rbp)
mov    -0x34(%rbp),%eax
add    $0x6,%eax
mov    %eax,-0x34(%rbp)
movslq -0x34(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%eax
cmp    $0x2c,%eax
jne    11c5 <parse_earlyprintk+0x85>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x7,-0x34(%rbp)
jne    124e <parse_earlyprintk+0x10e>
lea    -0x30(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
lea    0xe32(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    124e <parse_earlyprintk+0x10e>
lea    -0x30(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
lea    -0x40(%rbp),%rsi
mov    $0x10,%edx
call   1040 <simple_strtoull@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     122f <parse_earlyprintk+0xef>
lea    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
add    %rcx,%rax
cmp    -0x40(%rbp),%rax
jne    123b <parse_earlyprintk+0xfb>
movl   $0x3f8,-0x38(%rbp)
jmp    1249 <parse_earlyprintk+0x109>
mov    -0x40(%rbp),%rax
lea    -0x30(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x34(%rbp)
jmp    12e0 <parse_earlyprintk+0x1a0>
lea    -0x30(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
lea    0xdb6(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    12db <parse_earlyprintk+0x19b>
movl   $0x0,-0x44(%rbp)
lea    -0x30(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
lea    0xd8a(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    12a8 <parse_earlyprintk+0x168>
mov    -0x34(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x34(%rbp)
cltq
movsbl -0x30(%rbp,%rax,1),%eax
cmp    $0x31,%eax
jne    12ca <parse_earlyprintk+0x18a>
movl   $0x1,-0x44(%rbp)
movslq -0x44(%rbp),%rcx
lea    0xd47(%rip),%rax
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x38(%rbp)
jmp    12e0 <parse_earlyprintk+0x1a0>
movslq -0x34(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%eax
cmp    $0x2c,%eax
jne    12fb <parse_earlyprintk+0x1bb>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
lea    -0x30(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
lea    -0x40(%rbp),%rsi
xor    %edx,%edx
call   1040 <simple_strtoull@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1333 <parse_earlyprintk+0x1f3>
lea    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
add    %rcx,%rax
cmp    -0x40(%rbp),%rax
jne    133a <parse_earlyprintk+0x1fa>
movl   $0x2580,-0x4(%rbp)
jmp    133f <parse_earlyprintk+0x1ff>
cmpl   $0x0,-0x38(%rbp)
je     1354 <parse_earlyprintk+0x214>
mov    -0x38(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1050 <early_serial_init@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_earlyprintk>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
lea    0xeaf(%rip),%rdi
lea    0x10(%rsp),%rsi
mov    $0x20,%edx
call   1060 <cmdline_find_option@plt>
test   %rax,%rax
jle    129c <parse_earlyprintk+0x15c>
lea    0xe9c(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    $0x6,%ebx
mov    $0x6,%edx
call   1030 <strncmp@plt>
xor    %ecx,%ecx
test   %eax,%eax
cmovne %ecx,%ebx
mov    $0x3f8,%r15d
cmovne %ecx,%r15d
xor    %ebp,%ebp
cmpb   $0x2c,0x10(%rsp,%rbx,1)
sete   %bpl
or     %ebx,%ebp
cmp    $0x7,%ebp
jne    11c4 <parse_earlyprintk+0x84>
lea    0x17(%rsp),%r14
lea    0xe60(%rip),%rsi
mov    %r14,%rdi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     121c <parse_earlyprintk+0xdc>
mov    %ebp,%eax
lea    (%rsp,%rax,1),%rbx
add    $0x10,%rbx
lea    0xe41(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1253 <parse_earlyprintk+0x113>
lea    0xe29(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
lea    0x4(%rbp),%ecx
test   %eax,%eax
cmovne %ebp,%ecx
xor    %eax,%eax
cmpb   $0x31,0x10(%rsp,%rcx,1)
lea    0x1(%rcx),%ebp
sete   %al
lea    0xe06(%rip),%rcx
mov    (%rcx,%rax,4),%r15d
jmp    1253 <parse_earlyprintk+0x113>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
mov    $0x10,%edx
call   1040 <simple_strtoull@plt>
mov    $0x3f8,%r15d
mov    $0x7,%ebp
test   %eax,%eax
je     1253 <parse_earlyprintk+0x113>
mov    0x8(%rsp),%rcx
cmp    %rcx,%r14
je     1253 <parse_earlyprintk+0x113>
lea    0x10(%rsp),%rdx
sub    %edx,%ecx
mov    %ecx,%ebp
mov    %eax,%r15d
movslq %ebp,%rax
xor    %ecx,%ecx
cmpb   $0x2c,0x10(%rsp,%rax,1)
sete   %cl
add    %ecx,%eax
cltq
lea    (%rsp,%rax,1),%rbx
add    $0x10,%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1040 <simple_strtoull@plt>
test   %r15d,%r15d
je     129c <parse_earlyprintk+0x15c>
cmp    0x8(%rsp),%rbx
mov    $0x2580,%ecx
mov    %eax,%esi
cmove  %ecx,%esi
test   %eax,%eax
cmove  %ecx,%esi
mov    %r15d,%edi
call   1050 <early_serial_init@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"earlyprintk\00"
@.str.1 = [7 x i8] c"serial\00"
@.str.2 = [3 x i8] c"0x\00"
@.str.3 = [5 x i8] c"ttyS\00"
@parse_earlyprintk.bases = internal constant [2 x i32] [i32 1016, i32 760]
define void @parse_earlyprintk() {
%1 = alloca i32
%2 = alloca [32 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 9600, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%8 = call i64 @cmdline_find_option(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %7, i32 32)
%9 = icmp sgt i64 %8, 0
br i1 %9, label %10, label %120
10: ; preds = %0
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%12 = call i32 @strncmp(i8* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
%13 = icmp ne i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %10
store i32 1016, i32* %4
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 6
store i32 %16, i32* %3
br label %17
17: ; preds = %14, %10
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 44
br i1 %23, label %24, label %27
24: ; preds = %17
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
br label %27
27: ; preds = %24, %17
%28 = load i32, i32* %3
%29 = icmp eq i32 %28, 7
br i1 %29, label %30, label %61
30: ; preds = %27
%31 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = call i32 @strncmp(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%36 = icmp ne i32 %35, 0
br i1 %36, label %61, label %37
37: ; preds = %30
%38 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%39 = load i32, i32* %3
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = call i32 @simple_strtoull(i8* %41, i8** %5, i32 16)
store i32 %42, i32* %4
%43 = load i32, i32* %4
%44 = icmp eq i32 %43, 0
br i1 %44, label %52, label %45
45: ; preds = %37
%46 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%47 = load i32, i32* %3
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = load i8*, i8** %5
%51 = icmp eq i8* %49, %50
br i1 %51, label %52, label %53
52: ; preds = %45, %37
store i32 1016, i32* %4
br label %60
53: ; preds = %45
%54 = load i8*, i8** %5
%55 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%56 = ptrtoint i8* %54 to i64
%57 = ptrtoint i8* %55 to i64
%58 = sub i64 %56, %57
%59 = trunc i64 %58 to i32
store i32 %59, i32* %3
br label %60
60: ; preds = %53, %52
br label %93
61: ; preds = %30, %27
%62 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%63 = load i32, i32* %3
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %62, i64 %64
%66 = call i32 @strncmp(i8* %65, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%67 = icmp ne i32 %66, 0
br i1 %67, label %92, label %68
68: ; preds = %61
store i32 0, i32* %6
%69 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%70 = load i32, i32* %3
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %69, i64 %71
%73 = call i32 @strncmp(i8* %72, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%74 = icmp ne i32 %73, 0
br i1 %74, label %78, label %75
75: ; preds = %68
%76 = load i32, i32* %3
%77 = add nsw i32 %76, 4
store i32 %77, i32* %3
br label %78
78: ; preds = %75, %68
%79 = load i32, i32* %3
%80 = add nsw i32 %79, 1
store i32 %80, i32* %3
%81 = sext i32 %79 to i64
%82 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 %81
%83 = load i8, i8* %82
%84 = sext i8 %83 to i32
%85 = icmp eq i32 %84, 49
br i1 %85, label %86, label %87
86: ; preds = %78
store i32 1, i32* %6
br label %87
87: ; preds = %86, %78
%88 = load i32, i32* %6
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds [2 x i32], [2 x i32]* @parse_earlyprintk.bases, i64 0, i64 %89
%91 = load i32, i32* %90
store i32 %91, i32* %4
br label %92
92: ; preds = %87, %61
br label %93
93: ; preds = %92, %60
%94 = load i32, i32* %3
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 %95
%97 = load i8, i8* %96
%98 = sext i8 %97 to i32
%99 = icmp eq i32 %98, 44
br i1 %99, label %100, label %103
100: ; preds = %93
%101 = load i32, i32* %3
%102 = add nsw i32 %101, 1
store i32 %102, i32* %3
br label %103
103: ; preds = %100, %93
%104 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%105 = load i32, i32* %3
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds i8, i8* %104, i64 %106
%108 = call i32 @simple_strtoull(i8* %107, i8** %5, i32 0)
store i32 %108, i32* %1
%109 = load i32, i32* %1
%110 = icmp eq i32 %109, 0
br i1 %110, label %118, label %111
111: ; preds = %103
%112 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%113 = load i32, i32* %3
%114 = sext i32 %113 to i64
%115 = getelementptr inbounds i8, i8* %112, i64 %114
%116 = load i8*, i8** %5
%117 = icmp eq i8* %115, %116
br i1 %117, label %118, label %119
118: ; preds = %111, %103
store i32 9600, i32* %1
br label %119
119: ; preds = %118, %111
br label %120
120: ; preds = %119, %0
%121 = load i32, i32* %4
%122 = icmp ne i32 %121, 0
br i1 %122, label %123, label %127
123: ; preds = %120
%124 = load i32, i32* %4
%125 = load i32, i32* %1
%126 = call i32 @early_serial_init(i32 %124, i32 %125)
br label %127
127: ; preds = %123, %120
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"earlyprintk\00"
@.str.1 = [7 x i8] c"serial\00"
@.str.2 = [3 x i8] c"0x\00"
@.str.3 = [5 x i8] c"ttyS\00"
@parse_earlyprintk.bases = internal unnamed_addr constant [2 x i32] [i32 1016, i32 760]
define void @parse_earlyprintk() {
%1 = alloca [32 x i8]
%2 = alloca i8*
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%4 = call i64 @cmdline_find_option(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %3, i32 32)
%5 = icmp sgt i64 %4, 0
br i1 %5, label %6, label %72
6: ; preds = %0
%7 = bitcast i8** %2 to i8*
%8 = call i32 @strncmp(i8* %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
%9 = icmp eq i32 %8, 0
%10 = select i1 %9, i32 6, i32 0
%11 = select i1 %9, i32 1016, i32 0
%12 = zext i32 %10 to i64
%13 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 44
%16 = zext i1 %15 to i32
%17 = or i32 %10, %16
%18 = icmp eq i32 %17, 7
br i1 %18, label %19, label %34
19: ; preds = %6
%20 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 7
%21 = call i32 @strncmp(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %34
23: ; preds = %19
%24 = call i32 @simple_strtoull(i8* %20, i8** %2, i32 16)
%25 = icmp eq i32 %24, 0
br i1 %25, label %52, label %26
26: ; preds = %23
%27 = load i8*, i8** %2
%28 = icmp eq i8* %20, %27
br i1 %28, label %52, label %29
29: ; preds = %26
%30 = ptrtoint i8* %27 to i64
%31 = ptrtoint [32 x i8]* %1 to i64
%32 = sub i64 %30, %31
%33 = trunc i64 %32 to i32
br label %52
34: ; preds = %19, %6
%35 = zext i32 %17 to i64
%36 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 %35
%37 = call i32 @strncmp(i8* %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %52
39: ; preds = %34
%40 = call i32 @strncmp(i8* %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%41 = icmp eq i32 %40, 0
%42 = add nuw nsw i32 %17, 4
%43 = select i1 %41, i32 %42, i32 %17
%44 = add nuw nsw i32 %43, 1
%45 = zext i32 %43 to i64
%46 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 %45
%47 = load i8, i8* %46
%48 = icmp eq i8 %47, 49
%49 = zext i1 %48 to i64
%50 = getelementptr inbounds [2 x i32], [2 x i32]* @parse_earlyprintk.bases, i64 0, i64 %49
%51 = load i32, i32* %50
br label %52
52: ; preds = %29, %39, %34, %26, %23
%53 = phi i32 [ %17, %34 ], [ %44, %39 ], [ %33, %29 ], [ 7, %26 ], [ 7, %23 ]
%54 = phi i32 [ %11, %34 ], [ %51, %39 ], [ %24, %29 ], [ 1016, %26 ], [ 1016, %23 ]
%55 = sext i32 %53 to i64
%56 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 %55
%57 = load i8, i8* %56
%58 = icmp eq i8 %57, 44
%59 = zext i1 %58 to i32
%60 = add nsw i32 %53, %59
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 %61
%63 = call i32 @simple_strtoull(i8* %62, i8** %2, i32 0)
%64 = load i8*, i8** %2
%65 = icmp eq i32 %54, 0
br i1 %65, label %72, label %66
66: ; preds = %52
%67 = icmp eq i32 %63, 0
%68 = icmp eq i8* %62, %64
%69 = select i1 %67, i1 true, i1 %68
%70 = select i1 %69, i32 9600, i32 %63
%71 = call i32 @early_serial_init(i32 %54, i32 %70)
br label %72
72: ; preds = %0, %66, %52
ret void
}