#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 *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ replacebit(int, unsigned int *, int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  if (argc != 4) {
    fprintf(stderr, "Usage: %s [integer] [location] [flag].\n", argv[0]);
    return -1;
  }
  unsigned int result;
  int number = atoi(argv[1]);
  int i = atoi(argv[2]);
  int flag = atoi(argv[3]);
  if (replacebit(number, &result, i, flag) == 0)
    fprintf(stdout, "Original number is %d, after replacing, %u\n", number,
            result);
  else
    fprintf(stderr, "Error.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     117a <main+0x4a>
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe99(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1206 <main+0xd6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    -0x14(%rbp),%rsi
call   1050 <replacebit@plt>
cmp    $0x0,%rax
jne    11e8 <main+0xb8>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xe4c(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11ff <main+0xcf>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x4,%edi
jne    118f <main+0x5f>
mov    0x8(%rbx),%rdi
call   1040 <atoi@plt>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
call   1040 <atoi@plt>
mov    %eax,%ebp
mov    0x18(%rbx),%rdi
call   1040 <atoi@plt>
lea    0xc(%rsp),%rsi
mov    %r14d,%edi
mov    %ebp,%edx
mov    %eax,%ecx
call   1050 <replacebit@plt>
test   %rax,%rax
je     11b0 <main+0x80>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
lea    0xece(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11ce <main+0x9e>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe5e(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    11d0 <main+0xa0>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    0xc(%rsp),%ecx
lea    0xe64(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [40 x i8] c"Usage: %s [integer] [location] [flag].\0A\00"
@stdout = global i32 0
@.str.1 = [44 x i8] c"Original number is %d, after replacing, %u\0A\00"
@.str.2 = [8 x i8] c"Error.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 4
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 -1, i32* %3
br label %45
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %7
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %8
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 3
%29 = load i8*, i8** %28
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %9
%31 = load i32, i32* %7
%32 = load i32, i32* %8
%33 = load i32, i32* %9
%34 = call i64 @replacebit(i32 %31, i32* %6, i32 %32, i32 %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %18
%37 = load i32, i32* @stdout
%38 = load i32, i32* %7
%39 = load i32, i32* %6
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %38, i32 %39)
br label %44
41: ; preds = %18
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %44
44: ; preds = %41, %36
store i32 0, i32* %3
br label %45
45: ; preds = %44, %12
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [40 x i8] c"Usage: %s [integer] [location] [flag].\0A\00"
@stdout = global i32 0
@.str.1 = [44 x i8] c"Original number is %d, after replacing, %u\0A\00"
@.str.2 = [8 x i8] c"Error.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp eq i32 %0, 4
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %30
9: ; preds = %2
%10 = bitcast i32* %3 to i8*
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = getelementptr inbounds i8*, i8** %1, i64 3
%18 = load i8*, i8** %17
%19 = tail call i32 @atoi(i8* %18)
%20 = call i64 @replacebit(i32 %13, i32* %3, i32 %16, i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %9
%23 = load i32, i32* @stdout
%24 = load i32, i32* %3
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %24)
br label %29
26: ; preds = %9
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %26, %22
br label %30
30: ; preds = %29, %5
%31 = phi i32 [ -1, %5 ], [ 0, %29 ]
ret i32 %31
}