#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 termios {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *);
scalar_t__ tcgetattr(int /*<<< orphan*/, struct termios *);
void warn_ipforward(void) {
  FILE *fp = fopen("/proc/sys/net/ipv4/ip_forward", "r");
  if (fp) {
    int forward;
    if (fscanf(fp, "%d", &forward) && forward == 0) {
      struct termios term;
      if (tcgetattr(STDIN_FILENO, &term) == 0)
        printf("Warning: you must enable IP forwarding"
               " for packets to be forwarded at all:\n"
               " Use `"
               "echo 1 > /proc/sys/net/ipv4/ip_forward"
               "'\n");
    }
    fclose(fp);
  }
}


x86 assembly (clang, -O0):
<warn_ipforward>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
lea    0xeb8(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11d8 <warn_ipforward+0x88>
mov    -0x8(%rbp),%rdi
lea    0xe9b(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1050 <fscanf@plt>
cmp    $0x0,%rax
je     11cf <warn_ipforward+0x7f>
cmpl   $0x0,-0xc(%rbp)
jne    11cf <warn_ipforward+0x7f>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1060 <tcgetattr@plt>
cmp    $0x0,%rax
jne    11ca <warn_ipforward+0x7a>
lea    0xe5e(%rip),%rdi
call   1040 <printf@plt>
jmp    11cf <warn_ipforward+0x7f>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<warn_ipforward>:
push   %rbx
sub    $0x10,%rsp
lea    0xea4(%rip),%rdi
lea    0xebb(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11bc <warn_ipforward+0x6c>
mov    %rax,%rbx
lea    0xea9(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
test   %rax,%rax
je     11b4 <warn_ipforward+0x64>
cmpl   $0x0,0x4(%rsp)
jne    11b4 <warn_ipforward+0x64>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1060 <tcgetattr@plt>
test   %rax,%rax
jne    11b4 <warn_ipforward+0x64>
lea    0xe74(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@.str = [30 x i8] c"/proc/sys/net/ipv4/ip_forward\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@STDIN_FILENO = global i32 0
@.str.3 = [122 x i8] c"Warning: you must enable IP forwarding for packets to be forwarded at all:\0A Use `echo 1 > /proc/sys/net/ipv4/ip_forward'\0A\00"
define void @warn_ipforward() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca %struct.termios
%4 = call i32* @fopen(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %1
%5 = load i32*, i32** %1
%6 = icmp ne i32* %5, null
br i1 %6, label %7, label %24
7: ; preds = %0
%8 = load i32*, i32** %1
%9 = call i64 @fscanf(i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %7
%12 = load i32, i32* %2
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = load i32, i32* @STDIN_FILENO
%16 = call i64 @tcgetattr(i32 %15, %struct.termios* %3)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @printf(i8* getelementptr inbounds ([122 x i8], [122 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
br label %21
21: ; preds = %20, %11, %7
%22 = load i32*, i32** %1
%23 = call i32 @fclose(i32* %22)
br label %24
24: ; preds = %21, %0
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@.str = [30 x i8] c"/proc/sys/net/ipv4/ip_forward\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@STDIN_FILENO = global i32 0
@str = [121 x i8] c"Warning: you must enable IP forwarding for packets to be forwarded at all:\0A Use `echo 1 > /proc/sys/net/ipv4/ip_forward'\00"
define void @warn_ipforward() {
%1 = alloca i32
%2 = alloca %struct.termios
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %22, label %5
5: ; preds = %0
%6 = bitcast i32* %1 to i8*
%7 = call i64 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%8 = icmp ne i64 %7, 0
%9 = load i32, i32* %1
%10 = icmp eq i32 %9, 0
%11 = select i1 %8, i1 %10, i1 false
br i1 %11, label %12, label %20
12: ; preds = %5
%13 = bitcast %struct.termios* %2 to i8*
%14 = load i32, i32* @STDIN_FILENO
%15 = call i64 @tcgetattr(i32 %14, %struct.termios* %2)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([121 x i8], [121 x i8]* @str, i64 0, i64 0))
br label %19
19: ; preds = %17, %12
br label %20
20: ; preds = %19, %5
%21 = call i32 @fclose(i32* %3)
br label %22
22: ; preds = %20, %0
ret void
}