#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*/ value;
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ setenv(char *, char *, int);
void setenv_number(char *name, uint16_t num) {
  char value[6];
  char *value_ptr = &value[sizeof(value) - 1];
  *value_ptr = '\0';
  while (num > 0) {
    *--value_ptr = num % 10;
    num /= 10;
  }
  setenv(name, value_ptr, 1);
}


x86 assembly (clang, -O0):
<setenv_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x12(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
cmpl   $0x0,-0xc(%rbp)
jle    116e <setenv_number+0x5e>
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %dl,%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,-0x1(%rax)
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
jmp    1132 <setenv_number+0x22>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setenv_number>:
push   %rax
mov    %esi,%r9d
lea    0x7(%rsp),%rsi
movb   $0x0,0x7(%rsp)
test   %r9d,%r9d
jle    1156 <setenv_number+0x46>
mov    $0xcccccccd,%r8d
nopl   0x0(%rax)
mov    %r9d,%edx
imul   %r8,%rdx
shr    $0x23,%rdx
lea    (%rdx,%rdx,1),%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %r9d,%eax
sub    %ecx,%eax
mov    %al,-0x1(%rsi)
add    $0xffffffffffffffff,%rsi
cmp    $0x9,%r9d
mov    %edx,%r9d
ja     1130 <setenv_number+0x20>
mov    $0x1,%edx
call   1030 <setenv@plt>
pop    %rax
ret

LLVM IR (-O0):
define void @setenv_number(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [6 x i8]
%6 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 5
store i8* %7, i8** %6
%8 = load i8*, i8** %6
store i8 0, i8* %8
br label %9
9: ; preds = %12, %2
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %9
%13 = load i32, i32* %4
%14 = srem i32 %13, 10
%15 = trunc i32 %14 to i8
%16 = load i8*, i8** %6
%17 = getelementptr inbounds i8, i8* %16, i32 -1
store i8* %17, i8** %6
store i8 %15, i8* %17
%18 = load i32, i32* %4
%19 = sdiv i32 %18, 10
store i32 %19, i32* %4
br label %9
20: ; preds = %9
%21 = load i8*, i8** %3
%22 = load i8*, i8** %6
%23 = call i32 @setenv(i8* %21, i8* %22, i32 1)
ret void
}

LLVM IR (-O2):
define void @setenv_number(i8* %0, i32 %1) {
%3 = alloca [6 x i8]
%4 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 5
store i8 0, i8* %5
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %15
7: ; preds = %2, %7
%8 = phi i8* [ %12, %7 ], [ %5, %2 ]
%9 = phi i32 [ %13, %7 ], [ %1, %2 ]
%10 = urem i32 %9, 10
%11 = trunc i32 %10 to i8
%12 = getelementptr inbounds i8, i8* %8, i64 -1
store i8 %11, i8* %12
%13 = udiv i32 %9, 10
%14 = icmp ult i32 %9, 10
br i1 %14, label %15, label %7
15: ; preds = %7, %2
%16 = phi i8* [ %5, %2 ], [ %12, %7 ]
%17 = call i32 @setenv(i8* %0, i8* %16, i32 1)
ret void
}