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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int strlen(char *);
int write_hmconfig(char *cfgfile, char *hmconfig) {
  FILE *f;
  if ((f = fopen(cfgfile, "wb"))) {
    int len = strlen(hmconfig);
    if (len && (hmconfig[len - 1] == ' '))
      len--;
    fwrite(hmconfig, 1, len, f);
    fclose(f);
  } else
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<write_hmconfig>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11ca <write_hmconfig+0x8a>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11a7 <write_hmconfig+0x67>
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    11a7 <write_hmconfig+0x67>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11d6 <write_hmconfig+0x96>
movl   $0x1,-0x4(%rbp)
jmp    11dd <write_hmconfig+0x9d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_hmconfig>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
lea    0xeb2(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1198 <write_hmconfig+0x58>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
xor    %ebp,%ebp
mov    $0x0,%edx
test   %eax,%eax
je     117e <write_hmconfig+0x3e>
movslq %eax,%rcx
lea    -0x1(%rcx),%rdx
cmpb   $0x20,-0x1(%r14,%rcx,1)
cmovne %eax,%edx
mov    %r14,%rdi
mov    $0x1,%esi
mov    %rbx,%rcx
call   1060 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    119d <write_hmconfig+0x5d>
mov    $0x1,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
define i32 @write_hmconfig(i8* nocapture %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %19, label %5
5: ; preds = %2
%6 = tail call i32 @strlen(i8* %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %15, label %8
8: ; preds = %5
%9 = add nsw i32 %6, -1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %1, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 32
%14 = select i1 %13, i32 %9, i32 %6
br label %15
15: ; preds = %8, %5
%16 = phi i32 [ 0, %5 ], [ %14, %8 ]
%17 = tail call i32 @fwrite(i8* %1, i32 1, i32 %16, i32* %3)
%18 = tail call i32 @fclose(i32* %3)
br label %19
19: ; preds = %2, %15
%20 = phi i32 [ 0, %15 ], [ 1, %2 ]
ret i32 %20
}