#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*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
void putstr(char *key, char *val, FILE *fp) {
  char *savestr = malloc(strlen(key) + strlen(val) + 3);
  if (!savestr) {
    fprintf(stderr, "%s\n", strerror(errno));
    exit(1);
  }
  memset(savestr, 0, strlen(key) + strlen(val) + 3);
  strncpy(savestr, key, strlen(key));
  strncat(savestr, "=", 1);
  strncat(savestr, val, strlen(val));
  strncat(savestr, "\n", 1);
  if (!fputs(savestr, fp)) {
    fprintf(stderr, "%s\n", strerror(errno));
  }
  free(savestr);
}


x86 assembly (clang, -O0):
<putstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x24(%rbp),%edi
add    %eax,%edi
add    $0x3,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    121b <putstr+0x7b>
mov    0x2df4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x28(%rbp),%edi
mov    %rax,%rdx
lea    0xdf4(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x54(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x54(%rbp),%edx
mov    -0x50(%rbp),%rdi
add    %eax,%edx
add    $0x3,%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
call   1040 <strncpy@plt>
mov    -0x20(%rbp),%rdi
lea    0xd86(%rip),%rsi
mov    $0x1,%edx
call   1080 <strncat@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1080 <strncat@plt>
mov    -0x20(%rbp),%rdi
lea    0xd47(%rip),%rsi
mov    $0x1,%edx
call   1080 <strncat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <fputs@plt>
cmp    $0x0,%eax
jne    1307 <putstr+0x167>
mov    0x2cfe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    0x2cea(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x58(%rbp),%edi
mov    %rax,%rdx
lea    0xcfe(%rip),%rsi
call   1090 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putstr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x3,%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     129d <putstr+0xfd>
mov    %rax,%rbx
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %eax,%r13d
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    (%rax,%r13,1),%edx
add    $0x3,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1040 <strncpy@plt>
lea    0xdea(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1,%edx
call   1080 <strncat@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1080 <strncat@plt>
lea    0xdbf(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1,%edx
call   1080 <strncat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <fputs@plt>
test   %eax,%eax
jne    1287 <putstr+0xe7>
mov    0x2d7a(%rip),%rax
mov    (%rax),%ebp
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xd83(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   1090 <fprintf@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
mov    0x2d3c(%rip),%rax
mov    (%rax),%ebx
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xd45(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@errno = global i32 0
@.str.1 = [2 x i8] c"=\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @putstr(i8* %0, i8* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* %2, i32** %6
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
%10 = load i8*, i8** %5
%11 = call i32 @strlen(i8* %10)
%12 = add nsw i32 %9, %11
%13 = add nsw i32 %12, 3
%14 = call i8* @malloc(i32 %13)
store i8* %14, i8** %7
%15 = load i8*, i8** %7
%16 = icmp ne i8* %15, null
br i1 %16, label %23, label %17
17: ; preds = %3
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %3
%24 = load i8*, i8** %7
%25 = load i8*, i8** %4
%26 = call i32 @strlen(i8* %25)
%27 = load i8*, i8** %5
%28 = call i32 @strlen(i8* %27)
%29 = add nsw i32 %26, %28
%30 = add nsw i32 %29, 3
%31 = call i32 @memset(i8* %24, i32 0, i32 %30)
%32 = load i8*, i8** %7
%33 = load i8*, i8** %4
%34 = load i8*, i8** %4
%35 = call i32 @strlen(i8* %34)
%36 = call i32 @strncpy(i8* %32, i8* %33, i32 %35)
%37 = load i8*, i8** %7
%38 = call i32 @strncat(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%39 = load i8*, i8** %7
%40 = load i8*, i8** %5
%41 = load i8*, i8** %5
%42 = call i32 @strlen(i8* %41)
%43 = call i32 @strncat(i8* %39, i8* %40, i32 %42)
%44 = load i8*, i8** %7
%45 = call i32 @strncat(i8* %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%46 = load i8*, i8** %7
%47 = load i32*, i32** %6
%48 = call i32 @fputs(i8* %46, i32* %47)
%49 = icmp ne i32 %48, 0
br i1 %49, label %55, label %50
50: ; preds = %23
%51 = load i32, i32* @stderr
%52 = load i32, i32* @errno
%53 = call i8* @strerror(i32 %52)
%54 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %53)
br label %55
55: ; preds = %50, %23
%56 = load i8*, i8** %7
%57 = call i32 @free(i8* %56)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@errno = global i32 0
@.str.1 = [2 x i8] c"=\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @putstr(i8* %0, i8* %1, i32* nocapture %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i32 @strlen(i8* %1)
%6 = add i32 %4, 3
%7 = add i32 %6, %5
%8 = tail call i8* @malloc(i32 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %16
10: ; preds = %3
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = tail call i8* @strerror(i32 %12)
%14 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %3
%17 = tail call i32 @strlen(i8* %0)
%18 = tail call i32 @strlen(i8* %1)
%19 = add i32 %17, 3
%20 = add i32 %19, %18
%21 = tail call i32 @memset(i8* %8, i32 0, i32 %20)
%22 = tail call i32 @strlen(i8* %0)
%23 = tail call i32 @strncpy(i8* %8, i8* %0, i32 %22)
%24 = tail call i32 @strncat(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%25 = tail call i32 @strlen(i8* %1)
%26 = tail call i32 @strncat(i8* %8, i8* %1, i32 %25)
%27 = tail call i32 @strncat(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%28 = tail call i32 @fputs(i8* %8, i32* %2)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %16
%31 = load i32, i32* @stderr
%32 = load i32, i32* @errno
%33 = tail call i8* @strerror(i32 %32)
%34 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %30, %16
%36 = tail call i32 @free(i8* %8)
ret void
}