#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 */
struct in_addr {
  int dummy;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, struct in_addr const *, char *,
                             int);
scalar_t__ malloc(int);
int /*<<< orphan*/ putenv(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, unsigned int);
void set_server(const struct in_addr *ip, unsigned port) {
  char buf[16];
  char *env = (char *)malloc(sizeof(buf) + sizeof("MAT_SERVER=tcp://:nnnnn"));
  inet_ntop(AF_INET, ip, buf, sizeof(buf));
  sprintf(env, "MAT_SERVER=tcp://%s:%u", buf, port);
  putenv(env);
}


x86 assembly (clang, -O0):
<set_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
lea    -0x20(%rbp),%rdx
mov    $0x10,%ecx
call   1030 <inet_ntop@plt>
mov    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0xe76(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <putenv@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_server>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,%rbp
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%r15
mov    %rbx,%rsi
mov    %r15,%rdx
mov    $0x10,%ecx
call   1030 <inet_ntop@plt>
lea    0xe80(%rip),%rsi
mov    %rbp,%rdi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1060 <sprintf@plt>
mov    %rbp,%rdi
call   1040 <putenv@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@AF_INET = global i32 0
@.str = [23 x i8] c"MAT_SERVER=tcp://%s:%u\00"
define void @set_server(%struct.in_addr* %0, i32 %1) {
%3 = alloca %struct.in_addr*
%4 = alloca i32
%5 = alloca [16 x i8]
%6 = alloca i8*
store %struct.in_addr* %0, %struct.in_addr** %3
store i32 %1, i32* %4
%7 = call i64 @malloc(i32 40)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %6
%9 = load i32, i32* @AF_INET
%10 = load %struct.in_addr*, %struct.in_addr** %3
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%12 = call i32 @inet_ntop(i32 %9, %struct.in_addr* %10, i8* %11, i32 16)
%13 = load i8*, i8** %6
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%15 = load i32, i32* %4
%16 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %14, i32 %15)
%17 = load i8*, i8** %6
%18 = call i32 @putenv(i8* %17)
ret void
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
@AF_INET = global i32 0
@.str = [23 x i8] c"MAT_SERVER=tcp://%s:%u\00"
define void @set_server(%struct.in_addr* %0, i32 %1) {
%3 = alloca [16 x i8]
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%5 = tail call i64 @malloc(i32 40)
%6 = inttoptr i64 %5 to i8*
%7 = load i32, i32* @AF_INET
%8 = call i32 @inet_ntop(i32 %7, %struct.in_addr* %0, i8* %4, i32 16)
%9 = call i32 @sprintf(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %4, i32 %1)
%10 = call i32 @putenv(i8* %6)
ret void
}