#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;
      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    131a <parse_earlyprintk+0x1da>
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    12bb <parse_earlyprintk+0x17b>
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    12b6 <parse_earlyprintk+0x176>
movl   $0x0,-0x44(%rbp)
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    12a5 <parse_earlyprintk+0x165>
movl   $0x1,-0x44(%rbp)
movslq -0x44(%rbp),%rcx
lea    0xd6c(%rip),%rax
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x38(%rbp)
jmp    12bb <parse_earlyprintk+0x17b>
movslq -0x34(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%eax
cmp    $0x2c,%eax
jne    12d6 <parse_earlyprintk+0x196>
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     130e <parse_earlyprintk+0x1ce>
lea    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
add    %rcx,%rax
cmp    -0x40(%rbp),%rax
jne    1315 <parse_earlyprintk+0x1d5>
movl   $0x2580,-0x4(%rbp)
jmp    131a <parse_earlyprintk+0x1da>
cmpl   $0x0,-0x38(%rbp)
je     132f <parse_earlyprintk+0x1ef>
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   %r12
push   %rbx
sub    $0x30,%rsp
lea    0xead(%rip),%rdi
lea    0x10(%rsp),%rsi
mov    $0x20,%edx
call   1060 <cmdline_find_option@plt>
test   %rax,%rax
jle    1285 <parse_earlyprintk+0x145>
lea    0xe9a(%rip),%rsi
lea    0x10(%rsp),%r14
mov    $0x6,%ebp
mov    %r14,%rdi
mov    $0x6,%edx
call   1030 <strncmp@plt>
xor    %ecx,%ecx
test   %eax,%eax
cmovne %ecx,%ebp
mov    $0x3f8,%r12d
cmovne %ecx,%r12d
xor    %ebx,%ebx
cmpb   $0x2c,0x10(%rsp,%rbp,1)
sete   %bl
or     %rbp,%rbx
cmp    $0x7,%ebx
jne    11c9 <parse_earlyprintk+0x89>
lea    0x17(%rsp),%r15
lea    0xe5b(%rip),%rsi
mov    %r15,%rdi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1205 <parse_earlyprintk+0xc5>
mov    %ebx,%eax
lea    (%rsp,%rax,1),%rdi
add    $0x10,%rdi
lea    0xe3c(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    123c <parse_earlyprintk+0xfc>
xor    %eax,%eax
cmpb   $0x31,0x4(%rbx,%r14,1)
lea    0x5(%rbx),%ecx
sete   %al
lea    0xe1f(%rip),%rdx
mov    (%rdx,%rax,4),%r12d
mov    %ecx,%ebx
jmp    123c <parse_earlyprintk+0xfc>
lea    0x8(%rsp),%rsi
mov    %r15,%rdi
mov    $0x10,%edx
call   1040 <simple_strtoull@plt>
mov    $0x3f8,%r12d
mov    $0x7,%ebx
test   %eax,%eax
je     123c <parse_earlyprintk+0xfc>
mov    0x8(%rsp),%rcx
cmp    %rcx,%r15
je     123c <parse_earlyprintk+0xfc>
lea    0x10(%rsp),%rdx
sub    %edx,%ecx
mov    %ecx,%ebx
mov    %eax,%r12d
movslq %ebx,%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   %r12d,%r12d
je     1285 <parse_earlyprintk+0x145>
cmp    0x8(%rsp),%rbx
mov    $0x2580,%ecx
mov    %eax,%esi
cmove  %ecx,%esi
test   %eax,%eax
cmove  %ecx,%esi
mov    %r12d,%edi
call   1050 <early_serial_init@plt>
add    $0x30,%rsp
pop    %rbx
pop    %r12
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 %112
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 %85
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 %84, label %68
68: ; preds = %61
store i32 0, i32* %6
%69 = load i32, i32* %3
%70 = add nsw i32 %69, 4
store i32 %70, i32* %3
%71 = load i32, i32* %3
%72 = add nsw i32 %71, 1
store i32 %72, i32* %3
%73 = sext i32 %71 to i64
%74 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 %73
%75 = load i8, i8* %74
%76 = sext i8 %75 to i32
%77 = icmp eq i32 %76, 49
br i1 %77, label %78, label %79
78: ; preds = %68
store i32 1, i32* %6
br label %79
79: ; preds = %78, %68
%80 = load i32, i32* %6
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [2 x i32], [2 x i32]* @parse_earlyprintk.bases, i64 0, i64 %81
%83 = load i32, i32* %82
store i32 %83, i32* %4
br label %84
84: ; preds = %79, %61
br label %85
85: ; preds = %84, %60
%86 = load i32, i32* %3
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 %87
%89 = load i8, i8* %88
%90 = sext i8 %89 to i32
%91 = icmp eq i32 %90, 44
br i1 %91, label %92, label %95
92: ; preds = %85
%93 = load i32, i32* %3
%94 = add nsw i32 %93, 1
store i32 %94, i32* %3
br label %95
95: ; preds = %92, %85
%96 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%97 = load i32, i32* %3
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds i8, i8* %96, i64 %98
%100 = call i32 @simple_strtoull(i8* %99, i8** %5, i32 0)
store i32 %100, i32* %1
%101 = load i32, i32* %1
%102 = icmp eq i32 %101, 0
br i1 %102, label %110, label %103
103: ; preds = %95
%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 = load i8*, i8** %5
%109 = icmp eq i8* %107, %108
br i1 %109, label %110, label %111
110: ; preds = %103, %95
store i32 9600, i32* %1
br label %111
111: ; preds = %110, %103
br label %112
112: ; preds = %111, %0
%113 = load i32, i32* %4
%114 = icmp ne i32 %113, 0
br i1 %114, label %115, label %119
115: ; preds = %112
%116 = load i32, i32* %4
%117 = load i32, i32* %1
%118 = call i32 @early_serial_init(i32 %116, i32 %117)
br label %119
119: ; preds = %115, %112
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 %69
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 %49, label %26
26: ; preds = %23
%27 = load i8*, i8** %2
%28 = icmp eq i8* %20, %27
br i1 %28, label %49, 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 %49
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 %49
39: ; preds = %34
%40 = add nuw nsw i32 %17, 4
%41 = add nuw nsw i32 %17, 5
%42 = zext i32 %40 to i64
%43 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = icmp eq i8 %44, 49
%46 = zext i1 %45 to i64
%47 = getelementptr inbounds [2 x i32], [2 x i32]* @parse_earlyprintk.bases, i64 0, i64 %46
%48 = load i32, i32* %47
br label %49
49: ; preds = %29, %39, %34, %26, %23
%50 = phi i32 [ %17, %34 ], [ %41, %39 ], [ %33, %29 ], [ 7, %26 ], [ 7, %23 ]
%51 = phi i32 [ %11, %34 ], [ %48, %39 ], [ %24, %29 ], [ 1016, %26 ], [ 1016, %23 ]
%52 = sext i32 %50 to i64
%53 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 %52
%54 = load i8, i8* %53
%55 = icmp eq i8 %54, 44
%56 = zext i1 %55 to i32
%57 = add nsw i32 %50, %56
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 %58
%60 = call i32 @simple_strtoull(i8* %59, i8** %2, i32 0)
%61 = load i8*, i8** %2
%62 = icmp eq i32 %51, 0
br i1 %62, label %69, label %63
63: ; preds = %49
%64 = icmp eq i32 %60, 0
%65 = icmp eq i8* %59, %61
%66 = select i1 %64, i1 true, i1 %65
%67 = select i1 %66, i32 9600, i32 %60
%68 = call i32 @early_serial_init(i32 %51, i32 %67)
br label %69
69: ; preds = %0, %63, %49
ret void
}