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

/* Variables and functions */
int lux_network_open(char *, int /*<<< orphan*/);
int lux_serial_open(char *);
int /*<<< orphan*/ printf(char *, char const *);
int sscanf(char const *, char *, char *, ...);
int lux_uri_open(const char *uri) {
  char buf[512];
  uint16_t port;
  if (sscanf(uri, "serial://%511s", buf) == 1) {
    return lux_serial_open(buf);
  } else if (sscanf(uri, "udp://%511[^:]:%hu", buf, &port) == 2) {
    return lux_network_open(buf, port);
  }
  printf("[debug] line "
         "33"
         ": "
         "Invalid uri '%s'"
         "\n",
         uri);
  return -1;
}


x86 assembly (clang, -O0):
<lux_uri_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x210(%rbp),%rdx
lea    0xe9f(%rip),%rsi
mov    $0x0,%al
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1185 <lux_uri_open+0x45>
lea    -0x210(%rbp),%rdi
call   1050 <lux_serial_open@plt>
mov    %eax,-0x4(%rbp)
jmp    11e4 <lux_uri_open+0xa4>
mov    -0x10(%rbp),%rdi
lea    -0x210(%rbp),%rdx
lea    0xe78(%rip),%rsi
lea    -0x214(%rbp),%rcx
mov    $0x0,%al
call   1060 <sscanf@plt>
cmp    $0x2,%eax
jne    11c8 <lux_uri_open+0x88>
lea    -0x210(%rbp),%rdi
mov    -0x214(%rbp),%esi
call   1030 <lux_network_open@plt>
mov    %eax,-0x4(%rbp)
jmp    11e4 <lux_uri_open+0xa4>
jmp    11cd <lux_uri_open+0x8d>
mov    -0x10(%rbp),%rsi
lea    0xe4a(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lux_uri_open>:
push   %rbx
sub    $0x210,%rsp
mov    %rdi,%rbx
lea    0xeae(%rip),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    116f <lux_uri_open+0x2f>
lea    0x10(%rsp),%rdi
call   1050 <lux_serial_open@plt>
jmp    11b3 <lux_uri_open+0x73>
lea    0xe99(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <sscanf@plt>
cmp    $0x2,%eax
jne    119f <lux_uri_open+0x5f>
mov    0xc(%rsp),%esi
lea    0x10(%rsp),%rdi
call   1030 <lux_network_open@plt>
jmp    11b3 <lux_uri_open+0x73>
lea    0xe7c(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x210,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"serial://%511s\00"
@.str.1 = [19 x i8] c"udp://%511[^:]:%hu\00"
@.str.2 = [35 x i8] c"[debug] line 33: Invalid uri '%s'\0A\00"
define i32 @lux_uri_open(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [512 x i8]
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%8 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %6, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%12 = call i32 @lux_serial_open(i8* %11)
store i32 %12, i32* %2
br label %26
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%16 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %14, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %15, i32* %5)
%17 = icmp eq i32 %16, 2
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%20 = load i32, i32* %5
%21 = call i32 @lux_network_open(i8* %19, i32 %20)
store i32 %21, i32* %2
br label %26
22: ; preds = %13
br label %23
23: ; preds = %22
%24 = load i8*, i8** %3
%25 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %24)
store i32 -1, i32* %2
br label %26
26: ; preds = %23, %18, %10
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@.str = [15 x i8] c"serial://%511s\00"
@.str.1 = [19 x i8] c"udp://%511[^:]:%hu\00"
@.str.2 = [35 x i8] c"[debug] line 33: Invalid uri '%s'\0A\00"
define i32 @lux_uri_open(i8* %0) {
%2 = alloca [512 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
%6 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %4)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @lux_serial_open(i8* %4)
br label %18
10: ; preds = %1
%11 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %4, i32* %3)
%12 = icmp eq i32 %11, 2
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32, i32* %3
%15 = call i32 @lux_network_open(i8* %4, i32 %14)
br label %18
16: ; preds = %10
%17 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %18
18: ; preds = %16, %13, %8
%19 = phi i32 [ %9, %8 ], [ %15, %13 ], [ -1, %16 ]
ret i32 %19
}