#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*/ uint8_t;
typedef int uint32_t;
typedef int /*<<< orphan*/ uint16_t;
struct can_frame {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
scalar_t__ await_sdo_confirmation(struct can_frame *, int /*<<< orphan*/);
scalar_t__ c(struct can_frame);
int data16(struct can_frame);
int data24(struct can_frame);
int data32(struct can_frame);
int data8(struct can_frame);
int /*<<< orphan*/ dump_data_binary(struct can_frame, int);
int e(struct can_frame);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ is_abort_transfer_request(struct can_frame, int /*<<< orphan*/,
                                     int /*<<< orphan*/);
scalar_t__ is_upload_initiate_response(struct can_frame, int /*<<< orphan*/,
                                       int /*<<< orphan*/);
scalar_t__ is_upload_segment_response(struct can_frame);
int n(struct can_frame);
int /*<<< orphan*/ print_sdo_error(int);
int /*<<< orphan*/ printf(char *, ...);
int s(struct can_frame);
int /*<<< orphan*/ sdo_abort_transfer(int /*<<< orphan*/, int /*<<< orphan*/,
                                      int /*<<< orphan*/, int);
int /*<<< orphan*/ sdo_upload_initiate_request(int /*<<< orphan*/,
                                               int /*<<< orphan*/,
                                               int /*<<< orphan*/);
int /*<<< orphan*/ sdo_upload_segment_request(int /*<<< orphan*/, scalar_t__);
int /*<<< orphan*/ socketcan_close();
int /*<<< orphan*/ socketcan_open(char *);
int /*<<< orphan*/ stderr;
scalar_t__ t(struct can_frame);
void sdo_upload(char *can_interface, uint8_t node_id, uint16_t index,
                uint8_t subindex) {
  socketcan_open(can_interface);
  sdo_upload_initiate_request(node_id, index, subindex);
  struct can_frame confirmation;
  while (await_sdo_confirmation(&confirmation, node_id)) {
    if (is_upload_initiate_response(confirmation, index, subindex)) {
      if (e(confirmation) == 0 && s(confirmation) == 1) {
        sdo_upload_segment_request(node_id, 0);
        continue;
      } else if (e(confirmation) == 1 && s(confirmation) == 1) {
        switch (n(confirmation)) {
        case 0:
          printf("0x%X", data32(confirmation));
          break;
        case 1:
          printf("0x%X", data24(confirmation));
          break;
        case 2:
          printf("0x%X", data16(confirmation));
          break;
        case 3:
          printf("0x%X", data8(confirmation));
          break;
        }
      } else if (e(confirmation) == 1 && s(confirmation) == 0) {
        printf("0x%X", data32(confirmation));
      }
      printf("\n");
      socketcan_close();
      exit(EXIT_SUCCESS);
    } else if (is_upload_segment_response(confirmation)) {
      dump_data_binary(confirmation, 1);
      if (c(confirmation) == 0) {
        sdo_upload_segment_request(node_id, t(confirmation) + 1);
      } else {
        printf("\n");
        socketcan_close();
        exit(EXIT_SUCCESS);
      }
    } else if (is_abort_transfer_request(confirmation, index, subindex)) {
      uint32_t error_code = data32(confirmation);
      print_sdo_error(error_code);
      socketcan_close();
      exit(EXIT_FAILURE);
    }
  }
  sdo_abort_transfer(node_id, index, subindex, (0x05040000ul));
  fprintf(stderr, "SDO timeout\n");
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<sdo_upload>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   10c0 <socketcan_open@plt>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   10d0 <sdo_upload_initiate_request@plt>
mov    -0xc(%rbp),%esi
lea    -0x18(%rbp),%rdi
call   1140 <await_sdo_confirmation@plt>
cmp    $0x0,%rax
je     14ef <sdo_upload+0x27f>
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%edi
call   1170 <is_upload_initiate_response@plt>
cmp    $0x0,%rax
je     1425 <sdo_upload+0x1b5>
mov    -0x18(%rbp),%edi
call   10f0 <e@plt>
cmp    $0x0,%eax
jne    12fd <sdo_upload+0x8d>
mov    -0x18(%rbp),%edi
call   1120 <s@plt>
cmp    $0x1,%eax
jne    12fd <sdo_upload+0x8d>
mov    -0xc(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1150 <sdo_upload_segment_request@plt>
jmp    129c <sdo_upload+0x2c>
mov    -0x18(%rbp),%edi
call   10f0 <e@plt>
cmp    $0x1,%eax
jne    13be <sdo_upload+0x14e>
mov    -0x18(%rbp),%edi
call   1120 <s@plt>
cmp    $0x1,%eax
jne    13be <sdo_upload+0x14e>
mov    -0x18(%rbp),%edi
call   1050 <n@plt>
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x3,%eax
ja     13b9 <sdo_upload+0x149>
mov    -0x28(%rbp),%rax
lea    0xcbf(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%edi
call   1030 <data32@plt>
mov    %eax,%esi
lea    0xcb5(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    13b9 <sdo_upload+0x149>
mov    -0x18(%rbp),%edi
call   1100 <data24@plt>
mov    %eax,%esi
lea    0xc98(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    13b9 <sdo_upload+0x149>
mov    -0x18(%rbp),%edi
call   1080 <data16@plt>
mov    %eax,%esi
lea    0xc7b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    13b9 <sdo_upload+0x149>
mov    -0x18(%rbp),%edi
call   1130 <data8@plt>
mov    %eax,%esi
lea    0xc5e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    13fd <sdo_upload+0x18d>
mov    -0x18(%rbp),%edi
call   10f0 <e@plt>
cmp    $0x1,%eax
jne    13f8 <sdo_upload+0x188>
mov    -0x18(%rbp),%edi
call   1120 <s@plt>
cmp    $0x0,%eax
jne    13f8 <sdo_upload+0x188>
mov    -0x18(%rbp),%edi
call   1030 <data32@plt>
mov    %eax,%esi
lea    0xc1f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    13fd <sdo_upload+0x18d>
jmp    1402 <sdo_upload+0x192>
lea    0xc17(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   1090 <socketcan_close@plt>
mov    0x2bb2(%rip),%rax
mov    (%rax),%edi
call   1160 <exit@plt>
mov    -0x18(%rbp),%edi
call   1040 <is_upload_segment_response@plt>
cmp    $0x0,%rax
je     14a0 <sdo_upload+0x230>
mov    -0x18(%rbp),%edi
mov    $0x1,%esi
call   1180 <dump_data_binary@plt>
mov    -0x18(%rbp),%edi
call   1110 <c@plt>
cmp    $0x0,%rax
jne    1478 <sdo_upload+0x208>
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%edi
call   1060 <t@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rsi
add    $0x1,%rsi
call   1150 <sdo_upload_segment_request@plt>
jmp    149b <sdo_upload+0x22b>
lea    0xba1(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   1090 <socketcan_close@plt>
mov    0x2b3c(%rip),%rax
mov    (%rax),%edi
call   1160 <exit@plt>
jmp    14e5 <sdo_upload+0x275>
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%edi
call   10b0 <is_abort_transfer_request@plt>
cmp    $0x0,%rax
je     14e0 <sdo_upload+0x270>
mov    -0x18(%rbp),%edi
call   1030 <data32@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   10e0 <print_sdo_error@plt>
mov    $0x0,%al
call   1090 <socketcan_close@plt>
mov    0x2aff(%rip),%rax
mov    (%rax),%edi
call   1160 <exit@plt>
jmp    14e5 <sdo_upload+0x275>
jmp    14ea <sdo_upload+0x27a>
jmp    129c <sdo_upload+0x2c>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    $0x5040000,%ecx
call   1190 <sdo_abort_transfer@plt>
mov    0x2ad7(%rip),%rax
mov    (%rax),%edi
lea    0xb03(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2aba(%rip),%rax
mov    (%rax),%edi
call   1160 <exit@plt>

x86 assembly (clang, -O2):
<sdo_upload>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %esi,%ebx
call   10d0 <socketcan_open@plt>
mov    %ebx,%edi
mov    %ebp,%esi
mov    %r14d,%edx
call   10e0 <sdo_upload_initiate_request@plt>
mov    %rsp,%rdi
mov    %ebx,%esi
call   1150 <await_sdo_confirmation@plt>
test   %rax,%rax
jne    12e2 <sdo_upload+0x62>
mov    %ebx,%edi
mov    %ebp,%esi
mov    %r14d,%edx
mov    $0x5040000,%ecx
call   11a0 <sdo_abort_transfer@plt>
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
lea    0xd46(%rip),%rsi
call   10b0 <fprintf@plt>
mov    0x2cfd(%rip),%rax
mov    (%rax),%edi
call   1170 <exit@plt>
mov    %rsp,%r15
jmp    1341 <sdo_upload+0xc1>
nopw   0x0(%rax,%rax,1)
call   1050 <is_upload_segment_response@plt>
mov    (%rsp),%edi
test   %rax,%rax
je     1370 <sdo_upload+0xf0>
mov    $0x1,%esi
call   1190 <dump_data_binary@plt>
mov    (%rsp),%edi
call   1120 <c@plt>
test   %rax,%rax
jne    140e <sdo_upload+0x18e>
mov    (%rsp),%edi
call   1070 <t@plt>
mov    %rax,%rsi
add    $0x1,%rsi
mov    %ebx,%edi
call   1160 <sdo_upload_segment_request@plt>
mov    %r15,%rdi
mov    %ebx,%esi
call   1150 <await_sdo_confirmation@plt>
test   %rax,%rax
je     12ae <sdo_upload+0x2e>
mov    (%rsp),%edi
mov    %ebp,%esi
mov    %r14d,%edx
call   1180 <is_upload_initiate_response@plt>
mov    (%rsp),%edi
test   %rax,%rax
je     12f0 <sdo_upload+0x70>
call   1100 <e@plt>
test   %eax,%eax
jne    139a <sdo_upload+0x11a>
mov    (%rsp),%edi
call   1130 <s@plt>
cmp    $0x1,%eax
jne    139a <sdo_upload+0x11a>
xor    %esi,%esi
jmp    1327 <sdo_upload+0xa7>
mov    %ebp,%esi
mov    %r14d,%edx
call   10c0 <is_abort_transfer_request@plt>
test   %rax,%rax
je     132e <sdo_upload+0xae>
mov    (%rsp),%edi
call   1030 <data32@plt>
mov    %eax,%edi
call   10f0 <print_sdo_error@plt>
xor    %eax,%eax
call   10a0 <socketcan_close@plt>
jmp    12d4 <sdo_upload+0x54>
mov    (%rsp),%edi
call   1100 <e@plt>
cmp    $0x1,%eax
jne    13dd <sdo_upload+0x15d>
mov    (%rsp),%edi
call   1130 <s@plt>
cmp    $0x1,%eax
jne    13dd <sdo_upload+0x15d>
mov    (%rsp),%edi
call   1060 <n@plt>
cmp    $0x3,%eax
ja     140e <sdo_upload+0x18e>
mov    %eax,%eax
lea    0xc36(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    (%rsp),%edi
call   1110 <data24@plt>
jmp    13fe <sdo_upload+0x17e>
mov    (%rsp),%edi
call   1100 <e@plt>
cmp    $0x1,%eax
jne    140e <sdo_upload+0x18e>
mov    (%rsp),%edi
call   1130 <s@plt>
test   %eax,%eax
jne    140e <sdo_upload+0x18e>
mov    (%rsp),%edi
call   1030 <data32@plt>
mov    %eax,%esi
lea    0xc09(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
xor    %eax,%eax
call   10a0 <socketcan_close@plt>
mov    0x2baa(%rip),%rax
mov    (%rax),%edi
call   1170 <exit@plt>
mov    (%rsp),%edi
call   1090 <data16@plt>
jmp    13fe <sdo_upload+0x17e>
mov    (%rsp),%edi
call   1140 <data8@plt>
jmp    13fe <sdo_upload+0x17e>

LLVM IR (-O0):
%struct.can_frame = type { i32 }
@.str = [5 x i8] c"0x%X\00"
@.str.1 = [2 x i8] c"\0A\00"
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.2 = [13 x i8] c"SDO timeout\0A\00"
define void @sdo_upload(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.can_frame
%10 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = load i8*, i8** %5
%12 = call i32 @socketcan_open(i8* %11)
%13 = load i32, i32* %6
%14 = load i32, i32* %7
%15 = load i32, i32* %8
%16 = call i32 @sdo_upload_initiate_request(i32 %13, i32 %14, i32 %15)
br label %17
17: ; preds = %142, %38, %4
%18 = load i32, i32* %6
%19 = call i64 @await_sdo_confirmation(%struct.can_frame* %9, i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %143
21: ; preds = %17
%22 = load i32, i32* %7
%23 = load i32, i32* %8
%24 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %9, i32 0, i32 0
%25 = load i32, i32* %24
%26 = call i64 @is_upload_initiate_response(i32 %25, i32 %22, i32 %23)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %98
28: ; preds = %21
%29 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %9, i32 0, i32 0
%30 = load i32, i32* %29
%31 = call i32 @e(i32 %30)
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %41
33: ; preds = %28
%34 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %9, i32 0, i32 0
%35 = load i32, i32* %34
%36 = call i32 @s(i32 %35)
%37 = icmp eq i32 %36, 1
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = load i32, i32* %6
%40 = call i32 @sdo_upload_segment_request(i32 %39, i64 0)
br label %17
41: ; preds = %33, %28
%42 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %9, i32 0, i32 0
%43 = load i32, i32* %42
%44 = call i32 @e(i32 %43)
%45 = icmp eq i32 %44, 1
br i1 %45, label %46, label %76
46: ; preds = %41
%47 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %9, i32 0, i32 0
%48 = load i32, i32* %47
%49 = call i32 @s(i32 %48)
%50 = icmp eq i32 %49, 1
br i1 %50, label %51, label %76
51: ; preds = %46
%52 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %9, i32 0, i32 0
%53 = load i32, i32* %52
%54 = call i32 @n(i32 %53)
switch i32 %54, label %75 [
i32 0, label %55
i32 1, label %60
i32 2, label %65
i32 3, label %70
]
55: ; preds = %51
%56 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %9, i32 0, i32 0
%57 = load i32, i32* %56
%58 = call i32 @data32(i32 %57)
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %58)
br label %75
60: ; preds = %51
%61 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %9, i32 0, i32 0
%62 = load i32, i32* %61
%63 = call i32 @data24(i32 %62)
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %63)
br label %75
65: ; preds = %51
%66 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %9, i32 0, i32 0
%67 = load i32, i32* %66
%68 = call i32 @data16(i32 %67)
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %68)
br label %75
70: ; preds = %51
%71 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %9, i32 0, i32 0
%72 = load i32, i32* %71
%73 = call i32 @data8(i32 %72)
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %73)
br label %75
75: ; preds = %51, %70, %65, %60, %55
br label %92
76: ; preds = %46, %41
%77 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %9, i32 0, i32 0
%78 = load i32, i32* %77
%79 = call i32 @e(i32 %78)
%80 = icmp eq i32 %79, 1
br i1 %80, label %81, label %91
81: ; preds = %76
%82 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %9, i32 0, i32 0
%83 = load i32, i32* %82
%84 = call i32 @s(i32 %83)
%85 = icmp eq i32 %84, 0
br i1 %85, label %86, label %91
86: ; preds = %81
%87 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %9, i32 0, i32 0
%88 = load i32, i32* %87
%89 = call i32 @data32(i32 %88)
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %89)
br label %91
91: ; preds = %86, %81, %76
br label %92
92: ; preds = %91, %75
br label %93
93: ; preds = %92
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%95 = call i32 (...) @socketcan_close()
%96 = load i32, i32* @EXIT_SUCCESS
%97 = call i32 @exit(i32 %96)
unreachable
98: ; preds = %21
%99 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %9, i32 0, i32 0
%100 = load i32, i32* %99
%101 = call i64 @is_upload_segment_response(i32 %100)
%102 = icmp ne i64 %101, 0
br i1 %102, label %103, label %124
103: ; preds = %98
%104 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %9, i32 0, i32 0
%105 = load i32, i32* %104
%106 = call i32 @dump_data_binary(i32 %105, i32 1)
%107 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %9, i32 0, i32 0
%108 = load i32, i32* %107
%109 = call i64 @c(i32 %108)
%110 = icmp eq i64 %109, 0
br i1 %110, label %111, label %118
111: ; preds = %103
%112 = load i32, i32* %6
%113 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %9, i32 0, i32 0
%114 = load i32, i32* %113
%115 = call i64 @t(i32 %114)
%116 = add nsw i64 %115, 1
%117 = call i32 @sdo_upload_segment_request(i32 %112, i64 %116)
br label %123
118: ; preds = %103
%119 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%120 = call i32 (...) @socketcan_close()
%121 = load i32, i32* @EXIT_SUCCESS
%122 = call i32 @exit(i32 %121)
unreachable
123: ; preds = %111
br label %141
124: ; preds = %98
%125 = load i32, i32* %7
%126 = load i32, i32* %8
%127 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %9, i32 0, i32 0
%128 = load i32, i32* %127
%129 = call i64 @is_abort_transfer_request(i32 %128, i32 %125, i32 %126)
%130 = icmp ne i64 %129, 0
br i1 %130, label %131, label %140
131: ; preds = %124
%132 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %9, i32 0, i32 0
%133 = load i32, i32* %132
%134 = call i32 @data32(i32 %133)
store i32 %134, i32* %10
%135 = load i32, i32* %10
%136 = call i32 @print_sdo_error(i32 %135)
%137 = call i32 (...) @socketcan_close()
%138 = load i32, i32* @EXIT_FAILURE
%139 = call i32 @exit(i32 %138)
unreachable
140: ; preds = %124
br label %141
141: ; preds = %140, %123
br label %142
142: ; preds = %141
br label %17
143: ; preds = %17
%144 = load i32, i32* %6
%145 = load i32, i32* %7
%146 = load i32, i32* %8
%147 = call i32 @sdo_abort_transfer(i32 %144, i32 %145, i32 %146, i32 84148224)
%148 = load i32, i32* @stderr
%149 = call i32 @fprintf(i32 %148, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%150 = load i32, i32* @EXIT_FAILURE
%151 = call i32 @exit(i32 %150)
unreachable
}

LLVM IR (-O2):
%struct.can_frame = type { i32 }
@.str = [5 x i8] c"0x%X\00"
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.2 = [13 x i8] c"SDO timeout\0A\00"
define void @sdo_upload(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca %struct.can_frame
%6 = tail call i32 @socketcan_open(i8* %0)
%7 = tail call i32 @sdo_upload_initiate_request(i32 %1, i32 %2, i32 %3)
%8 = bitcast %struct.can_frame* %5 to i8*
%9 = call i64 @await_sdo_confirmation(%struct.can_frame* %5, i32 %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %101, label %11
11: ; preds = %4
%12 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %5, i64 0, i32 0
br label %13
13: ; preds = %11, %28
%14 = load i32, i32* %12
%15 = call i64 @is_upload_initiate_response(i32 %14, i32 %2, i32 %3)
%16 = icmp eq i64 %15, 0
%17 = load i32, i32* %12
br i1 %16, label %73, label %18
18: ; preds = %13
%19 = call i32 @e(i32 %17)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %31
21: ; preds = %18
%22 = load i32, i32* %12
%23 = call i32 @s(i32 %22)
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %31
25: ; preds = %21, %82
%26 = phi i64 [ %85, %82 ], [ 0, %21 ]
%27 = call i32 @sdo_upload_segment_request(i32 %1, i64 %26)
br label %28
28: ; preds = %25, %91
%29 = call i64 @await_sdo_confirmation(%struct.can_frame* %5, i32 %1)
%30 = icmp eq i64 %29, 0
br i1 %30, label %101, label %13
31: ; preds = %21, %18
%32 = load i32, i32* %12
%33 = call i32 @e(i32 %32)
%34 = icmp eq i32 %33, 1
br i1 %34, label %35, label %54
35: ; preds = %31
%36 = load i32, i32* %12
%37 = call i32 @s(i32 %36)
%38 = icmp eq i32 %37, 1
br i1 %38, label %39, label %54
39: ; preds = %35
%40 = load i32, i32* %12
%41 = call i32 @n(i32 %40)
switch i32 %41, label %68 [
i32 0, label %42
i32 1, label %45
i32 2, label %48
i32 3, label %51
]
42: ; preds = %39
%43 = load i32, i32* %12
%44 = call i32 @data32(i32 %43)
br label %65
45: ; preds = %39
%46 = load i32, i32* %12
%47 = call i32 @data24(i32 %46)
br label %65
48: ; preds = %39
%49 = load i32, i32* %12
%50 = call i32 @data16(i32 %49)
br label %65
51: ; preds = %39
%52 = load i32, i32* %12
%53 = call i32 @data8(i32 %52)
br label %65
54: ; preds = %35, %31
%55 = load i32, i32* %12
%56 = call i32 @e(i32 %55)
%57 = icmp eq i32 %56, 1
br i1 %57, label %58, label %68
58: ; preds = %54
%59 = load i32, i32* %12
%60 = call i32 @s(i32 %59)
%61 = icmp eq i32 %60, 0
br i1 %61, label %62, label %68
62: ; preds = %58
%63 = load i32, i32* %12
%64 = call i32 @data32(i32 %63)
br label %65
65: ; preds = %62, %42, %45, %48, %51
%66 = phi i32 [ %53, %51 ], [ %50, %48 ], [ %47, %45 ], [ %44, %42 ], [ %64, %62 ]
%67 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %66)
br label %68
68: ; preds = %65, %39, %58, %54
%69 = call i32 @putchar(i32 10)
%70 = call i32 (...) @socketcan_close()
%71 = load i32, i32* @EXIT_SUCCESS
%72 = call i32 @exit(i32 %71)
unreachable
73: ; preds = %13
%74 = call i64 @is_upload_segment_response(i32 %17)
%75 = icmp eq i64 %74, 0
%76 = load i32, i32* %12
br i1 %75, label %91, label %77
77: ; preds = %73
%78 = call i32 @dump_data_binary(i32 %76, i32 1)
%79 = load i32, i32* %12
%80 = call i64 @c(i32 %79)
%81 = icmp eq i64 %80, 0
br i1 %81, label %82, label %86
82: ; preds = %77
%83 = load i32, i32* %12
%84 = call i64 @t(i32 %83)
%85 = add nsw i64 %84, 1
br label %25
86: ; preds = %77
%87 = call i32 @putchar(i32 10)
%88 = call i32 (...) @socketcan_close()
%89 = load i32, i32* @EXIT_SUCCESS
%90 = call i32 @exit(i32 %89)
unreachable
91: ; preds = %73
%92 = call i64 @is_abort_transfer_request(i32 %76, i32 %2, i32 %3)
%93 = icmp eq i64 %92, 0
br i1 %93, label %28, label %94
94: ; preds = %91
%95 = load i32, i32* %12
%96 = call i32 @data32(i32 %95)
%97 = call i32 @print_sdo_error(i32 %96)
%98 = call i32 (...) @socketcan_close()
%99 = load i32, i32* @EXIT_FAILURE
%100 = call i32 @exit(i32 %99)
unreachable
101: ; preds = %28, %4
%102 = call i32 @sdo_abort_transfer(i32 %1, i32 %2, i32 %3, i32 84148224)
%103 = load i32, i32* @stderr
%104 = call i32 @fprintf(i32 %103, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%105 = load i32, i32* @EXIT_FAILURE
%106 = call i32 @exit(i32 %105)
unreachable
}