#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 probe_baud(int);
int simple_strtoull(char *, char **, int /*<<< orphan*/);
int /*<<< orphan*/ strncmp(char *, char *, int);
void parse_console_uart8250(void) {
  char optstr[64], *options;
  int baud = 9600;
  int port = 0;
  if (cmdline_find_option("console", optstr, sizeof optstr) <= 0)
    return;
  options = optstr;
  if (!strncmp(options, "uart8250,io,", 12))
    port = simple_strtoull(options + 12, &options, 0);
  else if (!strncmp(options, "uart,io,", 8))
    port = simple_strtoull(options + 8, &options, 0);
  else
    return;
  if (options && (options[0] == ','))
    baud = simple_strtoull(options + 1, &options, 0);
  else
    baud = probe_baud(port);
  if (port)
    early_serial_init(port, baud);
}


x86 assembly (clang, -O0):
<parse_console_uart8250>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x2580,-0x4c(%rbp)
movl   $0x0,-0x50(%rbp)
lea    -0x40(%rbp),%rsi
lea    0xe8f(%rip),%rdi
mov    $0x40,%edx
call   1070 <cmdline_find_option@plt>
cmp    $0x0,%rax
jg     118a <parse_console_uart8250+0x3a>
jmp    1264 <parse_console_uart8250+0x114>
lea    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
lea    0xe6b(%rip),%rsi
mov    $0xc,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11cb <parse_console_uart8250+0x7b>
mov    -0x48(%rbp),%rdi
add    $0xc,%rdi
lea    -0x48(%rbp),%rsi
xor    %edx,%edx
call   1040 <simple_strtoull@plt>
mov    %eax,-0x50(%rbp)
jmp    120e <parse_console_uart8250+0xbe>
mov    -0x48(%rbp),%rdi
lea    0xe3f(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1204 <parse_console_uart8250+0xb4>
mov    -0x48(%rbp),%rdi
add    $0x8,%rdi
lea    -0x48(%rbp),%rsi
xor    %edx,%edx
call   1040 <simple_strtoull@plt>
mov    %eax,-0x50(%rbp)
jmp    1209 <parse_console_uart8250+0xb9>
jmp    1264 <parse_console_uart8250+0x114>
jmp    120e <parse_console_uart8250+0xbe>
cmpq   $0x0,-0x48(%rbp)
je     1244 <parse_console_uart8250+0xf4>
mov    -0x48(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2c,%eax
jne    1244 <parse_console_uart8250+0xf4>
mov    -0x48(%rbp),%rdi
add    $0x1,%rdi
lea    -0x48(%rbp),%rsi
xor    %edx,%edx
call   1040 <simple_strtoull@plt>
mov    %eax,-0x4c(%rbp)
jmp    124f <parse_console_uart8250+0xff>
mov    -0x50(%rbp),%edi
call   1060 <probe_baud@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x50(%rbp)
je     1264 <parse_console_uart8250+0x114>
mov    -0x50(%rbp),%edi
mov    -0x4c(%rbp),%esi
call   1050 <early_serial_init@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_console_uart8250>:
push   %rbx
sub    $0x50,%rsp
lea    0xea4(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x40,%edx
call   1070 <cmdline_find_option@plt>
test   %rax,%rax
jle    1209 <parse_console_uart8250+0xb9>
mov    %rbx,0x8(%rsp)
lea    0xe85(%rip),%rsi
mov    %rbx,%rdi
mov    $0xc,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     11b5 <parse_console_uart8250+0x65>
lea    0xe7a(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    $0x8,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1209 <parse_console_uart8250+0xb9>
mov    $0x8,%eax
jmp    11ba <parse_console_uart8250+0x6a>
mov    $0xc,%eax
lea    (%rsp,%rax,1),%rdi
add    $0x10,%rdi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1040 <simple_strtoull@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     11f5 <parse_console_uart8250+0xa5>
cmpb   $0x2c,(%rdi)
jne    11f5 <parse_console_uart8250+0xa5>
add    $0x1,%rdi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1040 <simple_strtoull@plt>
test   %ebx,%ebx
jne    1200 <parse_console_uart8250+0xb0>
jmp    1209 <parse_console_uart8250+0xb9>
mov    %ebx,%edi
call   1060 <probe_baud@plt>
test   %ebx,%ebx
je     1209 <parse_console_uart8250+0xb9>
mov    %ebx,%edi
mov    %eax,%esi
call   1050 <early_serial_init@plt>
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"console\00"
@.str.1 = [13 x i8] c"uart8250,io,\00"
@.str.2 = [9 x i8] c"uart,io,\00"
define void @parse_console_uart8250() {
%1 = alloca [64 x i8]
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i32 9600, i32* %3
store i32 0, i32* %4
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%6 = call i64 @cmdline_find_option(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %5, i32 64)
%7 = icmp sle i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %0
br label %51
9: ; preds = %0
%10 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
store i8* %10, i8** %2
%11 = load i8*, i8** %2
%12 = call i32 @strncmp(i8* %11, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 12)
%13 = icmp ne i32 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %9
%15 = load i8*, i8** %2
%16 = getelementptr inbounds i8, i8* %15, i64 12
%17 = call i32 @simple_strtoull(i8* %16, i8** %2, i32 0)
store i32 %17, i32* %4
br label %28
18: ; preds = %9
%19 = load i8*, i8** %2
%20 = call i32 @strncmp(i8* %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 8)
%21 = icmp ne i32 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = load i8*, i8** %2
%24 = getelementptr inbounds i8, i8* %23, i64 8
%25 = call i32 @simple_strtoull(i8* %24, i8** %2, i32 0)
store i32 %25, i32* %4
br label %27
26: ; preds = %18
br label %51
27: ; preds = %22
br label %28
28: ; preds = %27, %14
%29 = load i8*, i8** %2
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %41
31: ; preds = %28
%32 = load i8*, i8** %2
%33 = getelementptr inbounds i8, i8* %32, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 44
br i1 %36, label %37, label %41
37: ; preds = %31
%38 = load i8*, i8** %2
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = call i32 @simple_strtoull(i8* %39, i8** %2, i32 0)
store i32 %40, i32* %3
br label %44
41: ; preds = %31, %28
%42 = load i32, i32* %4
%43 = call i32 @probe_baud(i32 %42)
store i32 %43, i32* %3
br label %44
44: ; preds = %41, %37
%45 = load i32, i32* %4
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %44
%48 = load i32, i32* %4
%49 = load i32, i32* %3
%50 = call i32 @early_serial_init(i32 %48, i32 %49)
br label %51
51: ; preds = %8, %26, %47, %44
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"console\00"
@.str.1 = [13 x i8] c"uart8250,io,\00"
@.str.2 = [9 x i8] c"uart,io,\00"
define void @parse_console_uart8250() {
%1 = alloca [64 x i8]
%2 = alloca i8*
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%4 = bitcast i8** %2 to i8*
%5 = call i64 @cmdline_find_option(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %3, i32 64)
%6 = icmp slt i64 %5, 1
br i1 %6, label %32, label %7
7: ; preds = %0
store i8* %3, i8** %2
%8 = call i32 @strncmp(i8* %3, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 12)
%9 = icmp eq i32 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = call i32 @strncmp(i8* %3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 8)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %32
13: ; preds = %10, %7
%14 = phi i64 [ 12, %7 ], [ 8, %10 ]
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 %14
%16 = call i32 @simple_strtoull(i8* %15, i8** %2, i32 0)
%17 = load i8*, i8** %2
%18 = icmp eq i8* %17, null
br i1 %18, label %25, label %19
19: ; preds = %13
%20 = load i8, i8* %17
%21 = icmp eq i8 %20, 44
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = getelementptr inbounds i8, i8* %17, i64 1
%24 = call i32 @simple_strtoull(i8* %23, i8** %2, i32 0)
br label %27
25: ; preds = %19, %13
%26 = call i32 @probe_baud(i32 %16)
br label %27
27: ; preds = %25, %22
%28 = phi i32 [ %24, %22 ], [ %26, %25 ]
%29 = icmp eq i32 %16, 0
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = call i32 @early_serial_init(i32 %16, i32 %28)
br label %32
32: ; preds = %27, %30, %10, %0
ret void
}