#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 utsname {
  int /*<<< orphan*/ release;
};

/* Variables and functions */
int /*<<< orphan*/ SYS_uname;
scalar_t__ getenv(char *);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int syscall(int /*<<< orphan*/, struct utsname *);
int uname(struct utsname *buf) {
  int ret;
  ret = syscall(SYS_uname, buf);
  char *fake_kern_ver = NULL;
  fake_kern_ver = (char *)getenv("FAKE_KERN");
  if (fake_kern_ver != NULL) {
    strcpy(buf->release, fake_kern_ver);
  }
  return ret;
}


x86 assembly (clang, -O0):
<uname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ea5(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
call   1050 <syscall@plt>
mov    %eax,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xea0(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1183 <uname+0x53>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uname>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2eab(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
call   1050 <syscall@plt>
mov    %eax,%ebp
lea    0xeb0(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1164 <uname+0x34>
mov    (%rbx),%edi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.utsname = type { i32 }
@SYS_uname = global i32 0
@.str = [10 x i8] c"FAKE_KERN\00"
define i32 @uname(%struct.utsname* %0) {
%2 = alloca %struct.utsname*
%3 = alloca i32
%4 = alloca i8*
store %struct.utsname* %0, %struct.utsname** %2
%5 = load i32, i32* @SYS_uname
%6 = load %struct.utsname*, %struct.utsname** %2
%7 = call i32 @syscall(i32 %5, %struct.utsname* %6)
store i32 %7, i32* %3
store i8* null, i8** %4
%8 = call i64 @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %4
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %18
12: ; preds = %1
%13 = load %struct.utsname*, %struct.utsname** %2
%14 = getelementptr inbounds %struct.utsname, %struct.utsname* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = load i8*, i8** %4
%17 = call i32 @strcpy(i32 %15, i8* %16)
br label %18
18: ; preds = %12, %1
%19 = load i32, i32* %3
ret i32 %19
}

LLVM IR (-O2):
%struct.utsname = type { i32 }
@SYS_uname = global i32 0
@.str = [10 x i8] c"FAKE_KERN\00"
define i32 @uname(%struct.utsname* %0) {
%2 = load i32, i32* @SYS_uname
%3 = tail call i32 @syscall(i32 %2, %struct.utsname* %0)
%4 = tail call i64 @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %1
%7 = inttoptr i64 %4 to i8*
%8 = getelementptr inbounds %struct.utsname, %struct.utsname* %0, i64 0, i32 0
%9 = load i32, i32* %8
%10 = tail call i32 @strcpy(i32 %9, i8* %7)
br label %11
11: ; preds = %6, %1
ret i32 %3
}