#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 */
struct sigma_dut {
  int dummy;
};
struct sigma_conn {
  int dummy;
};
struct sigma_cmd {
  int dummy;
};

/* Variables and functions */
char *get_param(struct sigma_cmd *, char *);
char *get_station_ifname();
int set_eap_common(struct sigma_dut *, struct sigma_conn *, char const *,
                   struct sigma_cmd *);
scalar_t__ set_network(char const *, int, char *, char *);
scalar_t__ set_network_quoted(char const *, int, char *, char *);
int cmd_sta_set_eapttls(struct sigma_dut *dut, struct sigma_conn *conn,
                        struct sigma_cmd *cmd) {
  const char *intf = get_param(cmd, "Interface");
  const char *ifname;
  int id;
  ifname = get_station_ifname();
  id = set_eap_common(dut, conn, ifname, cmd);
  if (id < 0)
    return id;
  if (set_network(ifname, id, "eap", "TTLS") < 0)
    return -2;
  if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0)
    return -2;
  return 1;
}


x86 assembly (clang, -O0):
<cmd_sta_set_eapttls>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe91(%rip),%rsi
call   1030 <get_param@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1070 <get_station_ifname@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1060 <set_eap_common@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    11b0 <cmd_sta_set_eapttls+0x60>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1217 <cmd_sta_set_eapttls+0xc7>
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
lea    0xe4c(%rip),%rdx
lea    0xe49(%rip),%rcx
call   1050 <set_network@plt>
cmp    $0x0,%rax
jge    11e0 <cmd_sta_set_eapttls+0x90>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1217 <cmd_sta_set_eapttls+0xc7>
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
lea    0xe25(%rip),%rdx
lea    0xe25(%rip),%rcx
call   1040 <set_network_quoted@plt>
cmp    $0x0,%rax
jge    1210 <cmd_sta_set_eapttls+0xc0>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1217 <cmd_sta_set_eapttls+0xc7>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_sta_set_eapttls>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xe98(%rip),%rsi
mov    %rdx,%rdi
call   1030 <get_param@plt>
xor    %eax,%eax
call   1070 <get_station_ifname@plt>
mov    %rax,%r14
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
mov    %rbx,%rcx
call   1060 <set_eap_common@plt>
mov    %eax,%ebx
test   %eax,%eax
js     11d7 <cmd_sta_set_eapttls+0x87>
lea    0xe72(%rip),%rdx
lea    0xe6f(%rip),%rcx
mov    %r14,%rdi
mov    %ebx,%esi
call   1050 <set_network@plt>
test   %rax,%rax
js     11d2 <cmd_sta_set_eapttls+0x82>
lea    0xe5e(%rip),%rdx
lea    0xe5e(%rip),%rcx
mov    %r14,%rdi
mov    %ebx,%esi
call   1040 <set_network_quoted@plt>
mov    %rax,%rbx
sar    $0x3f,%rbx
xor    $0x1,%ebx
jmp    11d7 <cmd_sta_set_eapttls+0x87>
mov    $0xfffffffe,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sigma_dut = type { i32 }
%struct.sigma_conn = type { i32 }
%struct.sigma_cmd = type { i32 }
@.str = [10 x i8] c"Interface\00"
@.str.1 = [4 x i8] c"eap\00"
@.str.2 = [5 x i8] c"TTLS\00"
@.str.3 = [7 x i8] c"phase2\00"
@.str.4 = [14 x i8] c"auth=MSCHAPV2\00"
define i32 @cmd_sta_set_eapttls(%struct.sigma_dut* %0, %struct.sigma_conn* %1, %struct.sigma_cmd* %2) {
%4 = alloca i32
%5 = alloca %struct.sigma_dut*
%6 = alloca %struct.sigma_conn*
%7 = alloca %struct.sigma_cmd*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store %struct.sigma_dut* %0, %struct.sigma_dut** %5
store %struct.sigma_conn* %1, %struct.sigma_conn** %6
store %struct.sigma_cmd* %2, %struct.sigma_cmd** %7
%11 = load %struct.sigma_cmd*, %struct.sigma_cmd** %7
%12 = call i8* @get_param(%struct.sigma_cmd* %11, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** %8
%13 = call i8* (...) @get_station_ifname()
store i8* %13, i8** %9
%14 = load %struct.sigma_dut*, %struct.sigma_dut** %5
%15 = load %struct.sigma_conn*, %struct.sigma_conn** %6
%16 = load i8*, i8** %9
%17 = load %struct.sigma_cmd*, %struct.sigma_cmd** %7
%18 = call i32 @set_eap_common(%struct.sigma_dut* %14, %struct.sigma_conn* %15, i8* %16, %struct.sigma_cmd* %17)
store i32 %18, i32* %10
%19 = load i32, i32* %10
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %3
%22 = load i32, i32* %10
store i32 %22, i32* %4
br label %36
23: ; preds = %3
%24 = load i8*, i8** %9
%25 = load i32, i32* %10
%26 = call i64 @set_network(i8* %24, i32 %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %23
store i32 -2, i32* %4
br label %36
29: ; preds = %23
%30 = load i8*, i8** %9
%31 = load i32, i32* %10
%32 = call i64 @set_network_quoted(i8* %30, i32 %31, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %29
store i32 -2, i32* %4
br label %36
35: ; preds = %29
store i32 1, i32* %4
br label %36
36: ; preds = %35, %34, %28, %21
%37 = load i32, i32* %4
ret i32 %37
}

LLVM IR (-O2):
%struct.sigma_dut = type { i32 }
%struct.sigma_conn = type { i32 }
%struct.sigma_cmd = type { i32 }
@.str = [10 x i8] c"Interface\00"
@.str.1 = [4 x i8] c"eap\00"
@.str.2 = [5 x i8] c"TTLS\00"
@.str.3 = [7 x i8] c"phase2\00"
@.str.4 = [14 x i8] c"auth=MSCHAPV2\00"
define i32 @cmd_sta_set_eapttls(%struct.sigma_dut* %0, %struct.sigma_conn* %1, %struct.sigma_cmd* %2) {
%4 = tail call i8* @get_param(%struct.sigma_cmd* %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%5 = tail call i8* (...) @get_station_ifname()
%6 = tail call i32 @set_eap_common(%struct.sigma_dut* %0, %struct.sigma_conn* %1, i8* %5, %struct.sigma_cmd* %2)
%7 = icmp slt i32 %6, 0
br i1 %7, label %15, label %8
8: ; preds = %3
%9 = tail call i64 @set_network(i8* %5, i32 %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp slt i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = tail call i64 @set_network_quoted(i8* %5, i32 %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%13 = icmp slt i64 %12, 0
%14 = select i1 %13, i32 -2, i32 1
br label %15
15: ; preds = %11, %8, %3
%16 = phi i32 [ %6, %3 ], [ -2, %8 ], [ %14, %11 ]
ret i32 %16
}