#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 in_addr {
  int /*<<< orphan*/ s_addr;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getdefaultgateway(int /*<<< orphan*/ *);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  struct in_addr gatewayaddr;
  int r;
  r = getdefaultgateway(&(gatewayaddr.s_addr));
  if (r >= 0)
    printf("default gateway : %s\n", inet_ntoa(gatewayaddr));
  else
    fprintf(stderr, "getdefaultgateway() failed\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1060 <getdefaultgateway@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     1188 <main+0x48>
mov    -0x18(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xe82(%rip),%rdi
call   1040 <printf@plt>
jmp    119d <main+0x5d>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    %rsp,%rdi
call   1060 <getdefaultgateway@plt>
test   %eax,%eax
js     1166 <main+0x26>
mov    (%rsp),%edi
call   1030 <inet_ntoa@plt>
lea    0xea4(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
jmp    117b <main+0x3b>
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
lea    0xea0(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@.str = [22 x i8] c"default gateway : %s\0A\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"getdefaultgateway() failed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.in_addr
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %6, i32 0, i32 0
%9 = call i32 @getdefaultgateway(i32* %8)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp sge i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %6, i32 0, i32 0
%14 = load i32, i32* %13
%15 = call i8* @inet_ntoa(i32 %14)
%16 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %20
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %17, %12
ret i32 0
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
@.str = [22 x i8] c"default gateway : %s\0A\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"getdefaultgateway() failed\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.in_addr
%4 = bitcast %struct.in_addr* %3 to i8*
%5 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 0, i32 0
%6 = call i32 @getdefaultgateway(i32* %5)
%7 = icmp sgt i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* %5
%10 = call i8* @inet_ntoa(i32 %9)
%11 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %12, %8
ret i32 0
}