#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_path_cost(char *, char *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int br_cmd_setportprio(char **argv) {
  int cost, err;
  if (sscanf(argv[3], "%i", &cost) != 1) {
    fprintf(stderr, "bad path priority value\n");
    return 1;
  }
  err = br_set_path_cost(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    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xea5(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     1190 <br_cmd_setportprio+0x50>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
lea    0xe86(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f2 <br_cmd_setportprio+0xb2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x14(%rbp),%edx
call   1040 <br_set_path_cost@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11e3 <br_cmd_setportprio+0xa3>
mov    0x2e24(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xe40(%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    %rdi,%rbx
mov    0x18(%rdi),%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_path_cost@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(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32
store i8** %0, i8*** %3
%6 = load i8**, i8*** %3
%7 = getelementptr inbounds i8*, i8** %6, i64 3
%8 = load i8*, i8** %7
%9 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%10 = icmp ne i32 %9, 1
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %2
br label %34
14: ; preds = %1
%15 = load i8**, i8*** %3
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = load i8**, i8*** %3
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
%21 = load i32, i32* %4
%22 = call i32 @br_set_path_cost(i8* %17, i8* %20, i32 %21)
store i32 %22, i32* %5
%23 = load i32, i32* %5
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %14
%26 = load i32, i32* @stderr
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %25, %14
%31 = load i32, i32* %5
%32 = icmp ne i32 %31, 0
%33 = zext i1 %32 to i32
store i32 %33, i32* %2
br label %34
34: ; preds = %30, %11
%35 = load i32, i32* %2
ret i32 %35
}

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(i8** nocapture %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = getelementptr inbounds i8*, i8** %0, i64 3
%5 = load i8*, i8** %4
%6 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%7 = icmp eq i32 %6, 1
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %26
11: ; preds = %1
%12 = getelementptr inbounds i8*, i8** %0, i64 1
%13 = load i8*, i8** %12
%14 = getelementptr inbounds i8*, i8** %0, i64 2
%15 = load i8*, i8** %14
%16 = load i32, i32* %2
%17 = call i32 @br_set_path_cost(i8* %13, i8* %15, i32 %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %11
%20 = load i32, i32* @stderr
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %19, %11
%25 = zext i1 %18 to i32
br label %26
26: ; preds = %24, %8
%27 = phi i32 [ 1, %8 ], [ %25, %24 ]
ret i32 %27
}