#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 sockaddr_in {
  int dummy;
};
struct ifreq {
  char *ifr_name;
  char *ifr_newname;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SIOCGIWNAME;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strncpy(char *, char *, int);
int main(int argc, char **argv) {
  int ret;
  struct ifreq req;
  struct sockaddr_in *addr;
  int s;
  if (argc != 2) {
    fprintf(stderr, "Need an interface name (like wlan0)\n");
    return 1;
  }
  s = socket(AF_INET, SOCK_DGRAM, 0);
  if (s < 0) {
    perror("Cannot open socket");
    return 1;
  }
  strncpy(req.ifr_name, argv[1], sizeof(req.ifr_name));
  ret = ioctl(s, SIOCGIWNAME, &req);
  if (ret < 0) {
    fprintf(stderr, "No wireless extension\n");
    return 1;
  }
  printf("%s\n", req.ifr_name);
  printf("%s\n", req.ifr_newname);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a1 <main+0x41>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    125f <main+0xff>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    11df <main+0x7f>
lea    0xe57(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    125f <main+0xff>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
mov    -0x34(%rbp),%edi
mov    0x2dc9(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1050 <ioctl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1238 <main+0xd8>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
lea    0xe11(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    125f <main+0xff>
mov    -0x28(%rbp),%rsi
lea    0xe0c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xdfc(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    11dd <main+0x7d>
mov    %rsi,%rbx
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
test   %eax,%eax
js     1210 <main+0xb0>
mov    %eax,%ebp
mov    0x8(%rbx),%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
call   1050 <ioctl@plt>
test   %eax,%eax
js     11ef <main+0x8f>
mov    0x8(%rsp),%rsi
lea    0xe8b(%rip),%rbx
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <printf@plt>
xor    %eax,%eax
jmp    1209 <main+0xa9>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
lea    0xe13(%rip),%rsi
jmp    11ff <main+0x9f>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe0e(%rip),%rdi
call   1070 <perror@plt>
jmp    1204 <main+0xa4>

LLVM IR (-O0):
%struct.ifreq = type { i8*, i8* }
%struct.sockaddr_in = type { i32 }
@stderr = global i32 0
@.str = [37 x i8] c"Need an interface name (like wlan0)\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [19 x i8] c"Cannot open socket\00"
@SIOCGIWNAME = global i32 0
@.str.2 = [23 x i8] c"No wireless extension\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.ifreq
%8 = alloca %struct.sockaddr_in*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %45
15: ; preds = %2
%16 = load i32, i32* @AF_INET
%17 = load i32, i32* @SOCK_DGRAM
%18 = call i32 @socket(i32 %16, i32 %17, i32 0)
store i32 %18, i32* %9
%19 = load i32, i32* %9
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %45
23: ; preds = %15
%24 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %7, i32 0, i32 0
%25 = load i8*, i8** %24
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @strncpy(i8* %25, i8* %28, i32 8)
%30 = load i32, i32* %9
%31 = load i32, i32* @SIOCGIWNAME
%32 = call i32 @ioctl(i32 %30, i32 %31, %struct.ifreq* %7)
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %23
%36 = load i32, i32* @stderr
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %45
38: ; preds = %23
%39 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %7, i32 0, i32 0
%40 = load i8*, i8** %39
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %40)
%42 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %7, i32 0, i32 1
%43 = load i8*, i8** %42
%44 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %43)
store i32 0, i32* %3
br label %45
45: ; preds = %38, %35, %21, %12
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
%struct.ifreq = type { i8*, i8* }
%struct.sockaddr_in = type { i32 }
@stderr = global i32 0
@.str = [37 x i8] c"Need an interface name (like wlan0)\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [19 x i8] c"Cannot open socket\00"
@SIOCGIWNAME = global i32 0
@.str.2 = [23 x i8] c"No wireless extension\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.ifreq
%4 = bitcast %struct.ifreq* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %33
9: ; preds = %2
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_DGRAM
%12 = tail call i32 @socket(i32 %10, i32 %11, i32 0)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %33
16: ; preds = %9
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i32 @strncpy(i8* undef, i8* %18, i32 8)
%20 = load i32, i32* @SIOCGIWNAME
%21 = call i32 @ioctl(i32 %12, i32 %20, %struct.ifreq* %3)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %16
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %33
26: ; preds = %16
%27 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 0
%28 = load i8*, i8** %27
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%30 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 1
%31 = load i8*, i8** %30
%32 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %26, %23, %14, %6
%34 = phi i32 [ 1, %6 ], [ 1, %14 ], [ 1, %23 ], [ 0, %26 ]
ret i32 %34
}