#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*/ printf(char *, char *, char *);
int strlen(char *);
int write(int, char *, int);
int writeConfig(int fd, char *config, char *contents) {
  int ret = 0;
  if (write(fd, config, strlen(config)) != strlen(config)) {
    ret = -1;
  }
  if (write(fd, contents, strlen(contents)) != strlen(contents)) {
    ret = -1;
  }
  if (write(fd, "\n", 1) != 1) {
    ret = -1;
  }
  if (ret == -1) {
    printf("ERROR: write %s%s\n", config, contents);
  }
  return ret;
}


x86 assembly (clang, -O0):
<writeConfig>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
je     118f <writeConfig+0x5f>
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
cmp    %ecx,%eax
je     11d4 <writeConfig+0xa4>
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
lea    0xe33(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
je     11f8 <writeConfig+0xc8>
movl   $0xffffffff,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1216 <writeConfig+0xe6>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xdef(%rip),%rdi
call   1050 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeConfig>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%r12d
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %r12d,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
xor    %ebp,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %r12d,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,%r13d
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
xor    %r13d,%ebp
lea    0xe7e(%rip),%rsi
mov    %r12d,%edi
mov    $0x1,%edx
call   1030 <write@plt>
xor    $0x1,%eax
or     %ebp,%eax
xor    %ebp,%ebp
or     %ebx,%eax
setne  %bl
je     11c0 <writeConfig+0x90>
lea    0xe4b(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1050 <printf@plt>
mov    %bl,%bpl
neg    %ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [19 x i8] c"ERROR: write %s%s\0A\00"
define i32 @writeConfig(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 0, i32* %7
%8 = load i32, i32* %4
%9 = load i8*, i8** %5
%10 = load i8*, i8** %5
%11 = call i32 @strlen(i8* %10)
%12 = call i32 @write(i32 %8, i8* %9, i32 %11)
%13 = load i8*, i8** %5
%14 = call i32 @strlen(i8* %13)
%15 = icmp ne i32 %12, %14
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 -1, i32* %7
br label %17
17: ; preds = %16, %3
%18 = load i32, i32* %4
%19 = load i8*, i8** %6
%20 = load i8*, i8** %6
%21 = call i32 @strlen(i8* %20)
%22 = call i32 @write(i32 %18, i8* %19, i32 %21)
%23 = load i8*, i8** %6
%24 = call i32 @strlen(i8* %23)
%25 = icmp ne i32 %22, %24
br i1 %25, label %26, label %27
26: ; preds = %17
store i32 -1, i32* %7
br label %27
27: ; preds = %26, %17
%28 = load i32, i32* %4
%29 = call i32 @write(i32 %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%30 = icmp ne i32 %29, 1
br i1 %30, label %31, label %32
31: ; preds = %27
store i32 -1, i32* %7
br label %32
32: ; preds = %31, %27
%33 = load i32, i32* %7
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %39
35: ; preds = %32
%36 = load i8*, i8** %5
%37 = load i8*, i8** %6
%38 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %36, i8* %37)
br label %39
39: ; preds = %35, %32
%40 = load i32, i32* %7
ret i32 %40
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [19 x i8] c"ERROR: write %s%s\0A\00"
define i32 @writeConfig(i32 %0, i8* %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %1)
%5 = tail call i32 @write(i32 %0, i8* %1, i32 %4)
%6 = tail call i32 @strlen(i8* %1)
%7 = icmp ne i32 %5, %6
%8 = tail call i32 @strlen(i8* %2)
%9 = tail call i32 @write(i32 %0, i8* %2, i32 %8)
%10 = tail call i32 @strlen(i8* %2)
%11 = icmp ne i32 %9, %10
%12 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%13 = icmp ne i32 %12, 1
%14 = select i1 %13, i1 true, i1 %11
%15 = select i1 %14, i1 true, i1 %7
br i1 %15, label %16, label %18
16: ; preds = %3
%17 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %2)
br label %18
18: ; preds = %16, %3
%19 = sext i1 %15 to i32
ret i32 %19
}