#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int get_roach_num() {
  int roach_num = -1;
  FILE *command_output;
  char line[100];
  command_output =
      popen("ifconfig eth0 | grep 'inet addr' | grep '10.0.0.1[0-9]' -o", "r");
  if (command_output < 0 || command_output == NULL)
    error("ERROR calling ifconfig");
  fgets(line, 100 - 1, command_output);
  sscanf(line, "10.0.0.1%d", &roach_num);
  return roach_num;
}


x86 assembly (clang, -O0):
<get_roach_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0xffffffff,-0x4(%rbp)
lea    0xea7(%rip),%rdi
lea    0xedb(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jb     117f <get_roach_num+0x3f>
cmpq   $0x0,-0x10(%rbp)
jne    118b <get_roach_num+0x4b>
lea    0xeb7(%rip),%rdi
call   1050 <error@plt>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x63,%esi
call   1030 <fgets@plt>
lea    -0x80(%rbp),%rdi
lea    0xeac(%rip),%rsi
lea    -0x4(%rbp),%rdx
call   1040 <sscanf@plt>
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_roach_num>:
push   %r14
push   %rbx
sub    $0x78,%rsp
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xeaa(%rip),%rdi
lea    0xede(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1176 <get_roach_num+0x36>
lea    0xecc(%rip),%rdi
call   1050 <error@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x63,%esi
mov    %rbx,%rdx
call   1030 <fgets@plt>
lea    0xec2(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %r14,%rdi
call   1040 <sscanf@plt>
mov    0xc(%rsp),%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [59 x i8] c"ifconfig eth0 | grep 'inet addr' | grep '10.0.0.1[0-9]' -o\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"ERROR calling ifconfig\00"
@.str.3 = [11 x i8] c"10.0.0.1%d\00"
define i32 @get_roach_num() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [100 x i8]
store i32 -1, i32* %1
%4 = call i32* @popen(i8* getelementptr inbounds ([59 x i8], [59 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** %2
%5 = load i32*, i32** %2
%6 = icmp ult i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %0
%8 = load i32*, i32** %2
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %7, %0
%11 = call i32 @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%14 = load i32*, i32** %2
%15 = call i32 @fgets(i8* %13, i32 99, i32* %14)
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%17 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%18 = load i32, i32* %1
ret i32 %18
}

LLVM IR (-O2):
@.str = [59 x i8] c"ifconfig eth0 | grep 'inet addr' | grep '10.0.0.1[0-9]' -o\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"ERROR calling ifconfig\00"
@.str.3 = [11 x i8] c"10.0.0.1%d\00"
define i32 @get_roach_num() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = bitcast i32* %1 to i8*
store i32 -1, i32* %1
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = tail call i32* @popen(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %9
9: ; preds = %0, %7
%10 = call i32 @fgets(i8* %4, i32 99, i32* %5)
%11 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%12 = load i32, i32* %1
ret i32 %12
}