#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 */
typedef int uint16_t;

/* Variables and functions */
int sscanf(char const *, char *, int *, int *, int *);
uint16_t parsePciID(const char *pciid) {
  int bus, dev, fun;
  int ret;
  ret = sscanf(pciid, "%d:%d.%d", &bus, &dev, &fun);
  return (ret == 3) ? ((bus & 0xFF) << 8 | (dev & 0xF) << 4 | (fun & 0xF))
                    : 0xFFFF;
}


x86 assembly (clang, -O0):
<parsePciID>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xed9(%rip),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%r8
call   1030 <sscanf@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x3,-0x18(%rbp)
jne    116b <parsePciID+0x5b>
mov    -0xc(%rbp),%eax
and    $0xff,%eax
shl    $0x8,%eax
mov    -0x10(%rbp),%ecx
and    $0xf,%ecx
shl    $0x4,%ecx
or     %ecx,%eax
mov    -0x14(%rbp),%ecx
and    $0xf,%ecx
or     %ecx,%eax
mov    %eax,-0x1c(%rbp)
jmp    1178 <parsePciID+0x68>
mov    $0xffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1178 <parsePciID+0x68>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parsePciID>:
sub    $0x18,%rsp
lea    0xee5(%rip),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
call   1030 <sscanf@plt>
mov    %eax,%ecx
mov    $0xffff,%eax
cmp    $0x3,%ecx
jne    115a <parsePciID+0x4a>
mov    0x14(%rsp),%eax
shl    $0x8,%eax
movzwl %ax,%eax
mov    0x10(%rsp),%ecx
shl    $0x4,%ecx
movzbl %cl,%ecx
or     %eax,%ecx
mov    0xc(%rsp),%eax
and    $0xf,%eax
or     %ecx,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%d:%d.%d\00"
define i32 @parsePciID(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %3, i32* %4, i32* %5)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp eq i32 %9, 3
br i1 %10, label %11, label %22
11: ; preds = %1
%12 = load i32, i32* %3
%13 = and i32 %12, 255
%14 = shl i32 %13, 8
%15 = load i32, i32* %4
%16 = and i32 %15, 15
%17 = shl i32 %16, 4
%18 = or i32 %14, %17
%19 = load i32, i32* %5
%20 = and i32 %19, 15
%21 = or i32 %18, %20
br label %23
22: ; preds = %1
br label %23
23: ; preds = %22, %11
%24 = phi i32 [ %21, %11 ], [ 65535, %22 ]
ret i32 %24
}

LLVM IR (-O2):
@.str = [9 x i8] c"%d:%d.%d\00"
define i32 @parsePciID(i8* nocapture %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3, i32* %4)
%9 = icmp eq i32 %8, 3
br i1 %9, label %10, label %21
10: ; preds = %1
%11 = load i32, i32* %2
%12 = shl i32 %11, 8
%13 = and i32 %12, 65280
%14 = load i32, i32* %3
%15 = shl i32 %14, 4
%16 = and i32 %15, 240
%17 = or i32 %16, %13
%18 = load i32, i32* %4
%19 = and i32 %18, 15
%20 = or i32 %17, %19
br label %21
21: ; preds = %1, %10
%22 = phi i32 [ %20, %10 ], [ 65535, %1 ]
ret i32 %22
}