#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 O_CREAT;
int O_TRUNC;
int O_WRONLY;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void generate_ntp_conf(char *server) {
  int fd;
  char *boilerplate = "restrict -4 default kod notrap nomodify nopeer noquery\n"
                      "restrict -6 default kod notrap nomodify nopeer noquery\n"
                      "restrict 127.0.0.1\n"
                      "restrict ::1\n";
  char buf[256];
  sprintf(buf, "server %s %s\n", server, "");
  fd = open("/tmp/myntp.conf", O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR);
  if (fd < 0)
    exit(-1);
  write(fd, buf, strlen(buf));
  write(fd, boilerplate, strlen(boilerplate));
  close(fd);
  fd =
      open("/tmp/myntp.drift", O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR);
  close(fd);
}


x86 assembly (clang, -O0):
<generate_ntp_conf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe8a(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xf03(%rip),%rsi
lea    0xefb(%rip),%rcx
call   1070 <sprintf@plt>
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
mov    0x2e48(%rip),%rax
or     (%rax),%esi
mov    0x2e07(%rip),%rax
or     (%rax),%esi
mov    0x2e0e(%rip),%rax
mov    (%rax),%edx
mov    0x2e15(%rip),%rax
or     (%rax),%edx
lea    0xed1(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11e8 <generate_ntp_conf+0x88>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x13c(%rbp)
lea    -0x120(%rbp),%rax
mov    %rax,-0x138(%rbp)
lea    -0x120(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x13c(%rbp),%edi
mov    -0x138(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x12c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x128(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x12c(%rbp),%edi
mov    -0x128(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
mov    0x2d99(%rip),%rax
mov    (%rax),%esi
mov    0x2d88(%rip),%rax
or     (%rax),%esi
mov    0x2d47(%rip),%rax
or     (%rax),%esi
mov    0x2d4e(%rip),%rax
mov    (%rax),%edx
mov    0x2d55(%rip),%rax
or     (%rax),%edx
lea    0xe21(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_ntp_conf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%rdx
lea    0xf14(%rip),%rsi
lea    0xf0c(%rip),%rcx
mov    %rsp,%rdi
call   1070 <sprintf@plt>
mov    0x2e67(%rip),%rax
mov    0x2e58(%rip),%r12
mov    (%r12),%esi
or     (%rax),%esi
mov    0x2e13(%rip),%r13
or     0x0(%r13),%esi
mov    0x2e18(%rip),%rbp
mov    0x2e21(%rip),%r15
mov    (%r15),%edx
or     0x0(%rbp),%edx
lea    0xed9(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     1244 <generate_ntp_conf+0xe4>
mov    %eax,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    0xe13(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1050 <close@plt>
mov    (%r12),%esi
mov    0x2de5(%rip),%rax
or     (%rax),%esi
or     0x0(%r13),%esi
mov    (%r15),%edx
or     0x0(%rbp),%edx
lea    0xe87(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%edi
call   1050 <close@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [143 x i8] c"restrict -4 default kod notrap nomodify nopeer noquery\0Arestrict -6 default kod notrap nomodify nopeer noquery\0Arestrict 127.0.0.1\0Arestrict ::1\0A\00"
@.str.1 = [14 x i8] c"server %s %s\0A\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [16 x i8] c"/tmp/myntp.conf\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_WRONLY = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.4 = [17 x i8] c"/tmp/myntp.drift\00"
define void @generate_ntp_conf(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [256 x i8]
store i8* %0, i8** %2
store i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str, i64 0, i64 0), i8** %4
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%7 = load i8*, i8** %2
%8 = call i32 @sprintf(i8* %6, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %7, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%9 = load i32, i32* @O_CREAT
%10 = load i32, i32* @O_TRUNC
%11 = or i32 %9, %10
%12 = load i32, i32* @O_WRONLY
%13 = or i32 %11, %12
%14 = load i32, i32* @S_IRUSR
%15 = load i32, i32* @S_IWUSR
%16 = or i32 %14, %15
%17 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %13, i32 %16)
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %1
%21 = call i32 @exit(i32 -1)
unreachable
22: ; preds = %1
%23 = load i32, i32* %3
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%26 = call i32 @strlen(i8* %25)
%27 = call i32 @write(i32 %23, i8* %24, i32 %26)
%28 = load i32, i32* %3
%29 = load i8*, i8** %4
%30 = load i8*, i8** %4
%31 = call i32 @strlen(i8* %30)
%32 = call i32 @write(i32 %28, i8* %29, i32 %31)
%33 = load i32, i32* %3
%34 = call i32 @close(i32 %33)
%35 = load i32, i32* @O_CREAT
%36 = load i32, i32* @O_TRUNC
%37 = or i32 %35, %36
%38 = load i32, i32* @O_WRONLY
%39 = or i32 %37, %38
%40 = load i32, i32* @S_IRUSR
%41 = load i32, i32* @S_IWUSR
%42 = or i32 %40, %41
%43 = call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %39, i32 %42)
store i32 %43, i32* %3
%44 = load i32, i32* %3
%45 = call i32 @close(i32 %44)
ret void
}

LLVM IR (-O2):
@.str = [143 x i8] c"restrict -4 default kod notrap nomodify nopeer noquery\0Arestrict -6 default kod notrap nomodify nopeer noquery\0Arestrict 127.0.0.1\0Arestrict ::1\0A\00"
@.str.1 = [14 x i8] c"server %s %s\0A\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [16 x i8] c"/tmp/myntp.conf\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_WRONLY = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.4 = [17 x i8] c"/tmp/myntp.drift\00"
define void @generate_ntp_conf(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%5 = load i32, i32* @O_CREAT
%6 = load i32, i32* @O_TRUNC
%7 = or i32 %6, %5
%8 = load i32, i32* @O_WRONLY
%9 = or i32 %7, %8
%10 = load i32, i32* @S_IRUSR
%11 = load i32, i32* @S_IWUSR
%12 = or i32 %11, %10
%13 = tail call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %9, i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %1
%16 = tail call i32 @exit(i32 -1)
unreachable
17: ; preds = %1
%18 = call i32 @strlen(i8* %3)
%19 = call i32 @write(i32 %13, i8* %3, i32 %18)
%20 = call i32 @strlen(i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @write(i32 %13, i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = call i32 @close(i32 %13)
%23 = load i32, i32* @O_CREAT
%24 = load i32, i32* @O_TRUNC
%25 = or i32 %24, %23
%26 = load i32, i32* @O_WRONLY
%27 = or i32 %25, %26
%28 = load i32, i32* @S_IRUSR
%29 = load i32, i32* @S_IWUSR
%30 = or i32 %29, %28
%31 = call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %27, i32 %30)
%32 = call i32 @close(i32 %31)
ret void
}