#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*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
int strlen(char *);
scalar_t__ system(char *);
int bh_add(int a, int b, int c, int d, int cidr) {
  char *cmd;
  char *ipblock;
  ipblock = (char *)malloc(32 + 1);
  if (ipblock == NULL)
    return 1;
  snprintf(ipblock, (32 + 1), "%d.%d.%d.%d/%d", a, b, c, d, cidr);
  cmd = malloc(sizeof "/sbin/ip" + sizeof "route add blackhole" +
               strlen(ipblock) + 77 + 1);
  if (cmd == NULL)
    return 1;
  snprintf(cmd,
           (sizeof "/sbin/ip" + sizeof "route add blackhole" + strlen(ipblock) +
            77 + 1),
           "%s %s %s", "/sbin/ip", "route add blackhole", ipblock);
  if (system(cmd)) {
    free(cmd);
    return 1;
  }
  free(cmd);
  return 0;
}


x86 assembly (clang, -O0):
<bh_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    $0x21,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    118d <bh_add+0x3d>
movl   $0x1,-0x4(%rbp)
jmp    1274 <bh_add+0x124>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    -0xc(%rbp),%r8d
mov    -0x10(%rbp),%r9d
mov    -0x14(%rbp),%r10d
mov    -0x18(%rbp),%eax
mov    $0x21,%esi
lea    0xe51(%rip),%rdx
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
mov    $0x0,%al
call   1060 <snprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
cltq
add    $0x1d,%rax
add    $0x4d,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f7 <bh_add+0xa7>
movl   $0x1,-0x4(%rbp)
jmp    1274 <bh_add+0x124>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
cltq
add    $0x1d,%rax
add    $0x4d,%rax
add    $0x1,%rax
mov    %eax,%esi
mov    -0x28(%rbp),%r9
lea    0xde8(%rip),%rdx
lea    0xdea(%rip),%rcx
lea    0xdec(%rip),%r8
mov    $0x0,%al
call   1060 <snprintf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <system@plt>
cmp    $0x0,%rax
je     1264 <bh_add+0x114>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    1274 <bh_add+0x124>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bh_add>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r15d
mov    %rcx,(%rsp)
mov    %edx,%r12d
mov    %esi,%r13d
mov    %edi,%r14d
mov    $0x21,%edi
call   1070 <malloc@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     120d <bh_add+0xbd>
mov    %rax,%rbx
lea    0xe73(%rip),%rdx
mov    %rax,%rdi
mov    $0x21,%esi
mov    %r14d,%ecx
mov    %r13d,%r8d
mov    %r12d,%r9d
xor    %eax,%eax
push   %r15
push   0x8(%rsp)
call   1060 <snprintf@plt>
add    $0x10,%rsp
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x6b(%rax),%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     120d <bh_add+0xbd>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x6b(%rax),%esi
lea    0xe36(%rip),%rdx
lea    0xe38(%rip),%rcx
lea    0xe3a(%rip),%r8
mov    %r14,%rdi
mov    %rbx,%r9
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    %r14,%rdi
call   1050 <system@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"%d.%d.%d.%d/%d\00"
@.str.1 = [9 x i8] c"%s %s %s\00"
@.str.2 = [9 x i8] c"/sbin/ip\00"
@.str.3 = [20 x i8] c"route add blackhole\00"
define i32 @bh_add(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%14 = call i8* @malloc(i32 33)
store i8* %14, i8** %13
%15 = load i8*, i8** %13
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %5
store i32 1, i32* %6
br label %57
18: ; preds = %5
%19 = load i8*, i8** %13
%20 = load i32, i32* %7
%21 = load i32, i32* %8
%22 = load i32, i32* %9
%23 = load i32, i32* %10
%24 = load i32, i32* %11
%25 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %19, i32 33, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %20, i32 %21, i32 %22, i32 %23, i32 %24)
%26 = load i8*, i8** %13
%27 = call i32 @strlen(i8* %26)
%28 = sext i32 %27 to i64
%29 = add i64 29, %28
%30 = add i64 %29, 77
%31 = add i64 %30, 1
%32 = trunc i64 %31 to i32
%33 = call i8* @malloc(i32 %32)
store i8* %33, i8** %12
%34 = load i8*, i8** %12
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %37
36: ; preds = %18
store i32 1, i32* %6
br label %57
37: ; preds = %18
%38 = load i8*, i8** %12
%39 = load i8*, i8** %13
%40 = call i32 @strlen(i8* %39)
%41 = sext i32 %40 to i64
%42 = add i64 29, %41
%43 = add i64 %42, 77
%44 = add i64 %43, 1
%45 = trunc i64 %44 to i32
%46 = load i8*, i8** %13
%47 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %38, i32 %45, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %46)
%48 = load i8*, i8** %12
%49 = call i64 @system(i8* %48)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %37
%52 = load i8*, i8** %12
%53 = call i32 @free(i8* %52)
store i32 1, i32* %6
br label %57
54: ; preds = %37
%55 = load i8*, i8** %12
%56 = call i32 @free(i8* %55)
store i32 0, i32* %6
br label %57
57: ; preds = %54, %51, %36, %17
%58 = load i32, i32* %6
ret i32 %58
}

LLVM IR (-O2):
@.str = [15 x i8] c"%d.%d.%d.%d/%d\00"
@.str.1 = [9 x i8] c"%s %s %s\00"
@.str.2 = [9 x i8] c"/sbin/ip\00"
@.str.3 = [20 x i8] c"route add blackhole\00"
define i32 @bh_add(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = tail call dereferenceable_or_null(33) i8* @malloc(i32 33)
%7 = icmp eq i8* %6, null
br i1 %7, label %22, label %8
8: ; preds = %5
%9 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %6, i32 33, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1, i32 %2, i32 %3, i32 %4)
%10 = tail call i32 @strlen(i8* %6)
%11 = add i32 %10, 107
%12 = tail call i8* @malloc(i32 %11)
%13 = icmp eq i8* %12, null
br i1 %13, label %22, label %14
14: ; preds = %8
%15 = tail call i32 @strlen(i8* %6)
%16 = add i32 %15, 107
%17 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %12, i32 %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%18 = tail call i64 @system(i8* %12)
%19 = icmp ne i64 %18, 0
%20 = tail call i32 @free(i8* %12)
%21 = zext i1 %19 to i32
br label %22
22: ; preds = %14, %8, %5
%23 = phi i32 [ 1, %5 ], [ 1, %8 ], [ %21, %14 ]
ret i32 %23
}