#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 */

/* Variables and functions */
int /*<<< orphan*/ bail(char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *,
                           char const *);
int system(char *);
int insert_into_hosts(const char *path, const char *hostname, const char *ip) {
  int retval = -1;
  char *command = (char *)malloc(sizeof(char) * 1024);
  sprintf(command, "echo \"%s\t%s\" >> %s ", ip, hostname, path);
  retval = system(command);
  if (retval != -1) {
    retval = 0;
  } else {
    bail("Error reconfiguring hosts file");
    retval = -1;
  }
  free(command);
  return retval;
}


x86 assembly (clang, -O0):
<insert_into_hosts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%r8
lea    0xe70(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <system@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
je     11b7 <insert_into_hosts+0x67>
movl   $0x0,-0x1c(%rbp)
jmp    11ca <insert_into_hosts+0x7a>
lea    0xe56(%rip),%rdi
call   1060 <bail@plt>
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insert_into_hosts>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbp
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xe8c(%rip),%rsi
mov    %rax,%rdi
mov    %rbp,%rdx
mov    %r14,%rcx
mov    %r15,%r8
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <system@plt>
xor    %ebp,%ebp
cmp    $0xffffffff,%eax
jne    11a5 <insert_into_hosts+0x55>
lea    0xe79(%rip),%rdi
call   1060 <bail@plt>
mov    $0xffffffff,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"echo \22%s\09%s\22 >> %s \00"
@.str.1 = [31 x i8] c"Error reconfiguring hosts file\00"
define i32 @insert_into_hosts(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 -1, i32* %7
%9 = call i64 @malloc(i32 1024)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %8
%11 = load i8*, i8** %8
%12 = load i8*, i8** %6
%13 = load i8*, i8** %5
%14 = load i8*, i8** %4
%15 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %12, i8* %13, i8* %14)
%16 = load i8*, i8** %8
%17 = call i32 @system(i8* %16)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp ne i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %3
store i32 0, i32* %7
br label %23
21: ; preds = %3
%22 = call i32 @bail(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %7
br label %23
23: ; preds = %21, %20
%24 = load i8*, i8** %8
%25 = call i32 @free(i8* %24)
%26 = load i32, i32* %7
ret i32 %26
}

LLVM IR (-O2):
@.str = [20 x i8] c"echo \22%s\09%s\22 >> %s \00"
@.str.1 = [31 x i8] c"Error reconfiguring hosts file\00"
define i32 @insert_into_hosts(i8* %0, i8* %1, i8* %2) {
%4 = tail call i64 @malloc(i32 1024)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @sprintf(i8* dereferenceable(1) %5, i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %2, i8* %1, i8* %0)
%7 = tail call i32 @system(i8* %5)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = tail call i32 @bail(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %3, %9
%12 = phi i32 [ -1, %9 ], [ 0, %3 ]
%13 = tail call i32 @free(i8* %5)
ret i32 %12
}