#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 unsigned long in_addr_t;

/* Variables and functions */
int RTF_GATEWAY;
int RTF_UP;
int /*<<< orphan*/ printf(char *, char *, unsigned long, unsigned long, int);
int /*<<< orphan*/ sscanf(char *, char *, char *, unsigned long *,
                          unsigned long *, int *);
int net_search_gateway(char *buf, in_addr_t *gate_addr) {
  char iface[16];
  unsigned long dest, gate;
  int iflags;
  sscanf(buf, "%s\t%08lX\t%08lX\t%8X\t", iface, &dest, &gate, &iflags);
  printf("net_search_gateway:%s, %lX, %lX, %X\n", iface, dest, gate, iflags);
  if ((iflags & (RTF_UP | RTF_GATEWAY)) == (RTF_UP | RTF_GATEWAY)) {
    *gate_addr = gate;
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<net_search_gateway>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    0xec1(%rip),%rsi
lea    -0x38(%rbp),%rcx
lea    -0x40(%rbp),%r8
lea    -0x44(%rbp),%r9
call   1040 <sscanf@plt>
lea    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    -0x44(%rbp),%r8d
lea    0xead(%rip),%rdi
call   1030 <printf@plt>
mov    -0x44(%rbp),%eax
mov    0x2e62(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2e61(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
mov    0x2e4e(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2e4d(%rip),%rdx
or     (%rdx),%ecx
cmp    %ecx,%eax
jne    11b4 <net_search_gateway+0x94>
mov    -0x40(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11bb <net_search_gateway+0x9b>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<net_search_gateway>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r14
lea    0xecf(%rip),%rsi
lea    0x20(%rsp),%rbx
lea    0x18(%rsp),%rcx
lea    0x10(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %rbx,%rdx
call   1040 <sscanf@plt>
mov    0x18(%rsp),%rdx
mov    0x10(%rsp),%rcx
mov    0xc(%rsp),%r8d
lea    0xeb1(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    0x2e66(%rip),%rax
mov    0x2e67(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0xc(%rsp),%edx
not    %edx
mov    $0xffffffff,%eax
test   %edx,%ecx
jne    1196 <net_search_gateway+0x76>
mov    0x10(%rsp),%rax
mov    %rax,(%r14)
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [20 x i8] c"%s\09%08lX\09%08lX\09%8X\09\00"
@.str.1 = [37 x i8] c"net_search_gateway:%s, %lX, %lX, %X\0A\00"
@RTF_UP = global i32 0
@RTF_GATEWAY = global i32 0
define i32 @net_search_gateway(i8* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca [16 x i8]
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
store i8* %0, i8** %4
store i64* %1, i64** %5
%10 = load i8*, i8** %4
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%12 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %11, i64* %7, i64* %8, i32* %9)
%13 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%14 = load i64, i64* %7
%15 = load i64, i64* %8
%16 = load i32, i32* %9
%17 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %13, i64 %14, i64 %15, i32 %16)
%18 = load i32, i32* %9
%19 = load i32, i32* @RTF_UP
%20 = load i32, i32* @RTF_GATEWAY
%21 = or i32 %19, %20
%22 = and i32 %18, %21
%23 = load i32, i32* @RTF_UP
%24 = load i32, i32* @RTF_GATEWAY
%25 = or i32 %23, %24
%26 = icmp eq i32 %22, %25
br i1 %26, label %27, label %30
27: ; preds = %2
%28 = load i64, i64* %8
%29 = load i64*, i64** %5
store i64 %28, i64* %29
store i32 0, i32* %3
br label %31
30: ; preds = %2
store i32 -1, i32* %3
br label %31
31: ; preds = %30, %27
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@.str = [20 x i8] c"%s\09%08lX\09%08lX\09%8X\09\00"
@.str.1 = [37 x i8] c"net_search_gateway:%s, %lX, %lX, %X\0A\00"
@RTF_UP = global i32 0
@RTF_GATEWAY = global i32 0
define i32 @net_search_gateway(i8* nocapture %0, i64* nocapture writeonly %1) {
%3 = alloca [16 x i8]
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%8 = bitcast i64* %4 to i8*
%9 = bitcast i64* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %7, i64* %4, i64* %5, i32* %6)
%12 = load i64, i64* %4
%13 = load i64, i64* %5
%14 = load i32, i32* %6
%15 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %7, i64 %12, i64 %13, i32 %14)
%16 = load i32, i32* %6
%17 = load i32, i32* @RTF_UP
%18 = load i32, i32* @RTF_GATEWAY
%19 = or i32 %18, %17
%20 = and i32 %19, %16
%21 = icmp eq i32 %20, %19
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = load i64, i64* %5
store i64 %23, i64* %1
br label %24
24: ; preds = %2, %22
%25 = phi i32 [ 0, %22 ], [ -1, %2 ]
ret i32 %25
}