#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*/ errlog(char *);
int /*<<< orphan*/ goodlog(char *);
int is_switch_ok(int);
int send_upgrade_cmd(int);
int bridge_switch(int fd) {
  int ret = 0;
  ret = send_upgrade_cmd(fd);
  if (ret) {
    errlog("\n>>> send_upgrade_cmd failed\n\n");
    return -2;
  }
  goodlog("\n>>> 2. send upgrade command to bridge success.\n\n");
  ret = is_switch_ok(fd);
  if (ret) {
    errlog("\n>>> switch check failed.\n\n");
    return -3;
  }
  goodlog("\n>>> 3. switch check success\n\n");
  return ret;
}


x86 assembly (clang, -O0):
<bridge_switch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <send_upgrade_cmd@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     117f <bridge_switch+0x3f>
lea    0xe92(%rip),%rdi
call   1030 <errlog@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11ca <bridge_switch+0x8a>
lea    0xe99(%rip),%rdi
call   1060 <goodlog@plt>
mov    -0x8(%rbp),%edi
call   1050 <is_switch_ok@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11b8 <bridge_switch+0x78>
lea    0xeaa(%rip),%rdi
call   1030 <errlog@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    11ca <bridge_switch+0x8a>
lea    0xeae(%rip),%rdi
call   1060 <goodlog@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bridge_switch>:
push   %rbx
mov    %edi,%ebx
call   1040 <send_upgrade_cmd@plt>
test   %eax,%eax
je     115f <bridge_switch+0x1f>
lea    0xead(%rip),%rdi
call   1030 <errlog@plt>
mov    $0xfffffffe,%eax
pop    %rbx
ret
lea    0xeb9(%rip),%rdi
call   1060 <goodlog@plt>
mov    %ebx,%edi
call   1050 <is_switch_ok@plt>
test   %eax,%eax
je     1189 <bridge_switch+0x49>
lea    0xed4(%rip),%rdi
call   1030 <errlog@plt>
mov    $0xfffffffd,%eax
pop    %rbx
ret
lea    0xedd(%rip),%rdi
call   1060 <goodlog@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [31 x i8] c"\0A>>> send_upgrade_cmd failed\0A\0A\00"
@.str.1 = [50 x i8] c"\0A>>> 2. send upgrade command to bridge success.\0A\0A\00"
@.str.2 = [28 x i8] c"\0A>>> switch check failed.\0A\0A\00"
@.str.3 = [31 x i8] c"\0A>>> 3. switch check success\0A\0A\00"
define i32 @bridge_switch(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %4
%5 = load i32, i32* %3
%6 = call i32 @send_upgrade_cmd(i32 %5)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @errlog(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 -2, i32* %2
br label %22
11: ; preds = %1
%12 = call i32 @goodlog(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* %3
%14 = call i32 @is_switch_ok(i32 %13)
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = call i32 @errlog(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
store i32 -3, i32* %2
br label %22
19: ; preds = %11
%20 = call i32 @goodlog(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%21 = load i32, i32* %4
store i32 %21, i32* %2
br label %22
22: ; preds = %19, %17, %9
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@.str = [31 x i8] c"\0A>>> send_upgrade_cmd failed\0A\0A\00"
@.str.1 = [50 x i8] c"\0A>>> 2. send upgrade command to bridge success.\0A\0A\00"
@.str.2 = [28 x i8] c"\0A>>> switch check failed.\0A\0A\00"
@.str.3 = [31 x i8] c"\0A>>> 3. switch check success\0A\0A\00"
define i32 @bridge_switch(i32 %0) {
%2 = tail call i32 @send_upgrade_cmd(i32 %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i32 @errlog(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %14
6: ; preds = %1
%7 = tail call i32 @goodlog(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @is_switch_ok(i32 %0)
%9 = icmp eq i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = tail call i32 @errlog(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %14
12: ; preds = %6
%13 = tail call i32 @goodlog(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %14
14: ; preds = %12, %10, %4
%15 = phi i32 [ -2, %4 ], [ -3, %10 ], [ 0, %12 ]
ret i32 %15
}