#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*/ FILE;

/* Variables and functions */
scalar_t__ EINVAL;
scalar_t__ ERANGE;
int _IOFBF;
int _IOLBF;
int _IONBF;
scalar_t__ errno;
scalar_t__ setvbuf(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int, size_t);
int /*<<< orphan*/ stream_name(int /*<<< orphan*/ *);
size_t strtol(char const *, char **, int /*<<< orphan*/);
int /*<<< orphan*/ warn(char *, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ warnx(char *, char, int /*<<< orphan*/);
void change_buf(FILE *s, const char *bufmode) {
  char *unit;
  size_t bufsize;
  int mode;
  bufsize = 0;
  if (bufmode[0] == '0' && bufmode[1] == '\0')
    mode = _IONBF;
  else if (bufmode[0] == 'L' && bufmode[1] == '\0')
    mode = _IOLBF;
  else if (bufmode[0] == 'B' && bufmode[1] == '\0') {
    mode = _IOFBF;
    bufsize = 0;
  } else {
    errno = 0;
    bufsize = strtol(bufmode, &unit, 0);
    if (errno == EINVAL || errno == ERANGE || unit == bufmode)
      warn("Wrong buffer mode '%s' for %s", bufmode, stream_name(s));
    switch (*unit) {
    case 'G':
      bufsize *= 1024 * 1024 * 1024;
      break;
    case 'M':
      bufsize *= 1024 * 1024;
      break;
    case 'k':
      bufsize *= 1024;
      break;
    case '\0':
      break;
    default:
      warnx("Unknown suffix '%c' for %s", *unit, stream_name(s));
      return;
    }
    mode = _IOFBF;
  }
  if (setvbuf(s, NULL, mode, bufsize) != 0)
    warn("Cannot set buffer mode '%s' for %s", bufmode, stream_name(s));
}


x86 assembly (clang, -O0):
<change_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    119a <change_buf+0x4a>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    119a <change_buf+0x4a>
mov    0x2e58(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    134f <change_buf+0x1ff>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x4c,%eax
jne    11cc <change_buf+0x7c>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    11cc <change_buf+0x7c>
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    134a <change_buf+0x1fa>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x42,%eax
jne    1206 <change_buf+0xb6>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    1206 <change_buf+0xb6>
mov    0x2dc4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
movq   $0x0,-0x20(%rbp)
jmp    1345 <change_buf+0x1f5>
mov    0x2dc3(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    0x2da2(%rip),%rax
mov    (%rax),%rax
mov    0x2d88(%rip),%rcx
cmp    (%rcx),%rax
je     1269 <change_buf+0x119>
mov    0x2d88(%rip),%rax
mov    (%rax),%rax
mov    0x2d8e(%rip),%rcx
cmp    (%rcx),%rax
je     1269 <change_buf+0x119>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    128c <change_buf+0x13c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <stream_name@plt>
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
lea    0xd79(%rip),%rdi
call   1030 <warn@plt>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x34(%rbp)
test   %eax,%eax
je     1309 <change_buf+0x1b9>
jmp    12a3 <change_buf+0x153>
mov    -0x34(%rbp),%eax
sub    $0x47,%eax
je     12d6 <change_buf+0x186>
jmp    12b4 <change_buf+0x164>
mov    -0x34(%rbp),%eax
sub    $0x4d,%eax
je     12e7 <change_buf+0x197>
jmp    12c5 <change_buf+0x175>
mov    -0x34(%rbp),%eax
sub    $0x6b,%eax
je     12f8 <change_buf+0x1a8>
jmp    130e <change_buf+0x1be>
mov    -0x20(%rbp),%rax
shl    $0x1e,%rax
mov    %rax,-0x20(%rbp)
jmp    1339 <change_buf+0x1e9>
mov    -0x20(%rbp),%rax
shl    $0x14,%rax
mov    %rax,-0x20(%rbp)
jmp    1339 <change_buf+0x1e9>
mov    -0x20(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x20(%rbp)
jmp    1339 <change_buf+0x1e9>
jmp    1339 <change_buf+0x1e9>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x35(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <stream_name@plt>
mov    %eax,%edx
mov    -0x35(%rbp),%al
lea    0xcf2(%rip),%rdi
movsbl %al,%esi
call   1040 <warnx@plt>
jmp    1390 <change_buf+0x240>
mov    0x2c78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    134a <change_buf+0x1fa>
jmp    134f <change_buf+0x1ff>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%esi
call   1070 <setvbuf@plt>
cmp    $0x0,%rax
je     1390 <change_buf+0x240>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <stream_name@plt>
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
lea    0xcae(%rip),%rdi
call   1030 <warn@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<change_buf>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    (%rsi),%al
cmp    $0x4c,%al
je     117d <change_buf+0x2d>
cmp    $0x42,%al
je     118f <change_buf+0x3f>
cmp    $0x30,%al
jne    1199 <change_buf+0x49>
cmpb   $0x0,0x1(%rbx)
jne    1199 <change_buf+0x49>
mov    0x2e70(%rip),%rax
jmp    1254 <change_buf+0x104>
cmpb   $0x0,0x1(%rbx)
jne    1199 <change_buf+0x49>
mov    0x2e3e(%rip),%rax
jmp    1254 <change_buf+0x104>
cmpb   $0x0,0x1(%rbx)
je     124d <change_buf+0xfd>
mov    0x2e30(%rip),%rbp
movq   $0x0,0x0(%rbp)
mov    %rsp,%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %rax,%r15
mov    0x0(%rbp),%rax
mov    0x2dfd(%rip),%rcx
mov    (%rsp),%rbp
cmp    (%rcx),%rax
je     11dd <change_buf+0x8d>
mov    0x2e0d(%rip),%rcx
cmp    (%rcx),%rax
je     11dd <change_buf+0x8d>
cmp    %rbx,%rbp
jne    11f6 <change_buf+0xa6>
mov    %r14,%rdi
call   1050 <stream_name@plt>
lea    0xe14(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <warn@plt>
movsbl 0x0(%rbp),%ebp
mov    0x2db7(%rip),%rax
cmp    $0x4c,%ebp
jg     1215 <change_buf+0xc5>
test   %ebp,%ebp
je     1257 <change_buf+0x107>
cmp    $0x47,%ebp
jne    122b <change_buf+0xdb>
shl    $0x1e,%r15
jmp    1257 <change_buf+0x107>
cmp    $0x4d,%ebp
je     1225 <change_buf+0xd5>
cmp    $0x6b,%ebp
jne    122b <change_buf+0xdb>
shl    $0xa,%r15
jmp    1257 <change_buf+0x107>
shl    $0x14,%r15
jmp    1257 <change_buf+0x107>
mov    %r14,%rdi
call   1050 <stream_name@plt>
lea    0xde4(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <warnx@plt>
mov    0x2d64(%rip),%rax
xor    %r15d,%r15d
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
mov    %r15,%rcx
call   1070 <setvbuf@plt>
test   %rax,%rax
je     128e <change_buf+0x13e>
mov    %r14,%rdi
call   1050 <stream_name@plt>
lea    0xdbf(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <warn@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@_IONBF = global i32 0
@_IOLBF = global i32 0
@_IOFBF = global i32 0
@errno = global i64 0
@EINVAL = global i64 0
@ERANGE = global i64 0
@.str = [30 x i8] c"Wrong buffer mode '%s' for %s\00"
@.str.1 = [27 x i8] c"Unknown suffix '%c' for %s\00"
@.str.2 = [35 x i8] c"Cannot set buffer mode '%s' for %s\00"
define void @change_buf(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i32* %0, i32** %3
store i8* %1, i8** %4
store i64 0, i64* %6
%8 = load i8*, i8** %4
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 48
br i1 %12, label %13, label %21
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = load i32, i32* @_IONBF
store i32 %20, i32* %7
br label %92
21: ; preds = %13, %2
%22 = load i8*, i8** %4
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 76
br i1 %26, label %27, label %35
27: ; preds = %21
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i64 1
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %27
%34 = load i32, i32* @_IOLBF
store i32 %34, i32* %7
br label %91
35: ; preds = %27, %21
%36 = load i8*, i8** %4
%37 = getelementptr inbounds i8, i8* %36, i64 0
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 66
br i1 %40, label %41, label %49
41: ; preds = %35
%42 = load i8*, i8** %4
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %41
%48 = load i32, i32* @_IOFBF
store i32 %48, i32* %7
store i64 0, i64* %6
br label %90
49: ; preds = %41, %35
store i64 0, i64* @errno
%50 = load i8*, i8** %4
%51 = call i64 @strtol(i8* %50, i8** %5, i32 0)
store i64 %51, i64* %6
%52 = load i64, i64* @errno
%53 = load i64, i64* @EINVAL
%54 = icmp eq i64 %52, %53
br i1 %54, label %63, label %55
55: ; preds = %49
%56 = load i64, i64* @errno
%57 = load i64, i64* @ERANGE
%58 = icmp eq i64 %56, %57
br i1 %58, label %63, label %59
59: ; preds = %55
%60 = load i8*, i8** %5
%61 = load i8*, i8** %4
%62 = icmp eq i8* %60, %61
br i1 %62, label %63, label %68
63: ; preds = %59, %55, %49
%64 = load i8*, i8** %4
%65 = load i32*, i32** %3
%66 = call i32 @stream_name(i32* %65)
%67 = call i32 @warn(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %64, i32 %66)
br label %68
68: ; preds = %63, %59
%69 = load i8*, i8** %5
%70 = load i8, i8* %69
%71 = sext i8 %70 to i32
switch i32 %71, label %82 [
i32 71, label %72
i32 77, label %75
i32 107, label %78
i32 0, label %81
]
72: ; preds = %68
%73 = load i64, i64* %6
%74 = mul i64 %73, 1073741824
store i64 %74, i64* %6
br label %88
75: ; preds = %68
%76 = load i64, i64* %6
%77 = mul i64 %76, 1048576
store i64 %77, i64* %6
br label %88
78: ; preds = %68
%79 = load i64, i64* %6
%80 = mul i64 %79, 1024
store i64 %80, i64* %6
br label %88
81: ; preds = %68
br label %88
82: ; preds = %68
%83 = load i8*, i8** %5
%84 = load i8, i8* %83
%85 = load i32*, i32** %3
%86 = call i32 @stream_name(i32* %85)
%87 = call i32 @warnx(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8 signext %84, i32 %86)
br label %103
88: ; preds = %81, %78, %75, %72
%89 = load i32, i32* @_IOFBF
store i32 %89, i32* %7
br label %90
90: ; preds = %88, %47
br label %91
91: ; preds = %90, %33
br label %92
92: ; preds = %91, %19
%93 = load i32*, i32** %3
%94 = load i32, i32* %7
%95 = load i64, i64* %6
%96 = call i64 @setvbuf(i32* %93, i32* null, i32 %94, i64 %95)
%97 = icmp ne i64 %96, 0
br i1 %97, label %98, label %103
98: ; preds = %92
%99 = load i8*, i8** %4
%100 = load i32*, i32** %3
%101 = call i32 @stream_name(i32* %100)
%102 = call i32 @warn(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %99, i32 %101)
br label %103
103: ; preds = %82, %98, %92
ret void
}

LLVM IR (-O2):
@_IONBF = global i32 0
@_IOLBF = global i32 0
@_IOFBF = global i32 0
@errno = global i64 0
@EINVAL = global i64 0
@ERANGE = global i64 0
@.str = [30 x i8] c"Wrong buffer mode '%s' for %s\00"
@.str.1 = [27 x i8] c"Unknown suffix '%c' for %s\00"
@.str.2 = [35 x i8] c"Cannot set buffer mode '%s' for %s\00"
define void @change_buf(i32* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = load i8, i8* %1
switch i8 %5, label %18 [
i8 48, label %6
i8 76, label %10
i8 66, label %14
]
6: ; preds = %2
%7 = getelementptr inbounds i8, i8* %1, i64 1
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
br i1 %9, label %44, label %18
10: ; preds = %2
%11 = getelementptr inbounds i8, i8* %1, i64 1
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %44, label %18
14: ; preds = %2
%15 = getelementptr inbounds i8, i8* %1, i64 1
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %44, label %18
18: ; preds = %2, %6, %10, %14
store i64 0, i64* @errno
%19 = call i64 @strtol(i8* %1, i8** %3, i32 0)
%20 = load i64, i64* @errno
%21 = load i64, i64* @EINVAL
%22 = icmp eq i64 %20, %21
%23 = load i64, i64* @ERANGE
%24 = icmp eq i64 %20, %23
%25 = select i1 %22, i1 true, i1 %24
%26 = load i8*, i8** %3
%27 = icmp eq i8* %26, %1
%28 = select i1 %25, i1 true, i1 %27
br i1 %28, label %29, label %32
29: ; preds = %18
%30 = tail call i32 @stream_name(i32* %0)
%31 = tail call i32 @warn(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %30)
br label %32
32: ; preds = %18, %29
%33 = load i8, i8* %26
%34 = sext i8 %33 to i32
switch i32 %34, label %41 [
i32 71, label %35
i32 77, label %37
i32 107, label %39
i32 0, label %44
]
35: ; preds = %32
%36 = shl i64 %19, 30
br label %44
37: ; preds = %32
%38 = shl i64 %19, 20
br label %44
39: ; preds = %32
%40 = shl i64 %19, 10
br label %44
41: ; preds = %32
%42 = tail call i32 @stream_name(i32* %0)
%43 = tail call i32 @warnx(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8 signext %33, i32 %42)
br label %53
44: ; preds = %35, %37, %39, %32, %14, %10, %6
%45 = phi i64 [ 0, %6 ], [ 0, %10 ], [ 0, %14 ], [ %19, %32 ], [ %40, %39 ], [ %38, %37 ], [ %36, %35 ]
%46 = phi i32* [ @_IONBF, %6 ], [ @_IOLBF, %10 ], [ @_IOFBF, %14 ], [ @_IOFBF, %32 ], [ @_IOFBF, %39 ], [ @_IOFBF, %37 ], [ @_IOFBF, %35 ]
%47 = load i32, i32* %46
%48 = tail call i64 @setvbuf(i32* %0, i32* null, i32 %47, i64 %45)
%49 = icmp eq i64 %48, 0
br i1 %49, label %53, label %50
50: ; preds = %44
%51 = tail call i32 @stream_name(i32* %0)
%52 = tail call i32 @warn(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %1, i32 %51)
br label %53
53: ; preds = %44, %50, %41
ret void
}