#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 */
struct loc {
  int dummy;
};

/* Variables and functions */
int EINVAL;
int loc_segments(char *, char **, char **, char **);
int phytool_parse_loc_segs(char *, char *, char *, struct loc *);
int phytool_parse_loc(char *text, struct loc *loc, int strict) {
  char *dev = NULL, *addr = NULL, *reg = NULL;
  int segs;
  segs = loc_segments(text, &dev, &addr, &reg);
  if (segs < (strict ? 3 : 2))
    return -EINVAL;
  return phytool_parse_loc_segs(dev, addr, reg, loc);
}


x86 assembly (clang, -O0):
<phytool_parse_loc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   1030 <loc_segments@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    -0x1c(%rbp),%esi
mov    $0x2,%ecx
mov    $0x3,%edx
cmp    $0x0,%esi
cmovne %edx,%ecx
cmp    %ecx,%eax
jge    1194 <phytool_parse_loc+0x74>
xor    %eax,%eax
mov    0x2e56(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11ac <phytool_parse_loc+0x8c>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1040 <phytool_parse_loc_segs@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<phytool_parse_loc>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,(%rsp)
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %rsp,%rcx
call   1030 <loc_segments@plt>
cmp    $0x1,%ebp
mov    $0x3,%ecx
sbb    $0x0,%ecx
cmp    %ecx,%eax
jge    1173 <phytool_parse_loc+0x53>
mov    0x2e73(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
jmp    1189 <phytool_parse_loc+0x69>
mov    0x10(%rsp),%rdi
mov    0x8(%rsp),%rsi
mov    (%rsp),%rdx
mov    %rbx,%rcx
call   1040 <phytool_parse_loc_segs@plt>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.loc = type { i32 }
@EINVAL = global i32 0
define i32 @phytool_parse_loc(i8* %0, %struct.loc* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca %struct.loc*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %5
store %struct.loc* %1, %struct.loc** %6
store i32 %2, i32* %7
store i8* null, i8** %8
store i8* null, i8** %9
store i8* null, i8** %10
%12 = load i8*, i8** %5
%13 = call i32 @loc_segments(i8* %12, i8** %8, i8** %9, i8** %10)
store i32 %13, i32* %11
%14 = load i32, i32* %11
%15 = load i32, i32* %7
%16 = icmp ne i32 %15, 0
%17 = zext i1 %16 to i64
%18 = select i1 %16, i32 3, i32 2
%19 = icmp slt i32 %14, %18
br i1 %19, label %20, label %23
20: ; preds = %3
%21 = load i32, i32* @EINVAL
%22 = sub nsw i32 0, %21
store i32 %22, i32* %4
br label %29
23: ; preds = %3
%24 = load i8*, i8** %8
%25 = load i8*, i8** %9
%26 = load i8*, i8** %10
%27 = load %struct.loc*, %struct.loc** %6
%28 = call i32 @phytool_parse_loc_segs(i8* %24, i8* %25, i8* %26, %struct.loc* %27)
store i32 %28, i32* %4
br label %29
29: ; preds = %23, %20
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
%struct.loc = type { i32 }
@EINVAL = global i32 0
define i32 @phytool_parse_loc(i8* %0, %struct.loc* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%8 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%9 = bitcast i8** %6 to i8*
store i8* null, i8** %6
%10 = call i32 @loc_segments(i8* %0, i8** %4, i8** %5, i8** %6)
%11 = icmp eq i32 %2, 0
%12 = select i1 %11, i32 2, i32 3
%13 = icmp slt i32 %10, %12
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = load i32, i32* @EINVAL
%16 = sub nsw i32 0, %15
br label %22
17: ; preds = %3
%18 = load i8*, i8** %4
%19 = load i8*, i8** %5
%20 = load i8*, i8** %6
%21 = call i32 @phytool_parse_loc_segs(i8* %18, i8* %19, i8* %20, %struct.loc* %1)
br label %22
22: ; preds = %17, %14
%23 = phi i32 [ %16, %14 ], [ %21, %17 ]
ret i32 %23
}