#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*/ die_errno(char *, char const *, char *, int);
scalar_t__ setenv(char const *, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
void redo_setenv_int(const char *k, int v) {
  char buf[16];
  snprintf(buf, 16, "%d", v);
  if (setenv(k, buf, 1) != 0) {
    die_errno("setenv('%s', '%s', %d) failed", k, buf, 1);
  }
}


x86 assembly (clang, -O0):
<redo_setenv_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x10,%esi
lea    0xeae(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
cmp    $0x0,%rax
je     118c <redo_setenv_int+0x5c>
mov    -0x8(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    0xe81(%rip),%rdi
mov    $0x1,%ecx
call   1050 <die_errno@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<redo_setenv_int>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ecx
mov    %rdi,%rbx
lea    0xebd(%rip),%rdx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x10,%esi
call   1040 <snprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
test   %rax,%rax
je     117f <redo_setenv_int+0x4f>
lea    0xe94(%rip),%rdi
mov    %rsp,%rdx
mov    %rbx,%rsi
mov    $0x1,%ecx
call   1050 <die_errno@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [30 x i8] c"setenv('%s', '%s', %d) failed\00"
define void @redo_setenv_int(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [16 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%7 = load i32, i32* %4
%8 = call i32 @snprintf(i8* %6, i32 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i8*, i8** %3
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%11 = call i64 @setenv(i8* %9, i8* %10, i32 1)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i8*, i8** %3
%15 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%16 = call i32 @die_errno(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %14, i8* %15, i32 1)
br label %17
17: ; preds = %13, %2
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [30 x i8] c"setenv('%s', '%s', %d) failed\00"
define void @redo_setenv_int(i8* %0, i32 %1) {
%3 = alloca [16 x i8]
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%5 = call i32 @snprintf(i8* %4, i32 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %1)
%6 = call i64 @setenv(i8* %0, i8* %4, i32 1)
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = call i32 @die_errno(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %4, i32 1)
br label %10
10: ; preds = %8, %2
ret void
}