#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 */
int /*<<< orphan*/ snprintf(char *, int, char *, int, ...);
int sscanf(char const *, char *, int *, ...);
int strlen(char const *);
int mk_busid(char busid[9], const char *devno) {
  int devno_int, cs1, cs2;
  if (strlen(devno) > 8)
    return -1;
  if (sscanf(devno, "%x.%x.%x", &cs1, &cs2, &devno_int) == 3) {
    snprintf(busid, 9, "%x.%x.%04x", cs1, cs2, devno_int);
    busid[8] = 0;
    return 0;
  }
  if (sscanf(devno, "%x", &devno_int) == 1) {
    snprintf(busid, 9, "0.0.%04x", devno_int);
    busid[8] = 0;
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<mk_busid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x8,%eax
jle    115e <mk_busid+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    120f <mk_busid+0xdf>
mov    -0x18(%rbp),%rdi
lea    0xe97(%rip),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x24(%rbp),%rcx
lea    -0x1c(%rbp),%r8
mov    $0x0,%al
call   1050 <sscanf@plt>
cmp    $0x3,%eax
jne    11bb <mk_busid+0x8b>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
mov    $0x9,%esi
lea    0xe69(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x10(%rbp),%rax
movb   $0x0,0x8(%rax)
movl   $0x0,-0x4(%rbp)
jmp    120f <mk_busid+0xdf>
mov    -0x18(%rbp),%rdi
lea    0xe40(%rip),%rsi
lea    -0x1c(%rbp),%rdx
mov    $0x0,%al
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    1208 <mk_busid+0xd8>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%ecx
mov    $0x9,%esi
lea    0xe27(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x10(%rbp),%rax
movb   $0x0,0x8(%rax)
movl   $0x0,-0x4(%rbp)
jmp    120f <mk_busid+0xdf>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mk_busid>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    $0xffffffff,%ebp
cmp    $0x8,%eax
jg     11db <mk_busid+0xab>
lea    0xea5(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x4(%rsp),%r8
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <sscanf@plt>
cmp    $0x3,%eax
jne    119f <mk_busid+0x6f>
mov    0xc(%rsp),%ecx
mov    0x8(%rsp),%r8d
mov    0x4(%rsp),%r9d
lea    0xe7b(%rip),%rdx
mov    %r14,%rdi
mov    $0x9,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
jmp    11d4 <mk_busid+0xa4>
lea    0xe60(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    11db <mk_busid+0xab>
mov    0x4(%rsp),%ecx
lea    0xe4f(%rip),%rdx
mov    %r14,%rdi
mov    $0x9,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
movb   $0x0,0x8(%r14)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%x.%x.%x\00"
@.str.1 = [11 x i8] c"%x.%x.%04x\00"
@.str.2 = [3 x i8] c"%x\00"
@.str.3 = [9 x i8] c"0.0.%04x\00"
define i32 @mk_busid(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = call i32 @strlen(i8* %9)
%11 = icmp sgt i32 %10, 8
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %36
13: ; preds = %2
%14 = load i8*, i8** %5
%15 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %14, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %7, i32* %8, i32* %6)
%16 = icmp eq i32 %15, 3
br i1 %16, label %17, label %25
17: ; preds = %13
%18 = load i8*, i8** %4
%19 = load i32, i32* %7
%20 = load i32, i32* %8
%21 = load i32, i32* %6
%22 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %18, i32 9, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 %20, i32 %21)
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i64 8
store i8 0, i8* %24
store i32 0, i32* %3
br label %36
25: ; preds = %13
%26 = load i8*, i8** %5
%27 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %35
29: ; preds = %25
%30 = load i8*, i8** %4
%31 = load i32, i32* %6
%32 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %30, i32 9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %31)
%33 = load i8*, i8** %4
%34 = getelementptr inbounds i8, i8* %33, i64 8
store i8 0, i8* %34
store i32 0, i32* %3
br label %36
35: ; preds = %25
store i32 -1, i32* %3
br label %36
36: ; preds = %35, %29, %17, %12
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@.str = [9 x i8] c"%x.%x.%x\00"
@.str.1 = [11 x i8] c"%x.%x.%04x\00"
@.str.2 = [3 x i8] c"%x\00"
@.str.3 = [9 x i8] c"0.0.%04x\00"
define i32 @mk_busid(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = tail call i32 @strlen(i8* %1)
%10 = icmp sgt i32 %9, 8
br i1 %10, label %27, label %11
11: ; preds = %2
%12 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %4, i32* %5, i32* %3)
%13 = icmp eq i32 %12, 3
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = load i32, i32* %4
%16 = load i32, i32* %5
%17 = load i32, i32* %3
%18 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %0, i32 9, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %16, i32 %17)
br label %25
19: ; preds = %11
%20 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = load i32, i32* %3
%24 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %0, i32 9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %14, %22
%26 = getelementptr inbounds i8, i8* %0, i64 8
store i8 0, i8* %26
br label %27
27: ; preds = %25, %19, %2
%28 = phi i32 [ -1, %2 ], [ -1, %19 ], [ 0, %25 ]
ret i32 %28
}