#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 *);
scalar_t__ write(int, char *, int);
void mkNTPconf(const u_char *addr) {
  char buf[256];
  int fd;
  int i;
  u_int *p;
  strcpy(buf, "/etc/dhcpc");
  strcat(buf, "/");
  strcat(buf, "ntp.conf");
  if ((fd = creat(buf, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) < 0) {
    logSysRet("creat (mkNTPconf)");
    return;
  }
  p = (u_int *)(addr + 1);
  *buf = '\0';
  for (i = 0; i < *addr / 4; ++i) {
    sprintf(buf + strlen(buf), "server %s\n",
            inet_ntoa(*((struct in_addr *)p)));
    ++p;
  }
  if (write(fd, buf, strlen(buf)) < 0) {
    logSysRet("write (mkNTPconf)");
  }
  close(fd);
}


x86 assembly (clang, -O0):
<mkNTPconf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x110(%rbp),%rdi
lea    0xe53(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x110(%rbp),%rdi
lea    0xe4b(%rip),%rsi
call   1090 <strcat@plt>
lea    -0x110(%rbp),%rdi
lea    0xe3a(%rip),%rsi
call   1090 <strcat@plt>
lea    -0x110(%rbp),%rdi
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
mov    0x2df9(%rip),%rax
or     (%rax),%esi
mov    0x2de0(%rip),%rax
or     (%rax),%esi
mov    0x2dcf(%rip),%rax
or     (%rax),%esi
call   10a0 <creat@plt>
mov    %eax,-0x114(%rbp)
cmp    $0x0,%eax
jge    1228 <mkNTPconf+0x98>
lea    0xdf8(%rip),%rdi
call   1040 <logSysRet@plt>
jmp    1347 <mkNTPconf+0x1b7>
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x120(%rbp)
movb   $0x0,-0x110(%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    12ec <mkNTPconf+0x15c>
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    0xd67(%rip),%rsi
call   10b0 <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    1248 <mkNTPconf+0xb8>
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    133c <mkNTPconf+0x1ac>
lea    0xcfc(%rip),%rdi
call   1040 <logSysRet@plt>
mov    -0x114(%rbp),%edi
call   1080 <close@plt>
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkNTPconf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%r13
lea    0xe55(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1030 <strcpy@plt>
lea    0xe4e(%rip),%rsi
mov    %rbp,%rdi
call   1090 <strcat@plt>
lea    0xe41(%rip),%rsi
mov    %rbp,%rdi
call   1090 <strcat@plt>
mov    0x2ded(%rip),%rax
mov    0x2e06(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2deb(%rip),%rax
or     (%rax),%esi
mov    0x2dda(%rip),%rax
or     (%rax),%esi
mov    %rbp,%rdi
call   10a0 <creat@plt>
test   %eax,%eax
js     12a0 <mkNTPconf+0x110>
mov    %eax,%r14d
movb   $0x0,(%rsp)
cmpl   $0x4,0x0(%r13)
jl     126d <mkNTPconf+0xdd>
xor    %ebx,%ebx
mov    %rsp,%r15
lea    0xe06(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
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   10b0 <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     1230 <mkNTPconf+0xa0>
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    1296 <mkNTPconf+0x106>
lea    0xda2(%rip),%rdi
call   1040 <logSysRet@plt>
mov    %r14d,%edi
call   1080 <close@plt>
jmp    12ac <mkNTPconf+0x11c>
lea    0xd6f(%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 = [9 x i8] c"ntp.conf\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.3 = [18 x i8] c"creat (mkNTPconf)\00"
@.str.4 = [11 x i8] c"server %s\0A\00"
@.str.5 = [18 x i8] c"write (mkNTPconf)\00"
define void @mkNTPconf(i32* %0) {
%2 = alloca i32*
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
store i32* %0, i32** %2
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%8 = call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%10 = call i32 @strcat(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%12 = call i32 @strcat(i8* %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%14 = load i32, i32* @S_IRUSR
%15 = load i32, i32* @S_IWUSR
%16 = or i32 %14, %15
%17 = load i32, i32* @S_IRGRP
%18 = or i32 %16, %17
%19 = load i32, i32* @S_IROTH
%20 = or i32 %18, %19
%21 = call i32 @creat(i8* %13, i32 %20)
store i32 %21, i32* %4
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %1
%24 = call i32 @logSysRet(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %64
25: ; preds = %1
%26 = load i32*, i32** %2
%27 = getelementptr inbounds i32, i32* %26, i64 1
store i32* %27, i32** %6
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
store i8 0, i8* %28
store i32 0, i32* %5
br label %29
29: ; preds = %49, %25
%30 = load i32, i32* %5
%31 = load i32*, i32** %2
%32 = load i32, i32* %31
%33 = sdiv i32 %32, 4
%34 = icmp slt i32 %30, %33
br i1 %34, label %35, label %52
35: ; preds = %29
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%38 = call i32 @strlen(i8* %37)
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %36, i64 %39
%41 = load i32*, i32** %6
%42 = bitcast i32* %41 to %struct.in_addr*
%43 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %42, i32 0, i32 0
%44 = load i32, i32* %43
%45 = call i8* @inet_ntoa(i32 %44)
%46 = call i32 @sprintf(i8* %40, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %45)
%47 = load i32*, i32** %6
%48 = getelementptr inbounds i32, i32* %47, i32 1
store i32* %48, i32** %6
br label %49
49: ; preds = %35
%50 = load i32, i32* %5
%51 = add nsw i32 %50, 1
store i32 %51, i32* %5
br label %29
52: ; preds = %29
%53 = load i32, i32* %4
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%55 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%56 = call i32 @strlen(i8* %55)
%57 = call i64 @write(i32 %53, i8* %54, i32 %56)
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %52
%60 = call i32 @logSysRet(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %61
61: ; preds = %59, %52
%62 = load i32, i32* %4
%63 = call i32 @close(i32 %62)
br label %64
64: ; preds = %61, %23
ret void
}

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