#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *);
char *malloc(size_t const);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
size_t strlen(char const *);
char *alloc_envar(const char *varname, const char *value) {
  const size_t varname_size = strlen(varname);
  const size_t value_size = strlen(value);
  const size_t buf_size = varname_size + 1 + value_size + 1;
  char *result_buf = malloc(buf_size);
  do {
    if (!(result_buf != NULL)) {
      fprintf(stderr, "%s:%d: Assertion failed: %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/gphoto/gphoto2/refs/heads/master/"
              "gphoto2/spawntest.c",
              48, "result_buf != NULL");
      exit(13);
    }
  } while (0);
  strcpy(result_buf, varname);
  strcat(result_buf, "=");
  strcat(result_buf, value);
  return result_buf;
}


x86 assembly (clang, -O0):
<alloc_envar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
add    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11e8 <alloc_envar+0x88>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xe3a(%rip),%rsi
lea    0xe50(%rip),%rdx
mov    $0x30,%ecx
lea    0xed3(%rip),%r8
call   1050 <fprintf@plt>
mov    $0xd,%edi
call   1080 <exit@plt>
jmp    11ed <alloc_envar+0x8d>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rdi
lea    0xeba(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc_envar>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x2,%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     11be <alloc_envar+0x5e>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
lea    0xf1d(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    0xe32(%rip),%rsi
lea    0xe48(%rip),%rdx
lea    0xed0(%rip),%r8
mov    $0x30,%ecx
call   1050 <fprintf@plt>
mov    $0xd,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"%s:%d: Assertion failed: %s\0A\00"
@.str.1 = [143 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/gphoto/gphoto2/refs/heads/master/gphoto2/spawntest.c\00"
@.str.2 = [19 x i8] c"result_buf != NULL\00"
@.str.3 = [2 x i8] c"=\00"
define i8* @alloc_envar(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %5
%11 = load i8*, i8** %4
%12 = call i64 @strlen(i8* %11)
store i64 %12, i64* %6
%13 = load i64, i64* %5
%14 = add i64 %13, 1
%15 = load i64, i64* %6
%16 = add i64 %14, %15
%17 = add i64 %16, 1
store i64 %17, i64* %7
%18 = load i64, i64* %7
%19 = call i8* @malloc(i64 %18)
store i8* %19, i8** %8
br label %20
20: ; preds = %2
%21 = load i8*, i8** %8
%22 = icmp ne i8* %21, null
br i1 %22, label %27, label %23
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.1, i64 0, i64 0), i32 48, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @exit(i32 13)
unreachable
27: ; preds = %20
br label %28
28: ; preds = %27
%29 = load i8*, i8** %8
%30 = load i8*, i8** %3
%31 = call i32 @strcpy(i8* %29, i8* %30)
%32 = load i8*, i8** %8
%33 = call i32 @strcat(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%34 = load i8*, i8** %8
%35 = load i8*, i8** %4
%36 = call i32 @strcat(i8* %34, i8* %35)
%37 = load i8*, i8** %8
ret i8* %37
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"%s:%d: Assertion failed: %s\0A\00"
@.str.1 = [143 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/gphoto/gphoto2/refs/heads/master/gphoto2/spawntest.c\00"
@.str.2 = [19 x i8] c"result_buf != NULL\00"
@.str.3 = [2 x i8] c"=\00"
define i8* @alloc_envar(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = add i64 %3, 2
%6 = add i64 %5, %4
%7 = tail call i8* @malloc(i64 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.1, i64 0, i64 0), i32 48, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%12 = tail call i32 @exit(i32 13)
unreachable
13: ; preds = %2
%14 = tail call i32 @strcpy(i8* %7, i8* %0)
%15 = tail call i32 @strcat(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%16 = tail call i32 @strcat(i8* %7, i8* %1)
ret i8* %7
}