#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 br_set_port_priority(char *const, char *const, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int sscanf(char *const, char *, int *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int br_cmd_setportprio(int argc, char *const *argv) {
  int cost, err;
  if (sscanf(argv[3], "%i", &cost) != 1) {
    fprintf(stderr, "bad path priority value\n");
    return 1;
  }
  err = br_set_port_priority(argv[1], argv[2], cost);
  if (err)
    fprintf(stderr, "set port priority failed: %s\n", strerror(errno));
  return err != 0;
}


x86 assembly (clang, -O0):
<br_cmd_setportprio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xea2(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     1193 <br_cmd_setportprio+0x53>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f5 <br_cmd_setportprio+0xb5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x14(%rbp),%edx
call   1040 <br_set_port_priority@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11e6 <br_cmd_setportprio+0xa6>
mov    0x2e21(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xe3d(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
cmpl   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<br_cmd_setportprio>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x18(%rsi),%rdi
lea    0xeaf(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    11aa <br_cmd_setportprio+0x6a>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
mov    0x4(%rsp),%edx
call   1040 <br_set_port_priority@plt>
mov    %eax,%ebx
test   %eax,%eax
je     11a1 <br_cmd_setportprio+0x61>
mov    0x2e62(%rip),%rax
mov    (%rax),%ebp
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe87(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
xor    %eax,%eax
test   %ebx,%ebx
setne  %al
jmp    11c6 <br_cmd_setportprio+0x86>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
lea    0xe49(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%i\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"bad path priority value\0A\00"
@.str.2 = [30 x i8] c"set port priority failed: %s\0A\00"
@errno = global i32 0
define i32 @br_cmd_setportprio(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 3
%10 = load i8*, i8** %9
%11 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%12 = icmp ne i32 %11, 1
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %36
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = load i32, i32* %6
%24 = call i32 @br_set_port_priority(i8* %19, i8* %22, i32 %23)
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %16
%28 = load i32, i32* @stderr
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %30)
br label %32
32: ; preds = %27, %16
%33 = load i32, i32* %7
%34 = icmp ne i32 %33, 0
%35 = zext i1 %34 to i32
store i32 %35, i32* %3
br label %36
36: ; preds = %32, %13
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@.str = [3 x i8] c"%i\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"bad path priority value\0A\00"
@.str.2 = [30 x i8] c"set port priority failed: %s\0A\00"
@errno = global i32 0
define i32 @br_cmd_setportprio(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = getelementptr inbounds i8*, i8** %1, i64 3
%6 = load i8*, i8** %5
%7 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%8 = icmp eq i32 %7, 1
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %27
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = load i32, i32* %3
%18 = call i32 @br_set_port_priority(i8* %14, i8* %16, i32 %17)
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %12
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %20, %12
%26 = zext i1 %19 to i32
br label %27
27: ; preds = %25, %9
%28 = phi i32 [ 1, %9 ], [ %26, %25 ]
ret i32 %28
}