#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_2__ TYPE_1__;

/* Type definitions */
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct TYPE_2__ {
  int /*<<< orphan*/ sa_family;
};
struct ifreq {
  TYPE_1__ ifr_addr;
  int /*<<< orphan*/ ifr_name;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ IFNAMSIZ;
int /*<<< orphan*/ SIOCGIFADDR;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
scalar_t__ inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ lcd_print_string(char *);
int /*<<< orphan*/ lcd_send_command(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, scalar_t__);
int print_ip_address() {
  int fd;
  struct ifreq ifr;
  char iface[] = "usb0";
  fd = socket(AF_INET, SOCK_DGRAM, 0);
  ifr.ifr_addr.sa_family = AF_INET;
  strncpy(ifr.ifr_name, iface, IFNAMSIZ - 1);
  ioctl(fd, SIOCGIFADDR, &ifr);
  close(fd);
  lcd_send_command(0x80);
  lcd_print_string((char *)iface);
  lcd_send_command((0x80 | 0x40));
  lcd_print_string(
      (char *)inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr));
  return 0;
}


x86 assembly (clang, -O0):
<print_ip_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0xe82(%rip),%eax
mov    %eax,-0x15(%rbp)
mov    0xe7d(%rip),%al
mov    %al,-0x11(%rbp)
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x4(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x15(%rbp),%rsi
mov    0x2e08(%rip),%rax
mov    (%rax),%rdx
sub    $0x1,%rdx
call   1030 <strncpy@plt>
mov    -0x4(%rbp),%edi
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1060 <ioctl@plt>
mov    -0x4(%rbp),%edi
call   1070 <close@plt>
mov    $0x80,%edi
call   1050 <lcd_send_command@plt>
lea    -0x15(%rbp),%rdi
call   1080 <lcd_print_string@plt>
mov    $0xc0,%edi
call   1050 <lcd_send_command@plt>
mov    -0x10(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%rdi
call   1080 <lcd_print_string@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_ip_address>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movb   $0x0,0xc(%rsp)
movl   $0x30627375,0x8(%rsp)
30
mov    0x2e55(%rip),%r14
mov    (%r14),%edi
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,%ebx
mov    (%r14),%eax
mov    %eax,0x10(%rsp)
mov    0x2e1a(%rip),%rax
mov    (%rax),%rdx
add    $0xffffffffffffffff,%rdx
lea    0x8(%rsp),%r14
mov    %r14,%rsi
call   1030 <strncpy@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
mov    %ebx,%edi
call   1060 <ioctl@plt>
mov    %ebx,%edi
call   1070 <close@plt>
mov    $0x80,%edi
call   1050 <lcd_send_command@plt>
mov    %r14,%rdi
call   1080 <lcd_print_string@plt>
mov    $0xc0,%edi
call   1050 <lcd_send_command@plt>
mov    0x10(%rsp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%rdi
call   1080 <lcd_print_string@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_in = type { i32 }
@__const.print_ip_address.iface = [5 x i8] c"usb0\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IFNAMSIZ = global i64 0
@SIOCGIFADDR = global i32 0
define i32 @print_ip_address() {
%1 = alloca i32
%2 = alloca %struct.ifreq
%3 = alloca [5 x i8]
%4 = bitcast [5 x i8]* %3 to i8*
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_DGRAM
%7 = call i32 @socket(i32 %5, i32 %6, i32 0)
store i32 %7, i32* %1
%8 = load i32, i32* @AF_INET
%9 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i32 0, i32 0
%10 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %9, i32 0, i32 0
store i32 %8, i32* %10
%11 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i32 0, i32 1
%12 = load i32, i32* %11
%13 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%14 = load i64, i64* @IFNAMSIZ
%15 = sub nsw i64 %14, 1
%16 = call i32 @strncpy(i32 %12, i8* %13, i64 %15)
%17 = load i32, i32* %1
%18 = load i32, i32* @SIOCGIFADDR
%19 = call i32 @ioctl(i32 %17, i32 %18, %struct.ifreq* %2)
%20 = load i32, i32* %1
%21 = call i32 @close(i32 %20)
%22 = call i32 @lcd_send_command(i32 128)
%23 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%24 = call i32 @lcd_print_string(i8* %23)
%25 = call i32 @lcd_send_command(i32 192)
%26 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i32 0, i32 0
%27 = bitcast %struct.TYPE_2__* %26 to %struct.sockaddr_in*
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %27, i32 0, i32 0
%29 = load i32, i32* %28
%30 = call i64 @inet_ntoa(i32 %29)
%31 = inttoptr i64 %30 to i8*
%32 = call i32 @lcd_print_string(i8* %31)
ret i32 0
}

LLVM IR (-O2):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@__const.print_ip_address.iface = [5 x i8] c"usb0\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IFNAMSIZ = global i64 0
@SIOCGIFADDR = global i32 0
define i32 @print_ip_address() {
%1 = alloca %struct.ifreq
%2 = alloca [5 x i8]
%3 = bitcast %struct.ifreq* %1 to i8*
%4 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_DGRAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = load i32, i32* @AF_INET
%9 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %1, i64 0, i32 0, i32 0
store i32 %8, i32* %9
%10 = load i64, i64* @IFNAMSIZ
%11 = add nsw i64 %10, -1
%12 = call i32 @strncpy(i32 undef, i8* %4, i64 %11)
%13 = load i32, i32* @SIOCGIFADDR
%14 = call i32 @ioctl(i32 %7, i32 %13, %struct.ifreq* %1)
%15 = call i32 @close(i32 %7)
%16 = call i32 @lcd_send_command(i32 128)
%17 = call i32 @lcd_print_string(i8* %4)
%18 = call i32 @lcd_send_command(i32 192)
%19 = load i32, i32* %9
%20 = call i64 @inet_ntoa(i32 %19)
%21 = inttoptr i64 %20 to i8*
%22 = call i32 @lcd_print_string(i8* %21)
ret i32 0
}