#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*/ u_int;
typedef int u_char;
struct in_addr {
  int dummy;
};

/* Variables and functions */
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int creat(char *, int);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ logSysRet(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, int const *, int const);
scalar_t__ write(int, char *, int);
void mkResolvConf(const u_char *addr, const u_char *domName) {
  char buf[256];
  int fd;
  int i;
  u_int *p;
  strcpy(buf, "/etc/dhcpc");
  strcat(buf, "/");
  strcat(buf, "resolv.conf");
  if ((fd = creat(buf, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) < 0) {
    logSysRet("creat (mkResolvConf)");
    return;
  }
  strcpy(buf, "domain ");
  strncat(buf, domName + 1, *domName);
  strcat(buf, "\n");
  p = (u_int *)(addr + 1);
  for (i = 0; i < *addr / 4; ++i) {
    sprintf(buf + strlen(buf), "nameserver %s\n",
            inet_ntoa(*((struct in_addr *)p)));
    ++p;
  }
  if (write(fd, buf, strlen(buf)) < 0) {
    logSysRet("write (mkResolvConf)");
  }
  close(fd);
}


x86 assembly (clang, -O0):
<mkResolvConf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x110(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x110(%rbp),%rdi
lea    0xe37(%rip),%rsi
call   10a0 <strcat@plt>
lea    -0x110(%rbp),%rdi
lea    0xe26(%rip),%rsi
call   10a0 <strcat@plt>
lea    -0x110(%rbp),%rdi
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
mov    0x2de5(%rip),%rax
or     (%rax),%esi
mov    0x2dcc(%rip),%rax
or     (%rax),%esi
mov    0x2dbb(%rip),%rax
or     (%rax),%esi
call   10b0 <creat@plt>
mov    %eax,-0x114(%rbp)
cmp    $0x0,%eax
jge    123c <mkResolvConf+0x9c>
lea    0xde7(%rip),%rdi
call   1040 <logSysRet@plt>
jmp    1394 <mkResolvConf+0x1f4>
lea    -0x110(%rbp),%rdi
lea    0xde4(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x4,%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
call   1080 <strncat@plt>
lea    -0x110(%rbp),%rdi
lea    0xdcc(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x120(%rbp)
movl   $0x0,-0x118(%rbp)
mov    -0x118(%rbp),%eax
mov    %eax,-0x124(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x124(%rbp),%eax
cmp    %ecx,%eax
jge    1339 <mkResolvConf+0x199>
lea    -0x110(%rbp),%rax
mov    %rax,-0x138(%rbp)
lea    -0x110(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    -0x138(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x130(%rbp)
mov    -0x120(%rbp),%rax
mov    (%rax),%edi
call   1060 <inet_ntoa@plt>
mov    -0x130(%rbp),%rdi
mov    %rax,%rdx
lea    0xd28(%rip),%rsi
call   10c0 <sprintf@plt>
mov    -0x120(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x120(%rbp)
mov    -0x118(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x118(%rbp)
jmp    1295 <mkResolvConf+0xf5>
mov    -0x114(%rbp),%eax
mov    %eax,-0x144(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x140(%rbp)
lea    -0x110(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x144(%rbp),%edi
mov    -0x140(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
cmp    $0x0,%rax
jge    1389 <mkResolvConf+0x1e9>
lea    0xcc1(%rip),%rdi
call   1040 <logSysRet@plt>
mov    -0x114(%rbp),%edi
call   1090 <close@plt>
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkResolvConf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%r15
mov    %rdi,%r13
lea    0xe42(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1030 <strcpy@plt>
lea    0xe3b(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <strcat@plt>
lea    0xe2e(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <strcat@plt>
mov    0x2dda(%rip),%rax
mov    0x2df3(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2dd8(%rip),%rax
or     (%rax),%esi
mov    0x2dc7(%rip),%rax
or     (%rax),%esi
mov    %rbp,%rdi
call   10b0 <creat@plt>
test   %eax,%eax
js     12e0 <mkResolvConf+0x140>
mov    %eax,%r14d
lea    0xe09(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1030 <strcpy@plt>
mov    (%r15),%edx
add    $0x4,%r15
mov    %rbp,%rdi
mov    %r15,%rsi
call   1080 <strncat@plt>
lea    0xdfa(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <strcat@plt>
cmpl   $0x4,0x0(%r13)
jl     12ad <mkResolvConf+0x10d>
xor    %ebx,%ebx
mov    %rsp,%r15
lea    0xdd2(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
call   1070 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rbp
mov    0x4(%r13,%rbx,4),%edi
call   1060 <inet_ntoa@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
call   10c0 <sprintf@plt>
mov    0x0(%r13),%eax
lea    0x3(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
sar    $0x2,%ecx
add    $0x1,%rbx
cmp    %ecx,%ebx
jl     1270 <mkResolvConf+0xd0>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
test   %rax,%rax
jns    12d6 <mkResolvConf+0x136>
lea    0xd74(%rip),%rdi
call   1040 <logSysRet@plt>
mov    %r14d,%edi
call   1090 <close@plt>
jmp    12ec <mkResolvConf+0x14c>
lea    0xd32(%rip),%rdi
call   1040 <logSysRet@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@.str = [11 x i8] c"/etc/dhcpc\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [12 x i8] c"resolv.conf\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.3 = [21 x i8] c"creat (mkResolvConf)\00"
@.str.4 = [8 x i8] c"domain \00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [15 x i8] c"nameserver %s\0A\00"
@.str.7 = [21 x i8] c"write (mkResolvConf)\00"
define void @mkResolvConf(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [256 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
store i32* %0, i32** %3
store i32* %1, i32** %4
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%10 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%12 = call i32 @strcat(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%14 = call i32 @strcat(i8* %13, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%16 = load i32, i32* @S_IRUSR
%17 = load i32, i32* @S_IWUSR
%18 = or i32 %16, %17
%19 = load i32, i32* @S_IRGRP
%20 = or i32 %18, %19
%21 = load i32, i32* @S_IROTH
%22 = or i32 %20, %21
%23 = call i32 @creat(i8* %15, i32 %22)
store i32 %23, i32* %6
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %2
%26 = call i32 @logSysRet(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %75
27: ; preds = %2
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%29 = call i32 @strcpy(i8* %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%31 = load i32*, i32** %4
%32 = getelementptr inbounds i32, i32* %31, i64 1
%33 = load i32*, i32** %4
%34 = load i32, i32* %33
%35 = call i32 @strncat(i8* %30, i32* %32, i32 %34)
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%37 = call i32 @strcat(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%38 = load i32*, i32** %3
%39 = getelementptr inbounds i32, i32* %38, i64 1
store i32* %39, i32** %8
store i32 0, i32* %7
br label %40
40: ; preds = %60, %27
%41 = load i32, i32* %7
%42 = load i32*, i32** %3
%43 = load i32, i32* %42
%44 = sdiv i32 %43, 4
%45 = icmp slt i32 %41, %44
br i1 %45, label %46, label %63
46: ; preds = %40
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%49 = call i32 @strlen(i8* %48)
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %47, i64 %50
%52 = load i32*, i32** %8
%53 = bitcast i32* %52 to %struct.in_addr*
%54 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %53, i32 0, i32 0
%55 = load i32, i32* %54
%56 = call i8* @inet_ntoa(i32 %55)
%57 = call i32 @sprintf(i8* %51, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %56)
%58 = load i32*, i32** %8
%59 = getelementptr inbounds i32, i32* %58, i32 1
store i32* %59, i32** %8
br label %60
60: ; preds = %46
%61 = load i32, i32* %7
%62 = add nsw i32 %61, 1
store i32 %62, i32* %7
br label %40
63: ; preds = %40
%64 = load i32, i32* %6
%65 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%66 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%67 = call i32 @strlen(i8* %66)
%68 = call i64 @write(i32 %64, i8* %65, i32 %67)
%69 = icmp slt i64 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %63
%71 = call i32 @logSysRet(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
br label %72
72: ; preds = %70, %63
%73 = load i32, i32* %6
%74 = call i32 @close(i32 %73)
br label %75
75: ; preds = %72, %25
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"/etc/dhcpc\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [12 x i8] c"resolv.conf\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.3 = [21 x i8] c"creat (mkResolvConf)\00"
@.str.4 = [8 x i8] c"domain \00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [15 x i8] c"nameserver %s\0A\00"
@.str.7 = [21 x i8] c"write (mkResolvConf)\00"
define void @mkResolvConf(i32* nocapture %0, i32* %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%8 = load i32, i32* @S_IRUSR
%9 = load i32, i32* @S_IWUSR
%10 = or i32 %9, %8
%11 = load i32, i32* @S_IRGRP
%12 = or i32 %10, %11
%13 = load i32, i32* @S_IROTH
%14 = or i32 %12, %13
%15 = call i32 @creat(i8* %4, i32 %14)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @logSysRet(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %49
19: ; preds = %2
%20 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%21 = getelementptr inbounds i32, i32* %1, i64 1
%22 = load i32, i32* %1
%23 = call i32 @strncat(i8* %4, i32* %21, i32 %22)
%24 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%25 = load i32, i32* %0
%26 = icmp sgt i32 %25, 3
br i1 %26, label %27, label %41
27: ; preds = %19, %27
%28 = phi i32* [ %30, %27 ], [ %0, %19 ]
%29 = phi i32 [ %37, %27 ], [ 0, %19 ]
%30 = getelementptr inbounds i32, i32* %28, i64 1
%31 = call i32 @strlen(i8* %4)
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %32
%34 = load i32, i32* %30
%35 = call i8* @inet_ntoa(i32 %34)
%36 = call i32 @sprintf(i8* %33, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %35)
%37 = add nuw nsw i32 %29, 1
%38 = load i32, i32* %0
%39 = sdiv i32 %38, 4
%40 = icmp slt i32 %37, %39
br i1 %40, label %27, label %41
41: ; preds = %27, %19
%42 = call i32 @strlen(i8* %4)
%43 = call i64 @write(i32 %15, i8* %4, i32 %42)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %41
%46 = call i32 @logSysRet(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
br label %47
47: ; preds = %45, %41
%48 = call i32 @close(i32 %15)
br label %49
49: ; preds = %47, %17
ret void
}