#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 stat {
  int st_mode;
  scalar_t__ st_size;
  int /*<<< orphan*/ st_rdev;
};

/* Variables and functions */
#define S_IFBLK 129
#define S_IFCHR 128
int S_IFMT;
int /*<<< orphan*/ sprintf(char *, char *, int);
void getsizeid(struct stat *s, char *sizeid) {
  switch (s->st_mode & S_IFMT) {
  case S_IFCHR:
  case S_IFBLK:
    sprintf(sizeid, "0x%x", (unsigned)s->st_rdev);
    break;
  default:
    sprintf(sizeid, "%d", (int)s->st_size);
    break;
  }
}


x86 assembly (clang, -O0):
<getsizeid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    0x2eb3(%rip),%rcx
mov    (%rcx),%ecx
and    %ecx,%eax
add    $0xffffff80,%eax
sub    $0x1,%eax
ja     115e <getsizeid+0x4e>
jmp    1142 <getsizeid+0x32>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%edx
lea    0xeac(%rip),%rsi
call   1030 <sprintf@plt>
jmp    1178 <getsizeid+0x68>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %eax,%edx
lea    0xe92(%rip),%rsi
call   1030 <sprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getsizeid>:
mov    %rsi,%rax
mov    (%rdi),%ecx
mov    0x2ec4(%rip),%rdx
and    (%rdx),%ecx
and    $0xfffffffe,%ecx
cmp    $0x80,%ecx
jne    113b <getsizeid+0x2b>
mov    0x10(%rdi),%edx
lea    0xecd(%rip),%rsi
mov    %rax,%rdi
jmp    1030 <sprintf@plt>
mov    0x8(%rdi),%edx
lea    0xec0(%rip),%rsi
mov    %rax,%rdi
jmp    1030 <sprintf@plt>

LLVM IR (-O0):
%struct.stat = type { i32, i64, i32 }
@S_IFMT = global i32 0
@.str = [5 x i8] c"0x%x\00"
@.str.1 = [3 x i8] c"%d\00"
define void @getsizeid(%struct.stat* %0, i8* %1) {
%3 = alloca %struct.stat*
%4 = alloca i8*
store %struct.stat* %0, %struct.stat** %3
store i8* %1, i8** %4
%5 = load %struct.stat*, %struct.stat** %3
%6 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%7 = load i32, i32* %6
%8 = load i32, i32* @S_IFMT
%9 = and i32 %7, %8
switch i32 %9, label %16 [
i32 128, label %10
i32 129, label %10
]
10: ; preds = %2, %2
%11 = load i8*, i8** %4
%12 = load %struct.stat*, %struct.stat** %3
%13 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 2
%14 = load i32, i32* %13
%15 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %14)
br label %23
16: ; preds = %2
%17 = load i8*, i8** %4
%18 = load %struct.stat*, %struct.stat** %3
%19 = getelementptr inbounds %struct.stat, %struct.stat* %18, i32 0, i32 1
%20 = load i64, i64* %19
%21 = trunc i64 %20 to i32
%22 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %16, %10
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32, i64, i32 }
@S_IFMT = global i32 0
@.str = [5 x i8] c"0x%x\00"
@.str.1 = [3 x i8] c"%d\00"
define void @getsizeid(%struct.stat* nocapture %0, i8* nocapture writeonly %1) {
%3 = getelementptr inbounds %struct.stat, %struct.stat* %0, i64 0, i32 0
%4 = load i32, i32* %3
%5 = load i32, i32* @S_IFMT
%6 = and i32 %4, -2
%7 = and i32 %6, %5
%8 = icmp eq i32 %7, 128
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = getelementptr inbounds %struct.stat, %struct.stat* %0, i64 0, i32 2
%11 = load i32, i32* %10
%12 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %11)
br label %18
13: ; preds = %2
%14 = getelementptr inbounds %struct.stat, %struct.stat* %0, i64 0, i32 1
%15 = load i64, i64* %14
%16 = trunc i64 %15 to i32
%17 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %13, %9
ret void
}