#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int associd;
};
typedef TYPE_1__ sctp_peeloff_arg_t;
typedef int /*<<< orphan*/ peeloff;

/* Variables and functions */
int /*<<< orphan*/ IPPROTO_SCTP;
int /*<<< orphan*/ SCTP_SOCKOPT_PEELOFF;
int get_asoc_id(int);
int getsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, TYPE_1__ *, int *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ system(char *);
void *peeloff_sctp(void *args) {
  int sctpsd = (long long)args;
  sctp_peeloff_arg_t peeloff;
  int optlen, newsd, associd;
  associd = get_asoc_id(sctpsd);
  printf("sd is %d, %d\n", sctpsd, associd);
  if (!associd)
    goto out;
  sleep(5);
  peeloff.associd = associd;
  optlen = sizeof(peeloff);
  newsd =
      getsockopt(sctpsd, IPPROTO_SCTP, SCTP_SOCKOPT_PEELOFF, &peeloff, &optlen);
  printf("new sd %d\n", newsd);
  if (newsd == -1)
    perror("getsockopt");
out:
  system("iptables -F");
  return NULL;
}


x86 assembly (clang, -O0):
<peeloff_sctp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <get_asoc_id@plt>
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    11a1 <peeloff_sctp+0x41>
jmp    1209 <peeloff_sctp+0xa9>
mov    $0x5,%edi
call   1080 <sleep@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x10(%rbp)
movl   $0x4,-0x14(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
mov    0x2e1d(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%r8
call   1060 <getsockopt@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0xffffffff,-0x18(%rbp)
jne    1204 <peeloff_sctp+0xa4>
lea    0xe1a(%rip),%rdi
call   1070 <perror@plt>
jmp    1209 <peeloff_sctp+0xa9>
lea    0xe14(%rip),%rdi
call   1040 <system@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<peeloff_sctp>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <get_asoc_id@plt>
mov    %eax,%ebp
lea    0xe8c(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebp,%ebp
je     11d0 <peeloff_sctp+0x70>
mov    $0x5,%edi
call   1080 <sleep@plt>
mov    %ebp,(%rsp)
movl   $0x4,0x4(%rsp)
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
mov    0x2e40(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rcx
lea    0x4(%rsp),%r8
mov    %ebx,%edi
call   1060 <getsockopt@plt>
mov    %eax,%ebx
lea    0xe4c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0xffffffff,%ebx
je     11e5 <peeloff_sctp+0x85>
lea    0xe4d(%rip),%rdi
call   1040 <system@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe2d(%rip),%rdi
call   1070 <perror@plt>
jmp    11d0 <peeloff_sctp+0x70>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32 }
@.str = [14 x i8] c"sd is %d, %d\0A\00"
@IPPROTO_SCTP = global i32 0
@SCTP_SOCKOPT_PEELOFF = global i32 0
@.str.1 = [11 x i8] c"new sd %d\0A\00"
@.str.2 = [11 x i8] c"getsockopt\00"
@.str.3 = [12 x i8] c"iptables -F\00"
define i8* @peeloff_sctp(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.TYPE_3__
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = ptrtoint i8* %8 to i64
%10 = trunc i64 %9 to i32
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = call i32 @get_asoc_id(i32 %11)
store i32 %12, i32* %7
%13 = load i32, i32* %3
%14 = load i32, i32* %7
%15 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %14)
%16 = load i32, i32* %7
%17 = icmp ne i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %1
br label %34
19: ; preds = %1
%20 = call i32 @sleep(i32 5)
%21 = load i32, i32* %7
%22 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %4, i32 0, i32 0
store i32 %21, i32* %22
store i32 4, i32* %5
%23 = load i32, i32* %3
%24 = load i32, i32* @IPPROTO_SCTP
%25 = load i32, i32* @SCTP_SOCKOPT_PEELOFF
%26 = call i32 @getsockopt(i32 %23, i32 %24, i32 %25, %struct.TYPE_3__* %4, i32* %5)
store i32 %26, i32* %6
%27 = load i32, i32* %6
%28 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %6
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %33
31: ; preds = %19
%32 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %31, %19
br label %34
34: ; preds = %33, %18
%35 = call i32 @system(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
ret i8* null
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32 }
@.str = [14 x i8] c"sd is %d, %d\0A\00"
@IPPROTO_SCTP = global i32 0
@SCTP_SOCKOPT_PEELOFF = global i32 0
@.str.1 = [11 x i8] c"new sd %d\0A\00"
@.str.2 = [11 x i8] c"getsockopt\00"
@.str.3 = [12 x i8] c"iptables -F\00"
define noalias i8* @peeloff_sctp(i8* %0) {
%2 = alloca %struct.TYPE_3__
%3 = alloca i32
%4 = ptrtoint i8* %0 to i64
%5 = trunc i64 %4 to i32
%6 = bitcast %struct.TYPE_3__* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = tail call i32 @get_asoc_id(i32 %5)
%9 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %8)
%10 = icmp eq i32 %8, 0
br i1 %10, label %21, label %11
11: ; preds = %1
%12 = tail call i32 @sleep(i32 5)
%13 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i64 0, i32 0
store i32 %8, i32* %13
store i32 4, i32* %3
%14 = load i32, i32* @IPPROTO_SCTP
%15 = load i32, i32* @SCTP_SOCKOPT_PEELOFF
%16 = call i32 @getsockopt(i32 %5, i32 %14, i32 %15, %struct.TYPE_3__* %2, i32* %3)
%17 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = icmp eq i32 %16, -1
br i1 %18, label %19, label %21
19: ; preds = %11
%20 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %11, %19, %1
%22 = call i32 @system(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
ret i8* null
}