#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*/ snprintf(char *, size_t, char *, int, int);
int /*<<< orphan*/ sscanf(int /*<<< orphan*/, char *, int *, int *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
int uname(struct utsname *);
void get_os(char *buffer, size_t size) {
  struct utsname name;
  if (uname(&name) != -1) {
    int major = 0, minor = 0;
    sscanf(name.release, "%d.%d.", &major, &minor);
    snprintf(buffer, size, "OS X 10.%d.%d", major - 4, minor);
  } else
    strncpy(buffer, "unknown OS X", size);
}


x86 assembly (clang, -O0):
<get_os>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <uname@plt>
cmp    $0xffffffff,%eax
je     11aa <get_os+0x6a>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%edi
lea    0xe86(%rip),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1060 <sscanf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%ecx
sub    $0x4,%ecx
mov    -0x20(%rbp),%r8d
lea    0xe67(%rip),%rdx
call   1040 <snprintf@plt>
jmp    11be <get_os+0x7e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe5c(%rip),%rsi
call   1030 <strncpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_os>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x10(%rsp),%rdi
call   1050 <uname@plt>
cmp    $0xffffffff,%eax
je     11ac <get_os+0x6c>
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
mov    0x10(%rsp),%edi
lea    0xe89(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
call   1060 <sscanf@plt>
mov    0xc(%rsp),%ecx
add    $0xfffffffc,%ecx
mov    0x8(%rsp),%r8d
lea    0xe6e(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <snprintf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe62(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
add    $0x18,%rsp
pop    %rbx
pop    %r14
jmp    1030 <strncpy@plt>

LLVM IR (-O0):
%struct.utsname = type { i32 }
@.str = [7 x i8] c"%d.%d.\00"
@.str.1 = [14 x i8] c"OS X 10.%d.%d\00"
@.str.2 = [13 x i8] c"unknown OS X\00"
define void @get_os(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca %struct.utsname
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
%8 = call i32 @uname(%struct.utsname* %5)
%9 = icmp ne i32 %8, -1
br i1 %9, label %10, label %20
10: ; preds = %2
store i32 0, i32* %6
store i32 0, i32* %7
%11 = getelementptr inbounds %struct.utsname, %struct.utsname* %5, i32 0, i32 0
%12 = load i32, i32* %11
%13 = call i32 @sscanf(i32 %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %6, i32* %7)
%14 = load i8*, i8** %3
%15 = load i64, i64* %4
%16 = load i32, i32* %6
%17 = sub nsw i32 %16, 4
%18 = load i32, i32* %7
%19 = call i32 @snprintf(i8* %14, i64 %15, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %18)
br label %24
20: ; preds = %2
%21 = load i8*, i8** %3
%22 = load i64, i64* %4
%23 = call i32 @strncpy(i8* %21, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i64 %22)
br label %24
24: ; preds = %20, %10
ret void
}

LLVM IR (-O2):
%struct.utsname = type { i32 }
@.str = [7 x i8] c"%d.%d.\00"
@.str.1 = [14 x i8] c"OS X 10.%d.%d\00"
@.str.2 = [13 x i8] c"unknown OS X\00"
define void @get_os(i8* %0, i64 %1) {
%3 = alloca %struct.utsname
%4 = alloca i32
%5 = alloca i32
%6 = bitcast %struct.utsname* %3 to i8*
%7 = call i32 @uname(%struct.utsname* %3)
%8 = icmp eq i32 %7, -1
br i1 %8, label %19, label %9
9: ; preds = %2
%10 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%11 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%12 = getelementptr inbounds %struct.utsname, %struct.utsname* %3, i64 0, i32 0
%13 = load i32, i32* %12
%14 = call i32 @sscanf(i32 %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %4, i32* %5)
%15 = load i32, i32* %4
%16 = add nsw i32 %15, -4
%17 = load i32, i32* %5
%18 = call i32 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %17)
br label %21
19: ; preds = %2
%20 = tail call i32 @strncpy(i8* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i64 %1)
br label %21
21: ; preds = %19, %9
ret void
}