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

/* Variables and functions */
int atoi(char const *);
int /*<<< orphan*/ fatal_error(char *, char const *);
int /*<<< orphan*/ int_char(int, unsigned char *);
int sscanf(char const *, char *, int *, int *);
int uint4(unsigned char *);
int f_set_int(int mode, unsigned char **sec, float *data, unsigned int ndata,
              char *inv_out, void **local, const char *arg1, const char *arg2,
              const char *arg3) {
  int i, j, k, m, val, seclen;
  if (mode < 0)
    return 0;
  i = atoi(arg1);
  j = atoi(arg2);
  if (i < 0 || i > 8)
    fatal_error("set_int: bad section number %s", arg1);
  if (j <= 0)
    fatal_error("set_hex: octet number must >= 1", "");
  if (i == 0)
    seclen = 16;
  else if (i == 8)
    seclen = 4;
  else
    seclen = uint4(sec[i]);
  k = sscanf(arg3, "%d%n", &val, &m);
  while (k == 1) {
    if (j + 3 > seclen)
      fatal_error("set_int out of bounds section %s", arg1);
    int_char(val, sec[i] + j - 1);
    j += 4;
    arg3 += m;
    k = sscanf(arg3, ":%d%n", &val, &m);
  }
  return 0;
}


x86 assembly (clang, -O0):
<f_set_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1190 <f_set_int+0x40>
movl   $0x0,-0x4(%rbp)
jmp    12d2 <f_set_int+0x182>
mov    0x10(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x34(%rbp)
mov    0x18(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x34(%rbp)
jl     11bc <f_set_int+0x6c>
cmpl   $0x8,-0x34(%rbp)
jle    11cc <f_set_int+0x7c>
mov    0x10(%rbp),%rsi
lea    0xe39(%rip),%rdi
call   1040 <fatal_error@plt>
cmpl   $0x0,-0x38(%rbp)
jg     11e9 <f_set_int+0x99>
lea    0xe42(%rip),%rdi
lea    0xe5a(%rip),%rsi
call   1040 <fatal_error@plt>
cmpl   $0x0,-0x34(%rbp)
jne    11ff <f_set_int+0xaf>
movl   $0x10,-0x48(%rbp)
jmp    122e <f_set_int+0xde>
cmpl   $0x8,-0x34(%rbp)
jne    1215 <f_set_int+0xc5>
movl   $0x4,-0x48(%rbp)
jmp    1229 <f_set_int+0xd9>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <uint4@plt>
mov    %eax,-0x48(%rbp)
jmp    122e <f_set_int+0xde>
mov    0x20(%rbp),%rdi
lea    0xe28(%rip),%rsi
lea    -0x44(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   1050 <sscanf@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x1,-0x3c(%rbp)
jne    12cb <f_set_int+0x17b>
mov    -0x38(%rbp),%eax
add    $0x3,%eax
cmp    -0x48(%rbp),%eax
jle    1272 <f_set_int+0x122>
mov    0x10(%rbp),%rsi
lea    0xdd2(%rip),%rdi
call   1040 <fatal_error@plt>
mov    -0x44(%rbp),%edi
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
movslq -0x38(%rbp),%rax
add    %rax,%rsi
add    $0xffffffffffffffff,%rsi
call   1060 <int_char@plt>
mov    -0x38(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x38(%rbp)
mov    -0x40(%rbp),%ecx
mov    0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,0x20(%rbp)
mov    0x20(%rbp),%rdi
lea    0xdaa(%rip),%rsi
lea    -0x44(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   1050 <sscanf@plt>
mov    %eax,-0x3c(%rbp)
jmp    1249 <f_set_int+0xf9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f_set_int>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,0x10(%rsp)
test   %edi,%edi
js     1279 <f_set_int+0x129>
mov    0x58(%rsp),%rbx
mov    0x50(%rsp),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1070 <atoi@plt>
mov    %eax,%r12d
cmp    $0x9,%ebp
jb     119d <f_set_int+0x4d>
lea    0xe6d(%rip),%rdi
mov    0x50(%rsp),%rsi
call   1040 <fatal_error@plt>
test   %r12d,%r12d
jg     11b5 <f_set_int+0x65>
lea    0xe76(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1040 <fatal_error@plt>
mov    0x60(%rsp),%rbx
test   %ebp,%ebp
je     11cb <f_set_int+0x7b>
cmp    $0x8,%ebp
jne    11d3 <f_set_int+0x83>
mov    $0x4,%r15d
jmp    11e7 <f_set_int+0x97>
mov    $0x10,%r15d
jmp    11e7 <f_set_int+0x97>
movslq %ebp,%rax
mov    0x10(%rsp),%rcx
mov    (%rcx,%rax,8),%rdi
call   1030 <uint4@plt>
movslq %eax,%r15
lea    0xe73(%rip),%rsi
lea    0x8(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rbx,%rdi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    1279 <f_set_int+0x129>
movslq %ebp,%r13
movslq %r12d,%r12
add    $0xffffffffffffffff,%r12
lea    0xc(%rsp),%r14
jmp    125c <f_set_int+0x10c>
cs nopw 0x0(%rax,%rax,1)
mov    0x8(%rsp),%edi
mov    0x10(%rsp),%rax
add    (%rax,%r13,8),%r12
mov    %r12,%rsi
call   1060 <int_char@plt>
movslq 0xc(%rsp),%rax
add    %rax,%rbx
mov    %rbx,%rdi
lea    0xe19(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %r14,%rcx
call   1050 <sscanf@plt>
mov    %rbp,%r12
cmp    $0x1,%eax
jne    1279 <f_set_int+0x129>
lea    0x4(%r12),%rbp
cmp    %r15,%rbp
jle    1220 <f_set_int+0xd0>
lea    0xdd2(%rip),%rdi
mov    0x50(%rsp),%rsi
call   1040 <fatal_error@plt>
jmp    1220 <f_set_int+0xd0>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"set_int: bad section number %s\00"
@.str.1 = [32 x i8] c"set_hex: octet number must >= 1\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [5 x i8] c"%d%n\00"
@.str.4 = [33 x i8] c"set_int out of bounds section %s\00"
@.str.5 = [6 x i8] c":%d%n\00"
define i32 @f_set_int(i32 %0, i8** %1, float* %2, i32 %3, i8* %4, i8** %5, i8* %6, i8* %7, i8* %8) {
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8**
%13 = alloca float*
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i8**
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i8*
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
store i32 %0, i32* %11
store i8** %1, i8*** %12
store float* %2, float** %13
store i32 %3, i32* %14
store i8* %4, i8** %15
store i8** %5, i8*** %16
store i8* %6, i8** %17
store i8* %7, i8** %18
store i8* %8, i8** %19
%26 = load i32, i32* %11
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %9
store i32 0, i32* %10
br label %98
29: ; preds = %9
%30 = load i8*, i8** %17
%31 = call i32 @atoi(i8* %30)
store i32 %31, i32* %20
%32 = load i8*, i8** %18
%33 = call i32 @atoi(i8* %32)
store i32 %33, i32* %21
%34 = load i32, i32* %20
%35 = icmp slt i32 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %29
%37 = load i32, i32* %20
%38 = icmp sgt i32 %37, 8
br i1 %38, label %39, label %42
39: ; preds = %36, %29
%40 = load i8*, i8** %17
%41 = call i32 @fatal_error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %40)
br label %42
42: ; preds = %39, %36
%43 = load i32, i32* %21
%44 = icmp sle i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %42
%46 = call i32 @fatal_error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
br label %47
47: ; preds = %45, %42
%48 = load i32, i32* %20
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %47
store i32 16, i32* %25
br label %63
51: ; preds = %47
%52 = load i32, i32* %20
%53 = icmp eq i32 %52, 8
br i1 %53, label %54, label %55
54: ; preds = %51
store i32 4, i32* %25
br label %62
55: ; preds = %51
%56 = load i8**, i8*** %12
%57 = load i32, i32* %20
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8*, i8** %56, i64 %58
%60 = load i8*, i8** %59
%61 = call i32 @uint4(i8* %60)
store i32 %61, i32* %25
br label %62
62: ; preds = %55, %54
br label %63
63: ; preds = %62, %50
%64 = load i8*, i8** %19
%65 = call i32 @sscanf(i8* %64, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32* %24, i32* %23)
store i32 %65, i32* %22
br label %66
66: ; preds = %77, %63
%67 = load i32, i32* %22
%68 = icmp eq i32 %67, 1
br i1 %68, label %69, label %97
69: ; preds = %66
%70 = load i32, i32* %21
%71 = add nsw i32 %70, 3
%72 = load i32, i32* %25
%73 = icmp sgt i32 %71, %72
br i1 %73, label %74, label %77
74: ; preds = %69
%75 = load i8*, i8** %17
%76 = call i32 @fatal_error(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %75)
br label %77
77: ; preds = %74, %69
%78 = load i32, i32* %24
%79 = load i8**, i8*** %12
%80 = load i32, i32* %20
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i8*, i8** %79, i64 %81
%83 = load i8*, i8** %82
%84 = load i32, i32* %21
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i8, i8* %83, i64 %85
%87 = getelementptr inbounds i8, i8* %86, i64 -1
%88 = call i32 @int_char(i32 %78, i8* %87)
%89 = load i32, i32* %21
%90 = add nsw i32 %89, 4
store i32 %90, i32* %21
%91 = load i32, i32* %23
%92 = load i8*, i8** %19
%93 = sext i32 %91 to i64
%94 = getelementptr inbounds i8, i8* %92, i64 %93
store i8* %94, i8** %19
%95 = load i8*, i8** %19
%96 = call i32 @sscanf(i8* %95, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32* %24, i32* %23)
store i32 %96, i32* %22
br label %66
97: ; preds = %66
store i32 0, i32* %10
br label %98
98: ; preds = %97, %28
%99 = load i32, i32* %10
ret i32 %99
}

LLVM IR (-O2):
@.str = [31 x i8] c"set_int: bad section number %s\00"
@.str.1 = [32 x i8] c"set_hex: octet number must >= 1\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [5 x i8] c"%d%n\00"
@.str.4 = [33 x i8] c"set_int out of bounds section %s\00"
@.str.5 = [6 x i8] c":%d%n\00"
define i32 @f_set_int(i32 %0, i8** nocapture %1, float* nocapture readnone %2, i32 %3, i8* nocapture readnone %4, i8** nocapture readnone %5, i8* %6, i8* nocapture %7, i8* nocapture %8) {
%10 = alloca i32
%11 = alloca i32
%12 = bitcast i32* %10 to i8*
%13 = bitcast i32* %11 to i8*
%14 = icmp slt i32 %0, 0
br i1 %14, label %60, label %15
15: ; preds = %9
%16 = tail call i32 @atoi(i8* %6)
%17 = tail call i32 @atoi(i8* %7)
%18 = icmp ugt i32 %16, 8
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = tail call i32 @fatal_error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %21
21: ; preds = %15, %19
%22 = icmp slt i32 %17, 1
br i1 %22, label %23, label %25
23: ; preds = %21
%24 = tail call i32 @fatal_error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %21
switch i32 %16, label %27 [
i32 0, label %33
i32 8, label %26
]
26: ; preds = %25
br label %33
27: ; preds = %25
%28 = sext i32 %16 to i64
%29 = getelementptr inbounds i8*, i8** %1, i64 %28
%30 = load i8*, i8** %29
%31 = tail call i32 @uint4(i8* %30)
%32 = sext i32 %31 to i64
br label %33
33: ; preds = %25, %26, %27
%34 = phi i64 [ 4, %26 ], [ %32, %27 ], [ 16, %25 ]
%35 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32* %11, i32* %10)
%36 = icmp eq i32 %35, 1
br i1 %36, label %37, label %60
37: ; preds = %33
%38 = sext i32 %16 to i64
%39 = getelementptr inbounds i8*, i8** %1, i64 %38
%40 = sext i32 %17 to i64
br label %41
41: ; preds = %37, %48
%42 = phi i64 [ %40, %37 ], [ %54, %48 ]
%43 = phi i8* [ %8, %37 ], [ %57, %48 ]
%44 = add nsw i64 %42, 3
%45 = icmp sgt i64 %44, %34
br i1 %45, label %46, label %48
46: ; preds = %41
%47 = call i32 @fatal_error(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %6)
br label %48
48: ; preds = %46, %41
%49 = load i32, i32* %11
%50 = load i8*, i8** %39
%51 = getelementptr inbounds i8, i8* %50, i64 -1
%52 = getelementptr inbounds i8, i8* %51, i64 %42
%53 = call i32 @int_char(i32 %49, i8* %52)
%54 = add i64 %42, 4
%55 = load i32, i32* %10
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %43, i64 %56
%58 = call i32 @sscanf(i8* %57, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32* %11, i32* %10)
%59 = icmp eq i32 %58, 1
br i1 %59, label %41, label %60
60: ; preds = %48, %33, %9
ret i32 0
}